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