Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure when importing sieve vacations from Horde with nested ifs #5540

Closed
tpokorra opened this issue Nov 29, 2016 · 4 comments
Closed

Failure when importing sieve vacations from Horde with nested ifs #5540

tpokorra opened this issue Nov 29, 2016 · 4 comments
Assignees
Milestone

Comments

@tpokorra
Copy link
Contributor

We have sieve vacation scripts from Horde with nested ifs. If we try to reuse them, we have had bad results, because the parser does not cope well with the nested ifs, and we end up with emails discarded because the next rule was not processed correclty.

Sample sieve script:

# Sieve Filter
# Erzeugt von Ingo (http://www.horde.org/ingo/) (30.09.2016, 16:02)

require ["vacation", "regex"];

# Abwesenheit
if allof ( not exists ["list-help", "list-unsubscribe", "list-subscribe", "list-owner", "list-post", "list-archive", "list-id", "Mailing-List"], not header :comparator "i;ascii-casemap" :is "Precedence" ["list", "bulk", "junk"], not header :comparator "i;ascii-casemap" :matches "To" "Multiple recipients of*" ) {
    if header :regex "Received" "^.*(2016) (\\(.*\\) )?..:..:.. (\\(.*\\) )?(\\+|\\-)....( \\(.*\\))?$" {
    if header :regex "Received" "^.*(Oct) (\\(.*\\) )?.... (\\(.*\\) )?..:..:.. (\\(.*\\) )?(\\+|\\-)....( \\(.*\\))?$" {
    if header :regex "Received" "^.*([0 ]4|[0 ]5|[0 ]6|[0 ]7) (\\(.*\\) )?... (\\(.*\\) )?.... (\\(.*\\) )?..:..:.. (\\(.*\\) )?(\\+|\\-)....( \\(.*\\))?$" {
    vacation :days 7 :addresses "[email protected]" :subject "vacation" "blablabla";
}
}
}

}

# Ausgeschlossene Adressen
if address :all :comparator "i;ascii-casemap" :is ["From", "Sender", "Resent-From"] ["[email protected]"]  {
    discard;
    stop;
}

turned into this by Roundcube when I change the name of the first rule to Abwesenheit2:

# Sieve Filter
# Erzeugt von Ingo (http://www.horde.org/ingo/) (30.09.2016, 16:02)

require ["vacation"];
# EDITOR Roundcube (Managesieve)
# EDITOR_VERSION 8.6
# rule:[Abwesenheit2]
if allof (not exists ["list-help","list-unsubscribe","list-subscribe","list-owner","list-post","list-archive","list-id","Mailing-List"], not header :is "precedence" ["list","bulk","junk"], not header :matches "to" "Multiple recipients of*")
{
        vacation :days 7 :addresses "[email protected]" :subject "vacation" "blablabla";
}
discard;
stop;

We already had quite some data loss.

We have now deleted all the old scripts, but for other customers we still need to migrate, and for other users of Roundcube it would be better to have a clean solution.

@tpokorra
Copy link
Contributor Author

one quick and dirty workaround would be to drop all rules with action discard, that don't have a test.

in ./plugins/managesieve/lib/Roundcube/rcube_sieve_script.php, in private function _parse_text($script), section Simple commands:

         if ($rule['actions'][0]['type'] == 'discard') {
                    $rule = null;
         }

@alecpl
Copy link
Member

alecpl commented Nov 30, 2016

Handling of nested rules is really not simple and I would rather not work on this. So, I propose a simple fix that will ignore all rules with "nested content". In such a case it would mean that the vacation rule would be ignore and the output would be:

# Sieve Filter
# Erzeugt von Ingo (http://www.horde.org/ingo/) (30.09.2016, 16:02)

# rule:[Ausgeschlossene Adressen]
if address :all :is ["From","Sender","Resent-From"] ["[email protected]"]
{
    discard;
    stop;
}

What do you think?

@alecpl alecpl added this to the 1.2.4 milestone Nov 30, 2016
@alecpl alecpl self-assigned this Nov 30, 2016
@tpokorra
Copy link
Contributor Author

ok, I understand that the nested ifs are too complicated to convert.

Yes, dropping the rule with nested ifs makes sense. It is a lot better than the current bug :)

Thank you, @alecpl !

@alecpl
Copy link
Member

alecpl commented Nov 30, 2016

Done.

@alecpl alecpl closed this as completed Nov 30, 2016
tpokorra pushed a commit to tpokorra/KolabScripts that referenced this issue Nov 30, 2016
ZiBiS added a commit to ZiBiS/roundcubemail that referenced this issue Dec 5, 2016
* 'master' of https://github.com/roundcube/roundcubemail:
  Simplified/unified key info frame
  Identicon plugin
  Parse error and CS fixes after PR merge
  Added replacement variables support in password_pop_host (roundcube#5539)
  Fix variable substitution in ldap host for some use-cases, e.g. new_user_identity (roundcube#5544)
  Fix handling of scripts with nested rules (roundcube#5540)
  Bump up Enigma version number
  Update changelog with 1.2.3 release
  CS fixes and update changelog
  Do not store passwords on disk - use proc_open instead of popen (roundcube#5531)
  Make sure subject is always on proper place in widescreen mode
  Remove redundant padding in textarea for raw editor
  Shrink CodeMirror code
  Release managesieve 8.8
  Cleanup and improve CodeMirror integration
  Fixed redundancy in sql caching system and compatibility with Galera Cluster (roundcube#5439)
  Use GSSAPI only if configured (roundcube#5530)
  handles multiple errors and shows error messages in editor tooltips
  syntax highlighted raw editor for sieve filter sets(codemirror)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants