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 < $tests[$i] .= ($test['not'] ? 'not ' : ''); < $tests[$i] .= 'header :' . $test['type']; < if (is_array($test['arg1'])) --- > $tests[$i] .= ($test['not'] ? 'not ' : ''); > 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'){ > $tests[$i] .= 'address :all :' . $test['type']; > }else{ > $tests[$i] .= 'header :' . $test['type']; > } > if (is_array($test['arg1'])) 824a829,832 > $patterns[] = '(not\s+)?(address)\s+:all\s+:(contains|is|matches)\s+\[(.*?[^\\\]")\]\s+\[(.*?[^\\\]")\]'; > $patterns[] = '(not\s+)?(address)\s+:all\s+:(contains|is|matches)\s+(".*?[^\\\]")\s+(".*?[^\\\]")'; > $patterns[] = '(not\s+)?(address)\s+:all\s+:(contains|is|matches)\s+\[(.*?[^\\\]")\]\s+(".*?[^\\\]")'; > $patterns[] = '(not\s+)?(address)\s+:all\s+:(contains|is|matches)\s+(".*?[^\\\]")\s+\[(.*?[^\\\]")\]'; 833d840 < 842c849 < else if (preg_match('/^(not\s+)?header/', $match[0])) { --- > else if (preg_match('/^(not\s+)?(header|address)/', $match[0])) { |