d6e924f3bef6b2630be38e89caf142ba1b4a0a38
[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 honeypots
43         return if did sub {
44                 local $_;
45                 local $store_profile="silent";
46                 store "=spamo-k332"   if grep /^\Qshort\@k332.feld.cvut.cz\E/i,Received_for();
47                 # TODO: foreign violation of RFC 822 section 4.4.4, Subject:.*Automatick.+odpov.+v.+nep.+tomnosti
48                 store "=spamo"        if headeris "From",'<ghandchi@hotmail.com>';
49                 store "=spamo"        if headeris "From",'<newsletter@levnapc.cz>';
50                 store "=spamo"        if headeris "From",'<Tomas@dtpstudio.cz>';
51                 store "=spamo"        if headeris "From",'<BNcom@email.bn.com>';
52                 {
53                         # weak detection: files with text/html w/o text/plain are usually a spam
54                         my @types_linear=map({ mime_type($_); } parts_linear());
55                         store "=spamo-html" if grep({ $_ eq "text/html"; } @types_linear) && !grep({ $_ eq "text/plain"; } @types_linear);
56                         }
57                 store "=spamo-big5" if ($_=mimehead(body_first())->mime_attr("Content-Type.charset")) && /^big5/i;
58                 };
59
60         # spam detection
61         return if did sub {
62                 local $store_profile="silent";
63                 local $_;
64                 store "=spam-abuse"                .";$_","log" if $_=dnsbl '.blackholes.mail-abuse.org.' ,1;   # all hosts
65                 # we don't check all hosts as they can be "dialup" category, FIXME: check for it
66                 store "=spam-five"                 .";$_","log" if $_=dnsbl '.blackholes.five-ten-sg.com.',0; # just first
67                 store "=spam-razor".($_ eq 1 ? "" : ";$_")      if $_=razor2();
68                 # I don't send viruses but viruses propagate mails of mine
69                 store "=spam-av"                                if headeris "X-Mailer",'ravmd/8.3.2';
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 "=rosbug","bell"       if headeris "Reply-To" ,'<scarab@reactos.wox.org>';
131         store "=fsd","log"           if headeris "X-Mailing-List",'<linux-fsdevel@vger.kernel.org>';
132         store "=surprise","sms"      if headeris "List-Post",'<surprise@atrey.karlin.mff.cuni.cz>';
133         store "=surprisesuse","sms"  if headeris "Sender"   ,'<owner-surprise@suse.cz>';
134         store "=tacacs","log"        if headeris "Sender"   ,'<tacplus-l@disaster.com>';
135         store "=tacacsd","log"       if headerhas \&Received_for,'devel@tacplus.org';   # TODO: fix when real list
136         store "=pm","sms"            if headeris "Sender"   ,'<owner-prague-pm@pm.org>';
137         store "=radary","log"        if headeris "Reply-To" ,'<pha@radary.cz>';
138         store "=dnet","log"          if headeris "Sender"   ,'<@lists.distributed.net>';
139         store "=linux-input","log"   if headeris "List-Post",'<linux-input@atrey.karlin.mff.cuni.cz>';
140         store "=strom","bell"        if headeris "List-Post",'<vodni-strom@atrey.karlin.mff.cuni.cz>';
141         store "=netinfo","log"       if headeris "Sender"   ,'<owner-netinfo-l@vol.cz>';
142         store "=saintmj","log"       if headeris "From"     ,'<netsaint@kam-enterprise.ms.mff.cuni.cz>';
143         store "=saintmj","log"       if headeris "From"     ,'<netsaint@kam.mff.cuni.cz>';
144         store "=4cerr","bell"        if headeris "From"     ,'<owner-4cinfo@atrey.karlin.mff.cuni.cz>';
145         store "=4c","sms"            if headeris "List-Post",'<4cinfo@atrey.karlin.mff.cuni.cz>';
146         store "=slashdot","bell"     if headeris "From"     ,'<slashdot@slashdot.org>';
147         store "=freshmeat","bell"    if headeris "From"     ,'<noreply@freshmeat.net>';
148         store "=sourceforge","bell"  if headeris "From"     ,'<noreply@sourceforge.net>';
149         store "=gsmperlcvs","silent" if headeris("From"     ,'<johan@intra.tektonica.com>')
150                                         && $Audit->subject()=~/^'.*' has been updated!$/;
151         # own webs
152         store "=energie","bell"      if headeris "From"     ,qr/^EnergieWeb/;
153
154         # Petr Koutecky does not mark his Stuff
155         store "=koutecky","log"      if headeris "From"     ,'<velkyhroch@seznam.cz>';
156
157         store "=errm","bell"         if $isFROM_MAILER && !did();
158
159         store "==","sms"             if !did;
160 }
161
162 sub audit_sms_address
163 {
164 my($obj)=@_;
165
166         my $address=$obj->address();
167         if (my $alternates=muttrc_get("alternates")) {
168                 return "I" if $address=~/$alternates/si;
169                 }
170         my %aliases=muttrc_aliases();
171         if (my $alias=$aliases{lc $address}) {
172                 local $_=$alias;
173                 s/\.cz$//i;
174                 return $_;
175                 }
176         local $_=$address;
177         s/\b(Bus)siness$/$1/i;
178         s/\.ident$//i;
179         return $_;
180 }
181
182 sub audit_sms
183 {
184 my(%args)=@_;
185
186         my $from=(@{$args{"from"}} ? join(",",map({ audit_sms_address($_); } @{$args{"from"}})) : "?");
187         local $_;
188
189         $_=$args{"subject"};
190         # headers
191         s/(?:Re|Aw|Odp|Fw|Fwd|OT)(?:\[\d+\])?://ig;
192         # former subject
193         s/\bbylo:.*$//i;
194         s/\[\s*WAS:.*\]\s*$//i;
195         # trim
196         s/^\s*//s;
197         s/\s*$//s;
198         my $subject=$_;
199
200         $_=$args{"body"};
201         # max. 9 lines of .sig
202         s/\n-- (?:\n[^\n]*){0,9}$//gs;
203         # "Original Message"/"Puvodni zprava" etc. up to empty line
204         # "- - - Original message: - - -" is by "Lotus Notes Release 5.0.5  September 22, 2000"
205         s/(^|\n)[\s^\n]*(?:-----[\w\s]*-----|- - - Original message: - - -)[\s^\n]*(?:\n[^\n]+)*\n{2,}(?:\s*[^>\s].*$)?/\n/gs;
206         # Remove "..." lines (is it used by anyone except me?)
207         s/^\Q...\E$/*/gm;
208         # quoting "> "
209         s/^(?:\s*[[:upper:]]{0,3}>)+.*$/*/gm;
210         s/(?:^|\n)(?:\*\n+)+/\n*\n/gs;
211         # attributions
212         s/^.*\b(?:wrote|writes|napsal jste):\s*$//gm;
213         my $body=$_;
214
215         return [$from,"($subject)$body"];
216 }
217
218 1;