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