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