fbcb4d9f32006c62f04d18849c800e0772ade03b
[PerlMail.git] / My-Audit.pm
1 # $Id$
2
3 sub audit_init
4 {
5         %audit_profile=(
6                         "btw"   =>[],
7                         "silent"=>["=btw"   ,"did"],
8                         "log"   =>["=silent","syslog"],
9                         "bell"  =>["=log"   ,"bell"],
10                         "sms"   =>["=bell"  ,"sms=1"],
11                         "crit"  =>["=sms"   ,"sms=3"],
12                         );
13         @sms_squeezes=(
14                         { "SqueezeControl"=>"noconv"                         },
15                         { "SqueezeControl"=>"conv"  ,"SQZ_OPTIMIZE_LEVEL"=>0 },
16                         { "SqueezeControl"=>"conv"  ,"SQZ_OPTIMIZE_LEVEL"=>1 },
17                         { "SqueezeControl"=>"med"   ,"SQZ_OPTIMIZE_LEVEL"=>0 },
18                         { "SqueezeControl"=>"med"   ,"SQZ_OPTIMIZE_LEVEL"=>1 },
19                         { "SqueezeControl"=>"max"   ,"SQZ_OPTIMIZE_LEVEL"=>0 },
20                         { "SqueezeControl"=>"max"   ,"SQZ_OPTIMIZE_LEVEL"=>1 },
21                         );
22         @alternates_host=(
23                         "jabberwock.ucw.cz",    # short@ucw.cz
24                         "atrey.karlin.mff.cuni.cz",     # short@atrey.karlin.mff.cuni.cz
25                         "k332.feld.cvut.cz",    # short@k332.feld.cvut.cz
26                         );
27         @dnsbl_whitelist=(
28                         "195.250.128.83",       # smtp3.vol.cz; vol.cz.multistage.blackholes.five-ten-sg.com.
29                         "64.49.222.22",         # mail.pm.org: rackspace.com.spam-support.blackholes.five-ten-sg.com.
30                         "208.147.243.5",        # gambit.liquidcomm.net: cw.net.spam-support.blackholes.five-ten-sg.com.
31                         );
32 }
33
34 sub audit
35 {
36         # TODO: <short-m@> storage?
37
38         # never spawn new mail if FROM_MAILER
39         # $isFROM_MAILER postponed after maillists as they may look as FROM_MAILER
40         #use re 'debug';
41         my $isFROM_MAILER=$Audit->header()=~/$procmailFROM_MAILER/mio;
42         $store_ignorenewmail=(0
43                         || $isFROM_MAILER
44                         || headerhas "From",'<Regexp:^owner->'
45                         );
46
47         # spam honeypots
48         return if did sub {
49                 local $_;
50                 local $store_profile="silent";
51                 store "=spamo-k332"   if grep /^\Qshort\@k332.feld.cvut.cz\E/i,Received_for();
52                 # TODO: foreign violation of RFC 822 section 4.4.4, Subject:.*Automatick.+odpov.+v.+nep.+tomnosti
53                 store "=spamo"        if headeris "From",'<ghandchi@hotmail.com>';
54                 store "=spamo"        if headeris "From",'<newsletter@levnapc.cz>';
55                 store "=spamo"        if headeris "From",'<Tomas@dtpstudio.cz>';
56                 store "=spamo"        if headeris "From",'<BNcom@email.bn.com>';
57                 store "=spamo"        if headeris "From",'<e4luck@lists.opt4email.com>';
58                 store "=spamo"        if headeris "From",'<mailcontests@lists.servitall.com>';
59                 store "=spamo"        if headeris "From",'<canda@lica.cz>';
60                 {
61                         # weak detection: files with text/html w/o text/plain are usually a spam
62                         my @types_linear=map({ mime_type($_); } parts_linear());
63                         store "=spamo-html" if grep({ $_ eq "text/html"; } @types_linear) && !grep({ $_ eq "text/plain"; } @types_linear);
64                         }
65                 store "=spamo-big5" if ($_=mimehead(body_first())->mime_attr("Content-Type.charset")) && /^big5/i;
66                 };
67
68         # spam detection
69         return if did sub {
70                 local $store_profile="silent";
71                 local $_;
72                 store "=spam-razor".($_ eq 1 ? "" : ";$_")      if $_=razor2();
73                 };
74         return if did sub {
75                 local $store_profile="silent";
76                 local $_;
77                 store "=spam-orbs"                 .";$_","log" if $_=dnsbl '.relays.ordb.org.' ,1;     # all hosts
78                 store "=spam-abuse"                .";$_","log" if $_=dnsbl '.blackholes.mail-abuse.org.' ,1;   # all hosts
79                 # we don't check all hosts as they can be "dialup" category, FIXME: check for it
80                 store "=spam-five"                 .";$_","log" if $_=dnsbl '.blackholes.five-ten-sg.com.',0; # just first
81                 # I don't send viruses but viruses propagate mails of mine
82                 store "=spam-av"                                if headeris "X-Mailer",'ravmd/8.3.2';
83                 };
84
85         # special delivery
86         store "=err","bell" and return if headerhas \&Received_for,'<short+err@>';
87
88         # ppl-wished foreign remapping, Reply-To is left untouched!
89         # FIXME: modifications are now being dropped by &write_message!
90         header_remap("From",{
91                         'kerere@post.cz'               =>'kamzik@k332.feld.cvut.cz',
92                         'profes@mbox.vol.cz'           =>'kratochvilova@egp.cz',
93                         'jkrouzek@mbox.vol.cz'         =>'krouzek@mbox.fsv.cuni.cz',
94                         'jakub.gorner@lidovky.cz'      =>'tonda@disnet.cz',
95                         'jan.kolar@videoprogress.cz'   =>'jenda.kolar@volny.cz',
96                         'daniel.rulicek@cponline.cz'   =>'daniel.rulicek@cpress.cz',
97                         'pavel@suse.cz'                =>'pavel@ucw.cz',
98
99                         });
100
101         # My obsolete e-mail addresses
102         store_muttrc_alternates "=redirect-","btw";
103
104         # nasty public lists with $store_ignore
105         {
106                 local $store_profile="log";
107                 local $store_ignore;
108                 $store_ignore="smsmail"    if 1==$Audit->body() && length(join "",$Audit->body())<180;  # SMS mail
109                 $store_ignore="sms OS"     if $Audit->subject()=~/^Email pro: /;        # "^Email pro: gsm@sh\.cvut\.cz$";
110                 $store_ignore="list-moron" if grep { headeris "From",$_; } qw(
111                                 <kempny@>
112                                 <help.me@wo.cz>
113                                 <mr.death@mail.cz>
114                                 <danx3@centrum.cz>
115                                 <@mujoskar.cz>
116                                 <satko@quanto.nr.sanet.sk>
117                                 <vithous@attorney.cz> <viroman@attorney.cz>
118                                 <konf@klain.cz>
119                                 <stein@tiscali.cz>
120                                 );
121
122                 store "=gsm"               if headeris  "Sender"   ,'<owner-gsm@sh.cvut.cz>';
123                 store "=gsmpand"           if headeris  "List-Post",'<gsm@pandora.cz>';
124                 }
125
126         # lists
127         store "=mozillabug","log"    if headeris "From"     ,'<bugzilla-daemon@mozilla.org>';
128         store "=9kc","log"           if headeris "List-Post",'<n9k@pandora.cz>';
129         store "=9kcd","log"          if headeris "List-Post",'<dev9k@pandora.cz>';
130         store "=9ku","log"           if headeris "List-Id"  ,'<9000.listman.net>';
131         store "=9kd","log"           if headeris "Sender"   ,'<owner-9000-developers@geekstuff.co.uk>';
132         store "=spong","log"         if headeris "List-Id"  ,'<spong-users.lists.sourceforge.net>';
133         store "=gtkd","silent"       if headeris "List-Id"  ,'<gtk-devel-list.gnome.org>';
134         store "=gnomevfs","log"      if headeris "List-Id"  ,'<gnome-vfs-list.gnome.org>';
135         store "=mffstatnice","bell"  if headeris "List-Post",'<statnice@atrey.karlin.mff.cuni.cz>';
136         store "=hw","log"            if headeris "List-Post",'<hw-news@list.gin.cz>';
137         store "=gnokii","log"        if headeris "List-Id"  ,'<gnokii-users.mail.freesoftware.fsf.org>';
138         store "=winelic","log"       if headeris "List-Id"  ,'<wine-license.winehq.com>';
139         store "=wined","silent"      if headeris "List-Id"  ,'<wine-devel.winehq.com>';
140         store "=winepat","silent"    if headeris "List-Id"  ,'<wine-patches.winehq.com>';
141         store "=winecvs","silent"    if headeris "List-Id"  ,'<wine-cvs.winehq.com>';
142         store "=wineann","log"       if headeris "List-Id"  ,'<wine-announce.winehq.com>';
143         store "=ros","log"           if headeris "List-Post",'<ros-general@reactos.com>';
144         store "=roskernel","log"     if headeris "List-Post",'<ros-kernel@reactos.com>';
145         store "=roscvs","silent"     if headeris "List-Post",'<ros-cvs@reactos.com>';
146         store "=rosbug","log"        if headeris "Reply-To" ,'<scarab@reactos.wox.org>';
147         store "=fsd","log"           if headeris "X-Mailing-List",'<linux-fsdevel@vger.kernel.org>';
148         store "=surprise","sms"      if headeris "List-Post",'<surprise@atrey.karlin.mff.cuni.cz>';
149         store "=surprisesuse","sms"  if headeris "Sender"   ,'<owner-surprise@suse.cz>';
150         store "=tacacs","log"        if headeris "Sender"   ,'<tacplus-l@disaster.com>';
151         store "=tacacsd","log"       if headerhas \&Received_for,'devel@tacplus.org';   # TODO: fix when real list
152         store "=pm","sms"            if headeris "Sender"   ,'<owner-prague-pm@pm.org>';
153         store "=radary","log"        if headeris "Reply-To" ,'<pha@radary.cz>';
154         store "=dnet","log"          if headeris "Sender"   ,'<@lists.distributed.net>';
155         store "=linux-input","log"   if headeris "List-Post",'<linux-input@atrey.karlin.mff.cuni.cz>';
156         store "=strom","bell"        if headeris "List-Post",'<vodni-strom@atrey.karlin.mff.cuni.cz>';
157         store "=netinfo","log"       if headeris "Sender"   ,'<owner-netinfo-l@vol.cz>';
158         store "=saintmj","log"       if headeris "From"     ,'<netsaint@kam-enterprise.ms.mff.cuni.cz>';
159         store "=saintmj","log"       if headeris "From"     ,'<netsaint@kam.mff.cuni.cz>';
160         store "=4cerr","bell"        if headeris "From"     ,'<owner-4cinfo@atrey.karlin.mff.cuni.cz>';
161         store "=4c","sms"            if headeris "List-Post",'<4cinfo@atrey.karlin.mff.cuni.cz>';
162         store "=slashdot","bell"     if headeris "From"     ,'<slashdot@slashdot.org>';
163         store "=freshmeat","bell"    if headeris "From"     ,'<noreply@freshmeat.net>';
164         store "=sourceforge","bell"  if headeris "From"     ,'<noreply@sourceforge.net>';
165         store "=gsmperlcvs","silent" if headeris("From"     ,'<johan@intra.tektonica.com>')
166                                         && $Audit->subject()=~/^'.*' has been updated!$/;
167         store "=libtoold","log"      if headeris "List-Id"  ,'<libtool.gnu.org>';
168         store "=libtoolpat","log"    if headeris "List-Id"  ,'<libtool-patches.gnu.org>';
169         # own webs
170         store "=energie","bell"      if headeris "From"     ,qr/^EnergieWeb/;
171         store "=ats","log"           if headeris("From"     ,'<root@ms.atspraha.cz>')
172                                         || (headeris("From",'<online@ringier.cz>') && headerhas("To",'<blesk@atspraha.cz>'));
173         store "=atscasablanca","log" if headeris "From"     ,'<casablanca@ms.atspraha.cz>';
174
175         # Petr Koutecky does not mark his Stuff
176         store "=koutecky","log"      if headeris "From"     ,'<velkyhroch@seznam.cz>';
177
178         store "=errm","bell"         if $isFROM_MAILER && !did();
179
180         store "==","sms"             if !did;
181 }
182
183 sub audit_sms_address
184 {
185 my($obj)=@_;
186
187         my $address=$obj->address();
188         if (my $alternates=muttrc_get("alternates")) {
189                 return "I" if $address=~/$alternates/si;
190                 }
191         my %aliases=muttrc_aliases();
192         if (my $alias=$aliases{lc $address}) {
193                 local $_=$alias;
194                 s/\b(Bus)siness$/$1/i;
195                 s/\.ident$//i;
196                 return $_;
197                 }
198         local $_=$address;
199         s/\.cz$//i;
200         return $_;
201 }
202
203 sub audit_sms
204 {
205 my(%args)=@_;
206
207         my $from=(@{$args{"from"}} ? join(",",map({ audit_sms_address($_); } @{$args{"from"}})) : "?");
208         local $_;
209
210         $_=$args{"subject"};
211         # headers
212         s/(?:Re|Aw|Odp|Fw|Fwd|OT)(?:\[\d+\])?://ig;
213         # former subject
214         s/\bbylo:.*$//i;
215         s/\[\s*WAS:.*\]\s*$//i;
216         # trim
217         s/^\s*//s;
218         s/\s*$//s;
219         my $subject=$_;
220
221         $_=$args{"body"};
222         # max. 9 lines of .sig
223         s/\n-- (?:\n[^\n]*){0,9}$//gs;
224         # "Original Message"/"Puvodni zprava" etc. up to empty line
225         # "- - - Original message: - - -" is by "Lotus Notes Release 5.0.5  September 22, 2000"
226         s/(^|\n)[\s^\n]*(?:-----[\w\s]*-----|- - - Original message: - - -)[\s^\n]*(?:\n[^\n]+)*\n{2,}(?:\s*[^>\s].*$)?/\n/gs;
227         # Remove "..." lines (is it used by anyone except me?)
228         s/^\Q...\E$/*/gm;
229         # quoting "> "
230         s/^(?:\s*[[:upper:]]{0,3}>)+.*$/*/gm;
231         s/(?:^|\n)(?:\*\n+)+/\n*\n/gs;
232         # attributions
233         s/^.*\b(?:wrote|writes|napsal jste):\s*$//gm;
234         my $body=$_;
235
236         return [$from,"($subject)$body"];
237 }
238
239 1;