=spam: Updates.
[PerlMail.git] / PerlMail / Config.pm
1 #! /usr/bin/perl
2
3 #       $Id$
4 # Copyright (C) 2002-2003 Jan Kratochvil <project-PerlMail@jankratochvil.net>
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20
21 package PerlMail::Config;
22 use vars qw($VERSION);
23 $VERSION=do { my @r=(q$Revision$=~/\d+/g); sprintf "%d.".("%03d"x$#r),@r; };
24 use strict;
25 use warnings;
26
27 require Exporter;
28 use vars qw(@ISA @EXPORT);
29 @ISA=qw(Exporter);
30 @EXPORT=qw(
31                 $HOME
32                 $Mail @ValidUsers $IdleMax $MaxBodySMS @SMSwebRcpt $SMSwebRcpt_username
33                 $Lock_pathname $PeerAddr $Socket_timeout $DB_table $DBI_database $DBI_user $DBI_pwd
34                 $clamscan_waitpid_timeout
35                 $sendmail_orig @addr_addon &FromAddress @h_rcpt @h_from
36                 %audit_profile @sms_squeezes @alternates_host @dnsbl_whitelist
37
38                 $Audit $is_pgp $opt_F $procmailFROM_MAILER $store_ignore $store_ignorenewmail
39                 $store_profile
40                 );
41
42 require Mail::Alias;
43
44
45 BEGIN {
46         for (qw(headerhas store headeris did dnsbl store_muttrc_alternates Received_for parts_linear mime_type
47                         body_first is_multipart mimehead mimebody spamassassin clamscan header_remap lmtp_deliver)) {
48                 eval 'sub '.$_.' { return ::'.$_.'(@_); }';
49                 }
50         }
51
52
53 # perlmail-accept & perlmail-sendmail
54
55 # Various configuration files location is derived from it:
56 our $HOME="/home/lace";
57
58
59 # perlmail-accept
60
61 # Mail folder:
62 our $Mail="$HOME/Mail";
63 # Users respected for the 'idle' state (see $IdleMax):
64 our @ValidUsers=qw(root lace short kratochvil _local);
65 # Maximum number of local console idle seconds while still considered as 'active user':
66 our $IdleMax=10;
67 # Maxium number of bytes to pass to Lingua::EN::Squeeze (performance optimization):
68 our $MaxBodySMS=0x1000;
69 # Telephone number to send SMSes by WWW::SMS to:
70 our @SMSwebRcpt=qw(420 602 431329);
71 # Some WWW::SMS modules require username:
72 our $SMSwebRcpt_username="lace2";
73 our $lmtp_admin="cyrus";
74 our $lmtp_pwd;
75 {
76         local *F;
77         open F,"$HOME/priv/lmtp.${lmtp_admin}.pwd" or die;
78         $lmtp_pwd=<F>;
79         chomp $lmtp_pwd;
80         close F or die;
81         }
82 our $lmtp_user_from="lace";
83 our $lmtp_user_to="lacemail";
84 our $clamscan_waitpid_timeout=3;
85
86
87 # perlmail-submit
88
89 # Global system lock for exclusive $DB_table access:
90 our $Lock_pathname="/tmp/PerlMail.lock";
91 # 'workstation' hostname and port. Hostname may be dyndns:
92 our $PeerAddr="kashome.dyn.jankratochvil.net.:852";
93 #our $PeerAddr="127.0.0.1:2852";
94 # 15sec is NOT enough as the remote peer must complete mail store:
95 our $Socket_timeout=7600;
96 # MySQL table name:
97 our $DB_table="PerlMail_folder";
98 # MySQL database name:
99 our $DBI_database="short";
100 # MySQL user name:
101 our $DBI_user="short";
102 # MySQL user password:
103 our $DBI_pwd=$HOME."/priv/mysql.".$DBI_user.".pwd";
104
105
106 # perlmail-sendmail
107
108 # Lists where <rcpt-USER.AT.HOST@jankratochvil.net> address is generated:
109 my @lists=qw(
110                 tacplus-l@disaster.com
111                 gsm@sh.cvut.cz
112                 n9k@pandora.cz
113                 dev9k@pandora.cz
114                 gsm@pandora.cz
115                 ros-general@reactos.com
116                 ros-kernel@reactos.com
117                 ros-dev@reactos.com
118                 ros-cvs@reactos.com
119                 4cinfo@atrey.karlin.mff.cuni.cz
120                 libtool@gnu.org
121                 libtool-patches@gnu.org
122                 wine-license@winehq.org
123                 gtk-devel-list@gnome.org
124                 gnome-vfs-list@gnome.org
125                 captive-announce-list@jankratochvil.net
126                 captive-list@jankratochvil.net
127                 captive-devel-list@jankratochvil.net
128                 linux-ntfs-announce@lists.sourceforge.net
129                 linux-ntfs-dev@lists.sourceforge.net
130                 orbit-list@gnome.org
131                 devel@kannel.org
132                 automake@gnu.org
133                 autoconf@gnu.org
134                 autoconf-patches@gnu.org
135                 wget-patches@sunsite.dk
136                 wget@sunsite.dk
137                 wineconf@winehq.org
138                 prague-pm@pm.org
139                 dev@httpd.apache.org
140                 asterisk-perl@lists.gnuinter.net
141                 isdn4linux@listserv.isdn4linux.de
142                 libc-alpha@sources.redhat.com
143                 squid-dev@squid-cache.org
144                 );
145                 #4c-list@vellum.cz
146
147 # Pathname of the original sendmail(8) binary:
148 our $sendmail_orig=(-x ($_="/usr/sbin/sendmail-orig") ? $_ : "/usr/sbin/sendmail");
149 # List of addresses to locally Bcc all mails to:
150 # Mail-Alias-1.12 defaults to "/etc/mail/aliases" which does not exist on RedHat sendmail-8.12.5-7
151 # Mail-Alias-1.12 will clutter $_ !
152 our @addr_addon=(Mail::Alias->new("/etc/aliases")->exists("sentout") ? ("sentout") : ());
153
154 our $opt_F;     # imported
155 our $is_pgp;    # imported
156 my %lists=map(($_=>1),@lists);
157 # Generate new From address for the target $rcpt of type Mail::Address.
158 # $iserror is true for "MAIL FROM" RFC821 address, false for "From:" RFC822 address.
159 # Returns: Mail::Address instance.
160 sub FromAddress
161 {
162 my($rcpt,$iserror)=@_;
163
164         my $phrase=(defined $opt_F ? $opt_F : "Jan Kratochvil");
165         {
166                 last if !$is_pgp;
167                 last if $iserror;
168                 local *F;
169                 local $_;
170                 my $filename="$HOME/.gnupg/options";
171                 open F,$filename or do { warn "Open \"$filename\": $!"; last; };
172                 local $/="\n";
173                 my @keys=map((/^\s*default-key\s+(\S+)\s*$/),<F>);
174                 @keys==1 or do { warn "Found ".scalar(@keys)." 'default-key's in your \"$filename\", ignoring"; last; };
175                 close F or warn "Close \"$filename\": $!";
176                 my $default_key=$keys[0];
177                 $default_key=~/^[[:xdigit:]]{8}$/ or do { warn "Invalid 'default-key', ignoring: $default_key"; last; };
178                 return Mail::Address->new(
179                                 $phrase,
180                                 'pgp-'.uc($default_key).'@jankratochvil.net',
181                                 );
182                 }
183         return Mail::Address->new($phrase,'lace@jankratochvil.net') if !$lists{$rcpt->address()};
184         return Mail::Address->new(
185                         $phrase,
186                         'rcpt'
187                                         .'-'
188                                         .(defined($rcpt->user()) ? $rcpt->user() : "NOUSER")
189                                         .".AT."
190                                         .(defined($rcpt->host()) ? $rcpt->host() : "LOCAL")
191                                         .'@jankratochvil.net',
192                         );
193 }
194
195 # RedHat sendmail-8.9.3-20/src/conf.c/HdrInfo[]/\Q/* destination fields */\E
196 # FIXME: Recognize "Resent-$_" headers for -t but when we are in 'resent' mode?
197 our @h_rcpt=(   # case in-sensitive!
198                 "To",
199                 "Cc",
200                 "Bcc",
201                 "Apparently-To",
202                 );
203 # ordering matters; first header found is substituted
204 # last header is subsituted if no one is found
205 our @h_from=(
206                 "Resent-From",
207                 "From",
208                 );
209
210
211 # My-Audit
212
213 # Setup profile names.
214 # First element of /^=/ form copies it referenced profile to be extended.
215 # 'did'    =>did() subroutine will return true for it.
216 # 'syslog' =>Use syslog(3).
217 # 'bell'   =>Bell sound.
218 # 'sms=\d+'=>Send SMS by WWW::SMS with specified maximum # of parts
219 our %audit_profile=(
220                 "btw"   =>["syslog"],
221                 "silent"=>["=btw"   ,"did"],
222                 "log"   =>["=silent","syslog"],
223                 "bell"  =>["=log"   ,"bell"],
224                 "sms"   =>["=bell"  ,"sms=1"],
225                 "crit"  =>["=sms"   ,"sms=3"],
226                 );
227 # Try the squeezing methods in this order:
228 our @sms_squeezes=(
229                 { "SqueezeControl"=>"noconv"                         },
230                 { "SqueezeControl"=>"conv"  ,"SQZ_OPTIMIZE_LEVEL"=>0 },
231                 { "SqueezeControl"=>"conv"  ,"SQZ_OPTIMIZE_LEVEL"=>1 },
232                 { "SqueezeControl"=>"med"   ,"SQZ_OPTIMIZE_LEVEL"=>0 },
233                 { "SqueezeControl"=>"med"   ,"SQZ_OPTIMIZE_LEVEL"=>1 },
234                 { "SqueezeControl"=>"max"   ,"SQZ_OPTIMIZE_LEVEL"=>0 },
235                 { "SqueezeControl"=>"max"   ,"SQZ_OPTIMIZE_LEVEL"=>1 },
236                 );
237 # Hostnames where we had alternate e-mail addresses:
238 our @alternates_host=(
239                 "jabberwock.ucw.cz",    # short@ucw.cz
240                 "atrey.karlin.mff.cuni.cz",     # short@atrey.karlin.mff.cuni.cz
241                 "k332.feld.cvut.cz",    # short@k332.feld.cvut.cz
242                 );
243 # Override DNS blacklists:
244 our @dnsbl_whitelist=(
245                 "195.250.128.83",       # smtp3.vol.cz; vol.cz.multistage.blackholes.five-ten-sg.com.
246                 "64.49.222.22",         # mail.pm.org: rackspace.com.spam-support.blackholes.five-ten-sg.com.
247                 "208.147.243.5",        # gambit.liquidcomm.net: cw.net.spam-support.blackholes.five-ten-sg.com.
248                 "213.235.135.70",       # smtp.tiscali.cz: tiscali.cz.multistage.blackholes.five-ten-sg.com.
249                 "205.139.198.11",       # eniac.disaster.com: cw.net.spam-support.blackholes.five-ten-sg.com.
250                 "127.0.0.2",                    # 2.0.0.127.relays.ordb.org.
251                 "65.113.40.131",        # bozo.vmware.com: qwest.net.spam-support.blackholes.five-ten-sg.com.
252                 "66.218.85.33",         # mta2.wss.scd.yahoo.com: yahoo.com.spam.blackholes.five-ten-sg.com.
253                 "212.80.76.42",         # mx2.seznam.cz: seznam.cz.free.blackholes.five-ten-sg.com.
254                 "64.110.204.63",        # hsdbrg64-110-204-63.sasknet.sk.ca: 64.110.202.181.sasknet.sk.ca.misc.spam.blackholes.five-ten-sg.com.
255                 "212.80.76.44",         # mx1.seznam.cz: 44.76.80.212.blackholes.five-ten-sg.com.
256                 "212.80.76.29",         # prace.seznam.cz: 212.80.76.42.seznam.cz.free.blackholes.five-ten-sg.com
257                 "193.252.22.30",        # smtp1.wanadoo.fr: 30.22.252.193.blackholes.five-ten-sg.com
258                 "213.151.87.16",        # posta.dobnet.cz: 16.87.151.213.relays.ordb.org
259                 );
260
261 our $Audit;     # imported
262 our $procmailFROM_MAILER;       # imported
263 our $store_ignorenewmail;       # imported
264 our $store_profile;     # imported
265 our $store_ignore;      # imported
266 sub audit
267 {
268         $store_profile=undef();
269
270         # never spawn new mail if FROM_MAILER
271         # $isFROM_MAILER postponed after maillists as they may look as FROM_MAILER
272         #use re 'debug';
273         my $isFROM_MAILER=$Audit->header()=~/$procmailFROM_MAILER/mio;
274         $store_ignorenewmail=(0
275                         || $isFROM_MAILER
276                         || headerhas "From",'<Regexp:^owner->'
277                         );
278
279         # spam honeypots
280         return if did sub {
281                 local $_;
282                 # Do not local $store_file as it is our-imported
283                 $store_profile="silent";
284                 store "=spam"         if grep /^\Qshort\@k332.feld.cvut.cz\E/i,Received_for();
285                 # TODO: foreign violation of RFC 822 section 4.4.4, Subject:.*Automatick.+odpov.+v.+nep.+tomnosti
286                 store "=spam"         if headeris "From",'<ghandchi@hotmail.com>';
287                 store "=spam"         if headeris "From",'<newsletter@levnapc.cz>';
288                 store "=spam"         if headeris "From",'<Tomas@dtpstudio.cz>';
289                 store "=spam"         if headeris "From",'<BNcom@email.bn.com>';
290                 store "=spam"         if headeris "From",'<e4luck@lists.opt4email.com>';
291                 store "=spam"         if headeris "From",'<mailcontests@lists.servitall.com>';
292                 store "=spam"         if headeris "From",'<canda@lica.cz>';
293                 store "=spam"         if headeris "From",'<newsletter@thecareernews.com>';
294                 store "=spam"         if headeris "From",'<newsletter@jobseekerweekly.com>';
295                 store "=spam"         if headeris "From",'<newsletter@jobmarketweekly.com>';
296                 store "=spam"         if headeris "From",'<newsletter@career-digest.com>';
297                 for my $header (qw(To Cc)) {
298                         store "=spam" if headerhas $header,'<st@jankratochvil.net>';
299                         store "=spam" if headerhas $header,'<est@jankratochvil.net>';
300                         store "=spam" if headerhas $header,'<uest@jankratochvil.net>';
301                         store "=spam" if headerhas $header,'<kratochvil.net@jankratochvil.net>';
302                         }
303                 {
304                         # weak detection: files with text/html w/o text/plain are usually a spam
305                         my @types_linear=map({ mime_type($_); } parts_linear());
306                         store "=spam"       if grep({ $_ eq "text/html"; } @types_linear) && !grep({ $_ eq "text/plain"; } @types_linear);
307                         }
308                 store "=spam"         if ($_=mimehead(body_first())->mime_attr("Content-Type.charset")) && /^big5/i;
309                 };
310         $store_profile=undef();
311
312         # spam detection
313         return if did sub {
314                 # It is too expensive to scan the huge =caperr announcements by spamassassin(1).
315                 return if headeris("From",qr/^captive-[a-z]*@/);
316                 # Do not local $store_file as it is our-imported
317                 $store_profile="log";
318                 local $_;
319                 store "=spam".";virus=$_"            if $_=clamscan();
320                 store "=spam".";spamassassin".($_ eq 1 ? "" : "=$_") if $_=spamassassin();
321                 store "=spam".";$_"                  if $_=dnsbl '.relays.ordb.org.' ,1;        # all hosts
322                 store "=spam".";$_"                  if $_=dnsbl '.blackholes.mail-abuse.org.' ,1;      # all hosts
323                 # we don't check all hosts as they can be "dialup" category, FIXME: check for it
324 #               store "=spam".";$_"                  if $_=dnsbl '.blackholes.five-ten-sg.com.',0; # just first
325                 # I don't send viruses but viruses propagate mails of mine
326                 store "=spam".";ravmd"               if headeris "X-Mailer",'ravmd/8.3.2';
327                 store "=spam".';short@ucw.cz+MAILER' if $isFROM_MAILER && headeris("To",'<short@ucw.cz>');
328                 if (!is_multipart()) {
329                         local $_=mimebody(body_first());
330                         my %sites=map(($_=>1),qw(
331                                         brandenburg.rz.fhtw-berlin.de
332                                         forum.gofeminin.de
333                                         service.spiegel.de
334                                         www.aufenthaltstitel.de
335                                         www.berlinonline.de
336                                         www.deutschlandchronik.de
337                                         www.heise.de
338                                         www.leverkusener-aufbruch.com
339                                         www.libasoli.de
340                                         www.mjoelnirsseite.de
341                                         www.npd-nrw.net
342                                         www.npd.de
343                                         www.rp-online.de
344                                         www.spiegel.de
345                                         www.taz.de
346                                         www.unserforum.com
347                                         www.zdf.de
348                                         ));
349                         my $found;
350                         while (m{http://([^/]+)/}g) {
351                                 do { $found=1; next; } if $sites{$1};
352                                 $found=0;
353                                 last;
354                                 }
355                         $found=1 if /^\s*Lese selbst:\n/s;
356                         store "=spam".';german-news' if $found;
357                         }
358                 };
359         $store_profile=undef();
360
361         # special delivery
362         store "=err","bell" and return if headerhas \&Received_for,'<short+err@>';
363
364         # ppl-wished foreign remapping, Reply-To is left untouched!
365         # FIXME: modifications are now being dropped by &write_message!
366         header_remap("From",{
367                         'kerere@post.cz'               =>'kamzik@k332.feld.cvut.cz',
368                         'profes@mbox.vol.cz'           =>'kratochvilova@egp.cz',
369                         'jkrouzek@mbox.vol.cz'         =>'krouzek@mbox.fsv.cuni.cz',
370                         'jakub.gorner@lidovky.cz'      =>'tonda@disnet.cz',
371                         'jan.kolar@videoprogress.cz'   =>'jenda.kolar@volny.cz',
372                         'daniel.rulicek@cponline.cz'   =>'daniel.rulicek@cpress.cz',
373                         'pavel@suse.cz'                =>'pavel@ucw.cz',
374                         });
375
376         # My obsolete e-mail addresses
377         store_muttrc_alternates "=redirect-","btw";
378
379         # nasty public lists with $store_ignore
380         {
381                 # Do not local $store_file as it is our-imported
382                 $store_profile="log";
383                 local $store_ignore;
384                 $store_ignore="smsmail"    if 1==$Audit->body() && length(join "",$Audit->body())<180;  # SMS mail
385                 $store_ignore="sms OS"     if $Audit->subject()=~/^Email pro: /;        # "^Email pro: gsm@sh\.cvut\.cz$";
386                 $store_ignore="list-moron" if grep { headeris "From",$_; } qw(
387                                 <kempny@>
388                                 <help.me@wo.cz>
389                                 <mr.death@mail.cz>
390                                 <danx3@centrum.cz>
391                                 <@mujoskar.cz>
392                                 <satko@quanto.nr.sanet.sk>
393                                 <vithous@attorney.cz> <viroman@attorney.cz>
394                                 <konf@klain.cz>
395                                 <stein@tiscali.cz>
396                                 <barevnej@volny.cz>
397                                 );
398
399                 store "=gsm"               if headeris  "X-BeenThere",'<gsm@lists.sh.cvut.cz>';
400                 store "=gsmpand"           if headeris  "List-Post",'<gsm@pandora.cz>';
401                 store "=9kc","log"         if headeris  "List-Post",'<n9k@pandora.cz>';
402                 store "=9kcd","log"        if headeris  "List-Post",'<dev9k@pandora.cz>';
403                 }
404         $store_profile=undef();
405
406         # lists
407         store "=mozillabug","log"    if headeris "From"     ,'<bugzilla-daemon@mozilla.org>';
408         store "=9ku","log"           if headeris "List-Id"  ,'<9000.listman.net>';
409         store "=9kd","log"           if headeris "Sender"   ,'<owner-9000-developers@geekstuff.co.uk>';
410         store "=spong","log"         if headeris "List-Id"  ,'<spong-users.lists.sourceforge.net>';
411         store "=gtkd","silent"       if headeris "List-Id"  ,'<gtk-devel-list.gnome.org>';
412         store "=gnomevfs","log"      if headeris "List-Id"  ,'<gnome-vfs-list.gnome.org>';
413         store "=mffstatnice","bell"  if headeris "List-Post",'<statnice@atrey.karlin.mff.cuni.cz>';
414         store "=hw","log"            if headeris "List-Post",'<hw-news@list.gin.cz>';
415         store "=gnokii","log"        if headeris "List-Id"  ,'<gnokii-users.mail.freesoftware.fsf.org>';
416         store "=winelic","silent"    if headeris "List-Id"  ,'<wine-license.winehq.org>';
417         store "=wined","silent"      if headeris "List-Id"  ,'<wine-devel.winehq.org>';
418         store "=winepat","silent"    if headeris "List-Id"  ,'<wine-patches.winehq.org>';
419         store "=winecvs","silent"    if headeris "List-Id"  ,'<wine-cvs.winehq.org>';
420         store "=wineann","silent"    if headeris "List-Id"  ,'<wine-announce.winehq.org>';
421         store "=wineconf","silent"   if headeris "List-Id"  ,'<wineconf.winehq.org>';
422         store "=ros","silent"        if headeris "List-Id"  ,'<ros-general.reactos.com>';
423         store "=roskernel","silent"  if headeris "List-Id"  ,'<ros-kernel.reactos.com>';
424         store "=rosd","silent"       if headeris "List-Id"  ,'<ros-dev.reactos.com>';
425         store "=roscvs","silent"     if headeris "List-Id"  ,'<ros-cvs.reactos.com>';
426         store "=rossvn","silent"     if headeris "List-Id"  ,'<ros-svn.reactos.com>';
427         store "=rosbug","silent"     if headeris "Reply-To" ,'<scarab@reactos.wox.org>';
428         store "=fsd","silent"        if headeris "X-Mailing-List",'<linux-fsdevel@vger.kernel.org>';
429         store "=kernel","silent"     if headeris "X-Mailing-List",'<linux-kernel@vger.kernel.org>';
430         store "=kernelnet","silent"  if headeris "X-Mailing-List",'<linux-net@vger.kernel.org>';
431         store "=ia64","silent"       if headeris "X-Mailing-List",'<linux-ia64@vger.kernel.org>';
432         store "=linuxjap","silent"   if headeris "X-Mailing-List",'<linux-japanese@vger.kernel.org>';
433         store "=kernelann","silent"  if headeris "X-Mailing-List",'<linux-kernel-announce@vger.kernel.org>';
434         store "=sparse","silent"     if headeris "X-Mailing-List",'<linux-sparse@vger.kernel.org>';
435         store "=smp","silent"        if headeris "X-Mailing-List",'<linux-smp@vger.kernel.org>';
436         store "=surprise","sms"      if headeris "List-Post",'<surprise@atrey.karlin.mff.cuni.cz>';
437         store "=surprisesuse","sms"  if headeris "Sender"   ,'<owner-surprise@suse.cz>';
438         store "=tacacs","silent"     if headeris "Sender"   ,'<tacplus-l@disaster.com>';
439         store "=tacacs","silent"     if headeris "Sender"   ,'<owner-tacplus-l@disaster.com>';
440         store "=tacacs","silent"     if headeris "List-Id"  ,'<devel.lists.tacplus.org>';
441         store "=pm","log"            if headeris "List-Id"  ,'<prague-pm.pm.org>';
442         store "=radary","log"        if headeris "Reply-To" ,'<pha@radary.cz>';
443         store "=dnet","log"          if headeris "Sender"   ,'<@lists.distributed.net>';
444         store "=linux-input","log"   if headeris "List-Post",'<linux-input@atrey.karlin.mff.cuni.cz>';
445         store "=strom","bell"        if headeris "List-Post",'<vodni-strom@atrey.karlin.mff.cuni.cz>';
446         store "=netinfo","log"       if headeris "Sender"   ,'<owner-netinfo-l@vol.cz>';
447         store "=saintmj","log"       if headeris "From"     ,'<nagios@kam-enterprise.ms.mff.cuni.cz>';
448         store "=saintmj","log"       if headeris "From"     ,'<nagios@kam.mff.cuni.cz>';
449         store "=saintmj","log"       if headeris "From"     ,'<netsaint@kam.mff.cuni.cz>';
450         store "=saintjk","log"       if headeris "From"     ,'<nagios@gw.jklabs.cz>';
451         store "=saintjk2","log"      if headeris("From"     ,'<jklabs@manon.vellum.cz>')
452                                      && headeris("To"       ,'<jklabs-nagios@jankratochvil.net>');
453         store "=4cerr","bell"        if headeris "From"     ,'<owner-4cinfo@atrey.karlin.mff.cuni.cz>';
454         store "=4c","sms"            if headeris "List-Post",'<4cinfo@atrey.karlin.mff.cuni.cz>';
455         store "=slashdot","bell"     if headeris "From"     ,'<slashdot@slashdot.org>';
456         store "=freshmeat","bell"    if headeris "From"     ,'<noreply@freshmeat.net>';
457         store "=sourceforge","bell"  if headeris "From"     ,'<noreply@sourceforge.net>';
458         store "=gsmperlcvs","silent" if headeris("From"     ,'<johan@intra.tektonica.com>')
459                                         && $Audit->subject()=~/^'.*' has been updated!$/;
460         store "=libtoold","silent"   if headeris "List-Id"  ,'<libtool.gnu.org>';
461         store "=libtoolpat","silent" if headeris "List-Id"  ,'<libtool-patches.gnu.org>';
462         store "=automake","silent"   if headeris "List-Id"  ,'<automake.gnu.org>';
463         store "=autoconf","log"      if headeris "List-Id"  ,'<autoconf.gnu.org>';
464         store "=autoconfpat","log"   if headeris "List-Id"  ,'<autoconf-patches.gnu.org>';
465         store "=hurd","log"          if headeris "List-Id"  ,'<l4-hurd.gnu.org>';
466         store "=gccbug","silent"     if headeris "List-Post",'<gcc-bugs@gcc.gnu.org>';
467         store "=gccann","log"        if headeris "List-Post",'<gcc-announce@gcc.gnu.org>';
468         store "=gcc","silent"        if headeris "List-Post",'<gcc@gcc.gnu.org>';
469         store "=gccpat","silent"     if headeris "List-Post",'<gcc-patches@gcc.gnu.org>';
470         my %mailman=(
471                         '<captive-admin@>'=>"=caperr",
472                         '<captive-devel-admin@>'=>"=caperr",
473                         '<captive-announce-admin@>'=>"=caperr",
474                         '<4c-admin@>'=>"=4cerr",
475                         );
476         if (!did sub {
477                         while ((my($mailaddr,$folder)=each(%mailman))) {
478                                 (my $maillistaddr=$mailaddr)=~s/-admin/-list$&/;
479                                 store $folder,"log" if (headeris("From",'<mailman-owner@vellum.cz>')&&headeris("To",$mailaddr))
480                                                 || headeris("From",$maillistaddr)
481                                                 || headeris("To",$maillistaddr)
482                                                 || headeris("From",$mailaddr);
483                                 }
484                         }) {
485                 store "=cap","bell"        if headeris "List-Id"  ,'<captive-list.jankratochvil.net>';
486                 store "=capd","bell"       if headeris "List-Id"  ,'<captive-devel-list.jankratochvil.net>';
487                 store "=capann","bell"     if headeris "List-Id"  ,'<captive-announce-list.jankratochvil.net>';
488                 store "=4c","bell"         if headeris "List-Id"  ,'<4c-list.vellum.cz>';
489                 }
490         store "=ntfsann","silent"    if headeris "List-Id"  ,'<linux-ntfs-announce.lists.sourceforge.net>';
491         store "=ntfsd","silent"      if headeris "List-Id"  ,'<linux-ntfs-dev.lists.sourceforge.net>';
492         store "=orbit","silent"      if headeris "List-Id"  ,'<orbit-list.gnome.org>';
493         store "=kannel","log"        if headeris "List-Id"  ,'<users.kannel.org>';
494         store "=kanneld","log"       if headeris "List-Id"  ,'<devel.kannel.org>';
495         store "=mailmand","silent"   if headeris "List-Id"  ,'<mailman-developers.python.org>';
496         store "=asterisk-perl","log" if headeris "List-Post",'<asterisk-perl@lists.gnuinter.net>';
497         store "=i4l","silent"        if headeris "List-Id"  ,'<isdn4linux.listserv.isdn4linux.de>';
498         store "=glibc","silent"      if headeris "List-Post",'<libc-alpha@sourceware.org>';
499         store "=fedann","bell"       if headeris "List-Id"  ,'<fedora-announce-list.redhat.com>';
500         store "=fedpkg","bell"       if headeris "List-Id"  ,'<fedora-package-announce.redhat.com>';
501         store "=fedtools","log"      if headeris "List-Id"  ,'<fedora-tools-list.redhat.com>';
502         store "=bashbug","log"       if headeris "List-Id"  ,'<bug-bash.gnu.org>';
503         store "=zaurus","silent"     if headeris "List-Id"  ,'<openzaurus-users.lists.sourceforge.net>';
504         store "=zaurusann","log"     if headeris "List-Id"  ,'<openzaurus-announce.lists.sourceforge.net>';
505         store "=zaurusd","silent"    if headeris "List-Id"  ,'<openzaurus-devel.lists.sourceforge.net>';
506         store "=zaurussoft","silent" if headeris "List-Id"  ,'<openzaurus-software.lists.sourceforge.net>';
507         store "=iptperl","silent"    if headeris "List-Id"  ,'<iptperl-general.lists.sourceforge.net>';
508         # own webs
509         store "=energie","bell"      if headeris "From"     ,qr/^EnergieWeb/;
510         store "=ats","log"           if headeris("From"     ,'<root@ms.atspraha.cz>')
511                                         || (headeris("From",'<online@ringier.cz>') && headerhas("To",'<blesk@atspraha.cz>'));
512         store "=atscasablanca","log" if headeris "From"     ,'<casablanca@ms.atspraha.cz>';
513         store "=www-sms","log"       if headeris "List-Id"  ,'<www-sms-developers.lists.sourceforge.net>';
514         store "=httpdd","log"        if headeris "list-post",'<dev@httpd.apache.org>';
515         store "=mms2log","log"       if headeris "Return-Path",'<root@node0.mms2.org>';
516         store "=hotelgatelog","log"  if headeris "Return-Path",'<root@hotelgate.hotelnet>';
517         store "=imja","log"          if headeris "List-Id"  ,'<im-ja-devel.lists.sourceforge.net>';
518         store "=wince","log"         if headeris "List-Post",'<wince@pandora.cz>';
519         store "=mysqlperl","log"     if headeris "List-Id"  ,'<perl.mysql.com>';
520         store "=whiteann","log"      if headeris "List-Id"  ,'<whitebox-announce.beau.org>';
521         store "=white","log"         if headeris "List-Id"  ,'<whitebox-users.beau.org>';
522         store "=centos","log"        if headeris "List-Id"  ,'<centos.centos.org>';
523         store "=modperldoc","log"    if headeris "List-Id"  ,'<docs-dev.perl.apache.org>';
524         store "=qemud","log"         if headeris "List-Id"  ,'<qemu-devel.nongnu.org>';
525         store "=diamond","log"       if headeris "X-Replicator-Inst",'"www.diamondcard.us"';
526         store "=soap","log"          if headeris "Sender"   ,'<owner-soap@DISCUSS.DEVELOP.COM>';
527         store "=nagiosd","log"       if headeris "List-Id"  ,'<nagios-devel.lists.sourceforge.net>';
528         store "=nagios","log"        if headeris "List-Id"  ,'<nagios-users.lists.sourceforge.net>';
529         store "=grub","log"          if headeris "List-Id"  ,'<grub-devel.gnu.org>';
530         store "=gdb","log"           if headeris "Mailing-List",'contact gdb-help@sourceware.org; run by ezmlm';
531         store "=gdbpr","log"         if headeris "Mailing-List",'contact gdb-prs-help@sourceware.org; run by ezmlm';
532         store "=gdbpat","log"        if headeris "Mailing-List",'contact gdb-patches-help@sourceware.org; run by ezmlm';
533         store "=gdbann","log"        if headeris "Mailing-List",'contact gdb-announce-help@sourceware.org; run by ezmlm';
534         store "=binutils","log"      if headeris "Mailing-List",'contact binutils-help@sourceware.org; run by ezmlm';
535         store "=binutilsbug","log"   if headeris "List-Id"  ,'<bug-binutils.gnu.org>';
536
537         # Petr Koutecky does not mark his Stuff
538         store "=koutecky","log"      if headeris "Return-Path",'<velkyhroch@seznam.cz>';
539         store "=koutecky","log"      if headeris "Return-Path",'<pk.petr@centrum.cz>';
540         store "=koutecky","log"      if headeris "Return-Path",'<petr.koutecky@premisa.cz>';
541         store "=koutecky","log"      if headeris "Return-Path",'<Petr.Koutecky@pr4.pm.ds.mfcr.cz>';
542
543         if (($isFROM_MAILER && !did) || !did) {
544 #               lmtp_deliver $lmtp_admin,$lmtp_pwd,$lmtp_user_from,$lmtp_user_to;
545                 }
546
547         store "=errm","bell"         if $isFROM_MAILER && !did();
548
549         if (!did) {
550                 store "==","sms";
551                 spamassassin "sa-learn --ham";
552                 }
553 }
554
555 sub audit_sms_address
556 {
557 my($obj)=@_;
558
559         my $address=$obj->address();
560         if (my $alternates=muttrc_get("alternates")) {
561                 return "I" if $address=~/$alternates/si;
562                 }
563         my %aliases=muttrc_aliases();
564         if (my $alias=$aliases{lc $address}) {
565                 local $_=$alias;
566                 s/\b(Bus)siness$/$1/i;
567                 s/\.ident$//i;
568                 return $_;
569                 }
570         local $_=$address;
571         s/\.cz$//i;
572         return $_;
573 }
574
575 # $args{"from"}
576 # $args{"subject"}
577 # $args{"body"}
578 sub audit_sms
579 {
580 my(%args)=@_;
581
582         my $from=(@{$args{"from"}} ? join(",",map({ audit_sms_address($_); } @{$args{"from"}})) : "?");
583         local $_;
584
585         $_=$args{"subject"};
586         # headers
587         s/(?:Re|Aw|Odp|Fw|Fwd|OT)(?:\[\d+\])?://ig;
588         # former subject
589         s/\bbylo:.*$//i;
590         s/\[\s*WAS:.*\]\s*$//i;
591         # trim
592         s/^\s*//s;
593         s/\s*$//s;
594         my $subject=$_;
595
596         $_=$args{"body"};
597         # max. 9 lines of .sig
598         s/\n-- (?:\n[^\n]*){0,9}$//gs;
599         # "Original Message"/"Puvodni zprava" etc. up to empty line
600         # "- - - Original message: - - -" is by "Lotus Notes Release 5.0.5  September 22, 2000"
601         s/(^|\n)[\s^\n]*(?:-----[\w\s]*-----|- - - Original message: - - -)[\s^\n]*(?:\n[^\n]+)*\n{2,}(?:\s*[^>\s].*$)?/\n/gs;
602         # Remove "..." lines (is it used by anyone except me?)
603         s/^\Q...\E$/*/gm;
604         # quoting "> "
605         s/^(?:\s*[[:upper:]]{0,3}>)+.*$/*/gm;
606         s/(?:^|\n)(?:\*\n+)+/\n*\n/gs;
607         # attributions
608         s/^.*\b(?:wrote|writes|napsal jste):\s*$//gm;
609         my $body=$_;
610
611         return [$from,"($subject)$body"];
612 }
613
614 1;