4 # read qmail module config
5 $p = -l $0 ? readlink($0) : $0;
6 $p =~ /^(.*)\/[^\/]+$/;
7 open(CONF, "$1/config");
15 # read headers and body
20 if (/^(\S+):\s+(.*)/) {
29 # read the filter file
30 if (open(FILTER, $ARGV[0])) {
33 if (/^(\S+)\s+(\S+)\s+(\S+)\s+(.*)$/) {
34 push(@filter, [ $1, $2, $3, $4 ]);
36 elsif (/^(\S+)\s+(\S+)$/) {
37 push(@filter, [ $1, $2 ]);
43 print STDERR "Filter file $ARGV[0] does not exist!\n";
47 # run the filter to find the first matching rule
48 open(LOG, ">>$ARGV[0].log");
49 foreach $f (@filter) {
50 local $field = $f->[2] eq 'body' ? $body : $header{$f->[2]};
53 $st = ($field !~ /$f->[3]/i);
55 elsif ($f->[0] == 1) {
56 $st = ($field =~ /$f->[3]/i);
58 elsif ($f->[0] == 2) {
63 if ($f->[1] =~ /^\//) {
65 open(MAIL, ">>$f->[1]");
69 # Forward to another address
70 $f->[1] =~ s/\\/\\\\/g;
72 open(MAIL, "|$config{'qmail_dir'}/bin/qmail-inject '$f->[1]'");
77 $now = localtime(time());
78 print LOG "[$now] [$header{'from'}] [",join(" ",@$f),"]\n";