First production sendmail(8) wrapper
[PerlMail.git] / My-Audit.pm
1 # $Id$
2
3 sub audit_init
4 {
5         %audit_profile=(
6                         "btw"   =>[],
7                         "silent"=>["=btw"   ,"did","syslog"],
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 }
23
24 sub audit
25 {
26         {
27                 local $store_ignorenewmail=1;   # no reason now, just a paranoia
28                 store "=input","btw";
29                 }
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-rbl"                  .";$_"  if $_=$Audit->rblcheck();
47                 store "=spam-razor".($_ eq 1 ? "" : ";$_") if $_=razor2();
48                 # I don't send viruses but viruses propagate mails of mine
49                 store "=spam-av"                           if headeris "X-Mailer",'ravmd/8.3.2';
50                 };
51
52         # spam honeypots
53         return if did sub {
54                 local $_;
55                 local $store_profile="silent";
56                 store "=spamo-k332"   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 "=spamo"        if headeris "From",'<ghandchi@hotmail.com>';
59                 store "=spamo"        if headeris "From",'<newsletter@levnapc.cz>';
60                 store "=spamo"        if headeris "From",'<Tomas@dtpstudio.cz>';
61                 {
62                         # weak detection: files with text/html w/o text/plain are usually a spam
63                         my @types_linear=map({ mime_type($_); } parts_linear());
64                         store "=spamo-html" if grep({ $_ eq "text/html"; } @types_linear) && !grep({ $_ eq "text/plain"; } @types_linear);
65                         }
66                 store "=spamo-big5" if ($_=mimehead(body_first())->mime_attr("Content-Type.charset")) && /^big5/i;
67                 };
68
69         # special delivery
70         store "=err","bell" and return if headerhas \&Received_for,'<short+err@>';
71
72         # ppl-wished foreign remapping, Reply-To is left untouched!
73         header_remap("From",{
74                         'kerere@post.cz'            =>'kamzik@k332.feld.cvut.cz',
75                         'profes@mbox.vol.cz'        =>'kratochvilova@egp.cz',
76                         'jkrouzek@mbox.vol.cz'      =>'krouzek@mbox.fsv.cuni.cz',
77                         'jakub.gorner@lidovky.cz'   =>'tonda@disnet.cz',
78                         'jan.kolar@videoprogress.cz'=>'jenda.kolar@volny.cz',
79                         'daniel.rulicek@cponline.cz'=>'daniel.rulicek@cpress.cz',
80                         'pavel@suse.cz'             =>'pavel@ucw.cz',
81                         });
82
83         # My obsolete e-mail addresses
84         store_muttrc_alternates "=redirect-","btw";
85
86         # nasty public lists with $store_ignore
87         {
88                 local $store_profile="bell";
89                 local $store_ignore;
90                 $store_ignore="smsmail"    if 1==$Audit->body() && length(join "",$Audit->body())<180;  # SMS mail
91                 $store_ignore="sms OS"     if $Audit->subject()=~/^Email pro: /;        # "^Email pro: gsm@sh\.cvut\.cz$";
92                 $store_ignore="list-moron" if grep { headeris "From",$_; } qw(
93                                 <kempny@>
94                                 <help.me@wo.cz>
95                                 <mr.death@mail.cz>
96                                 <danx3@centrum.cz>
97                                 <@mujoskar.cz>
98                                 <satko@quanto.nr.sanet.sk>
99                                 <vithous@attorney.cz> <viroman@attorney.cz>
100                                 <konf@klain.cz>
101                                 );
102
103                 store "=gsm"               if headeris  "Sender"   ,'<owner-gsm@sh.cvut.cz>';
104                 store "=gsmpand"           if headeris  "List-Post",'<gsm@pandora.cz>';
105                 }
106
107         # lists
108         store "=mozillabug","log"    if headeris "From"     ,'<bugzilla-daemon@mozilla.org>';
109         store "=9kc","bell"          if headeris "List-Post",'<n9k@pandora.cz>';
110         store "=9kcd","bell"         if headeris "List-Post",'<dev9k@pandora.cz>';
111         store "=9ku","log"           if headeris "List-Id"  ,'<9000.listman.net>';
112         store "=9kd","log"           if headeris "Sender"   ,'<owner-9000-developers@geekstuff.co.uk>';
113         store "=spong","log"         if headeris "List-Id"  ,'<spong-users.lists.sourceforge.net>';
114         store "=gtkd","log"          if headeris "List-Id"  ,'<gtk-devel-list.gnome.org>';
115         store "=mffstatnice","bell"  if headeris "List-Post",'<statnice@atrey.karlin.mff.cuni.cz>';
116         store "=hw","log"            if headeris "List-Post",'<hw-news@list.gin.cz>';
117         store "=gnokii","bell"       if headeris "List-Id"  ,'<gnokii-users.mail.freesoftware.fsf.org>';
118         store "=winelic","log"       if headeris "List-Id"  ,'<wine-license.winehq.com>';
119         store "=wined","log"         if headeris "List-Id"  ,'<wine-devel.winehq.com>';
120         store "=winepat","log"       if headeris "List-Id"  ,'<wine-patches.winehq.com>';
121         store "=winecvs","silent"    if headeris "List-Id"  ,'<wine-cvs.winehq.com>';
122         store "=ros","log"           if headeris "List-Post",'<ros-general@reactos.com>';
123         store "=roskernel","bell"    if headeris "List-Post",'<ros-kernel@reactos.com>';
124         store "=roscvs","silent"     if headeris "List-Post",'<ros-cvs@reactos.com>';
125         store "=fsd","log"           if headeris "X-Mailing-List",'<linux-fsdevel@vger.kernel.org>';
126         store "=surprise","sms"      if headeris "List-Post",'<surprise@atrey.karlin.mff.cuni.cz>';
127         store "=surprisesuse","sms"  if headeris "Sender"   ,'<owner-surprise@suse.cz>';
128         store "=tacacs","log"        if headeris "Sender"   ,'<tacplus-l@disaster.com>';
129         store "=pm","sms"            if headeris "Sender"   ,'<owner-prague-pm@pm.org>';
130         store "=radary","sms"        if headeris "Reply-To" ,'<pha@radary.cz>';
131         store "=dnet","log"          if headeris "Sender"   ,'<@lists.distributed.net>';
132         store "=linux-input","log"   if headeris "List-Post",'<linux-input@atrey.karlin.mff.cuni.cz>';
133         store "=strom","bell"        if headeris "List-Post",'<vodni-strom@atrey.karlin.mff.cuni.cz>';
134         store "=netinfo","log"       if headeris "Sender"   ,'<owner-netinfo-l@vol.cz>';
135         store "=saintmj","log"       if headeris "From"     ,'<netsaint@kam-enterprise.ms.mff.cuni.cz>';
136         store "=saintmj","log"       if headeris "From"     ,'<netsaint@kam.mff.cuni.cz>';
137         store "=4cerr","bell"        if headeris "From"     ,'<owner-4cinfo@atrey.karlin.mff.cuni.cz>';
138         store "=4c","sms"            if headeris "List-Post",'<4cinfo@atrey.karlin.mff.cuni.cz>';
139         store "=slashdot","bell"     if headeris "From"     ,'<slashdot@slashdot.org>';
140         store "=freshmeat","bell"    if headeris "From"     ,'<noreply@freshmeat.net>';
141         store "=gsmperlcvs","silent" if headeris("From"     ,'<johan@intra.tektonica.com>')
142                                         && $Audit->subject()=~/^'.*' has been updated!$/;
143         # own webs
144         store "=energie","bell"      if headeris "From"     ,qr/^EnergieWeb/;
145
146         # Petr Koutecky does not mark his Stuff
147         store "=koutecky","bell"     if headeris "From"     ,'<velkyhroch@seznam.cz>';
148
149         store "=errm","bell"         if $isFROM_MAILER && !did();
150
151         store "==","sms"             if !did;
152 }
153
154 sub audit_sms
155 {
156 my(%args)=@_;
157
158         my $from=(@{$args{"from"}} ? join(",",map({
159                         s/\.cz$//i;
160                         $_;
161                         } @{$args{"from"}})) : "?");
162         local $_=$args{"body"};
163
164         # max. 9 lines of .sig
165         s/\n-- (?:\n[^\n]*){0,9}$//gs;
166         # "Original Message"/"Puvodni zprava" etc. up to empty line
167         s/(^|\n)[\s^\n]*-----[\w\s]*-----[\s^\n]*(?:\n[^\n]+)*\n{2,}(?:\s*[^>\s].*$)?/\n/gs;
168         # Remove "..." lines (is it used by anyone except me?)
169         s/^\Q...\E$/*/gm;
170         # quoting "> "
171         s/^\s*[>][>\s]*.*$/*/gm;
172         s/(?:^|\n)(?:\*\n+)+/\n*\n/gs;
173         # attributions
174         s/^On.*\b(?:wrote|writes):\s*$//gm;
175
176         return [$from,"(".$args{"subject"}.")".$_];
177 }
178
179 1;