Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 magnus 1
From: Richard Lithvall <richard@lithvall.nu>
2
Date: Mon, 24 Mar 2003 16:31:40 +0100
3
To: sa-exim@lists.merlins.org
4
Subject: [SA-exim] Rejecting spam at SMTP but forward it to its recipients
5
 
6
Hi list members!
7
 
8
As the lazy postmaster I am I don't want to check every mail caught by
9
SA for false positives but I really want to reject the damn spam at SMTP
10
time.
11
Therefore I wrote this little perl hack delegating this responsibilty to
12
my users (they all use exim filters to file mail tagged as spam into a
13
Junk folder).
14
 
15
It works as follows.
16
- Configure SA-exim to save rejected mail into a directory
17
- Run the perl script attatched below from cron, let's say, once an hour
18
(as user mail or whoever that runs your exim)
19
- Inform your users how things work and their responsibilites to check
20
for false positives.
21
 
22
Please comment this script/hack and I'd really love to get some English
23
spelling/grammar check as well :-)
24
 
25
/Richard
26
 
27
 
28
#!/usr/bin/perl
29
$dir = "/var/spool/exim4/SApermrejectsave/new";
30
foreach $mail (<$dir/*>) {
31
        if(-f $mail){
32
                open(MAIL, $mail);
33
#               print "Working on: " . $mail . "\n";
34
                $from = <MAIL>;
35
                $from =~ s/^From\s(.+?)\s.+\n/$1/;
36
                while (<MAIL>){
37
                        if(/^X-SA-Exim-Rcpt-To:\s(.+)/){
38
                                @rcpts = split(/, /, $1);
39
                                last;
40
                        }
41
                        if(/^$/){
42
                                last;
43
                        }
44
                }
45
                open(BSMTP, "| /usr/sbin/exim4 -bS");
46
                print BSMTP "mail from:<" . $from . ">\n";
47
                foreach $rcpt (@rcpts){
48
                        print BSMTP "rcpt to:<" . $rcpt . ">\n";
49
                }
50
                print BSMTP "data\n";
51
                print BSMTP "X-Spam-Notice: This mail was rejected
52
during reception due to heuristic check marked it as spam,\n";
53
                print BSMTP "\tbut forwarded to You for checking for
54
false positives.\n";
55
                seek(MAIL, 0, 0);
56
                $throw_away_first_from_line = <MAIL>;
57
                while (<MAIL>){
58
                        if(/^\./){
59
                                print BSMTP ".";
60
                        }
61
                        print BSMTP;
62
                }
63
                close(MAIL);
64
                print BSMTP ".\n";
65
                print BSMTP "quit\n";
66
                close(BSMTP);
67
                unlink($mail);
68
        }
69
}
70