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