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