View Single Post
  #25 (permalink)  
Old 10-21-2009, 09:32 AM
Federico Federico is offline
Junior Member
 
Posts: 7
Default

I'd like to give my contribution to this discussion.

We've recently migrated from Postfix+Dovecot to Zimbra and we had the same issue with filter rules.

We had this kind of input:

Code:
#### machinename ##### 
if address :is "From" "root@machinename.domain.tld" { 
  # CRON 
  if header :contains ["Subject"] ["Cron <root@machinename.domain.tld>"] { 
    fileinto "INBOX.machinename.cron"; 
    stop; 
  } 
  # LOGWATCH 
  if header :contains ["Subject"] ["Logwatch for"] { 
    fileinto "INBOX.machinename.logwatch"; 
    stop; 
  } 
  # CATCHALL 
  fileinto "INBOX.machinename"; 
  stop; 
} 
##################
So we solved the situation with this perl script:
Code:
#!/usr/bin/perl -w

use warnings;
use strict;

open(FILE,"dovecot.sieve") || die ('unable to read rules');
my @line=<FILE>;
close(FILE);

my @rule;
my $index=0;

foreach my $val (@line) {
        next if $val =~ m/^$/;
        if ($val =~ m/#### (.*) #####/) {
                $rule[$index]{machine} = $1;  
        }
        if ($val =~ m/if header :contains \["Subject"\] \["Cron <(.*@.*)>"\]/) {
                $rule[$index]{cron} = $1; 
        }
        if ($val =~ m/##################/) {
                $index++;
        }
}

for my $i ( 0 .. $#rule ) { 

                my $machine=$rule[$i]{machine};
                my $mailcron=$rule[$i]{cron};

                print "zmmailbox -a admin -p accountpass -m accountname afrl $machine.cron header \"Subject\" contains \"Cron <root\@$machine>\" fileinto /Inbox/$machine.cron\n";
                print "zmmailbox -a admin -p accountpass -m accountname afrl $machine.logwatch header  \"Subject\" contains \"Logwatch for\" fileinto /Inbox/$machine.logwatch\n";
                print "zmmailbox -a admin -p accountpass -m accountname afrl $machine.catchall header \"From\" contains \"root\@$machine.hermess.it\" fileinto /Inbox/$machine\n";
}
A little bit...raw, but it works!
Reply With Quote