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