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