Improved roundcube managesieve plugin

This guide is DEPRECATED, roundcube 5.0 support move sieve address comparisons now

Implement sieve parameter :address :all in RoundCube

When creating a new filter in RC Managesieve plugin with the rule “Sender is equal to” RC compile a sieve script like this one:

if anyof (header :is "From" "example@example.com")
{
	fileinto "INBOX.Spam";
	stop;
}

Of course this script will FAIL when sender is ‘”Simone Caruso” <example@example.com>’, because “header” matches strings NOT addresses! Ref. RFC5228

The correct syntax for matching address (To, From, Cc) is like this:

if anyof (address :all :is "From" "example@example.com")
{
	fileinto "INBOX.Spam";
	stop;
}

Here the patch to solve the problem (RoundCube 0.4.2 – plugins/managesieve/lib/rcube_sieve.php):

513,515c513,519
&lt;                     $tests[$i] .= ($test['not'] ? 'not ' : '');
&lt;                     $tests[$i] .= 'header :' . $test['type'];
&lt;                     if (is_array($test['arg1'])) --- &gt;                  $tests[$i] .= ($test['not'] ? 'not ' : '');
&gt;                    if(in_array('From', $test['arg1']) OR $test['arg1']=='From' OR in_array('To', $test['arg1']) OR $test['arg1']=='To' OR in_array('Cc', $test['arg1']) OR $test['arg1']=='Cc'){
&gt;                       $tests[$i] .= 'address :all :' . $test['type'];
&gt;                  }else{
&gt;                       $tests[$i] .= 'header :' . $test['type'];
&gt;                    }
&gt;                  if (is_array($test['arg1']))
824a829,832
&gt;       $patterns[] = '(not\s+)?(address)\s+:all\s+:(contains|is|matches)\s+\[(.*?[^\\\]")\]\s+\[(.*?[^\\\]")\]';
&gt;       $patterns[] = '(not\s+)?(address)\s+:all\s+:(contains|is|matches)\s+(".*?[^\\\]")\s+(".*?[^\\\]")';
&gt;       $patterns[] = '(not\s+)?(address)\s+:all\s+:(contains|is|matches)\s+\[(.*?[^\\\]")\]\s+(".*?[^\\\]")';
&gt;       $patterns[] = '(not\s+)?(address)\s+:all\s+:(contains|is|matches)\s+(".*?[^\\\]")\s+\[(.*?[^\\\]")\]';
833d840
&lt;
842c849
&lt;                 else if (preg_match('/^(not\s+)?header/', $match[0])) { --- &gt;                 else if (preg_match('/^(not\s+)?(header|address)/', $match[0])) {
Share

Leave a Reply

Your e-mail address will not be published. Required fields are marked *