9ca80cb7ea90ed57c85efd0f21292cf013ccfd2e
[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                 $sendmail_orig @addr_addon &FromAddress @h_rcpt @h_from
35                 %audit_profile @sms_squeezes @alternates_host @dnsbl_whitelist
36
37                 $Audit $is_pgp $opt_F $procmailFROM_MAILER $store_ignore $store_ignorenewmail
38                 $store_profile
39                 );
40
41 require Mail::Alias;
42
43
44 BEGIN {
45         for (qw(headerhas store headeris did dnsbl store_muttrc_alternates Received_for parts_linear mime_type
46                         body_first mimehead spamassassin header_remap)) {
47                 eval 'sub '.$_.' { return ::'.$_.'(@_); }';
48                 }
49         }
50
51
52 # perlmail-accept & perlmail-sendmail
53
54 # Various configuration files location is derived from it:
55 our $HOME="/home/lace";
56
57
58 # perlmail-accept
59
60 # Mail folder:
61 our $Mail="$HOME/Mail";
62 # Users respected for the 'idle' state (see $IdleMax):
63 our @ValidUsers=qw(root lace short kratochvil _local);
64 # Maximum number of local console idle seconds while still considered as 'active user':
65 our $IdleMax=10;
66 # Maxium number of bytes to pass to Lingua::EN::Squeeze (performance optimization):
67 our $MaxBodySMS=0x1000;
68 # Telephone number to send SMSes by WWW::SMS to:
69 our @SMSwebRcpt=qw(420 602 431329);
70 # Some WWW::SMS modules require username:
71 our $SMSwebRcpt_username="lace2";
72
73
74 # perlmail-submit
75
76 # Global system lock for exclusive $DB_table access:
77 our $Lock_pathname="/tmp/PerlMail.lock";
78 # 'workstation' hostname and port. Hostname may be dyndns:
79 our $PeerAddr="exuhome.dyn.jankratochvil.net.:852";
80 #our $PeerAddr="127.0.0.1:2852";
81 # 15sec is NOT enough as the remote peer must complete mail store:
82 our $Socket_timeout=7600;
83 # MySQL table name:
84 our $DB_table="PerlMail_folder";
85 # MySQL database name:
86 our $DBI_database="short";
87 # MySQL user name:
88 our $DBI_user="short";
89 # MySQL user password:
90 our $DBI_pwd=$HOME."/priv/mysql.".$DBI_user.".pwd";
91
92
93 # perlmail-sendmail
94
95 # Lists where <rcpt-USER.AT.HOST@jankratochvil.net> address is generated:
96 my @lists=qw(
97                 tacplus-l@disaster.com
98                 gsm@sh.cvut.cz
99                 linux-fsdevel@vger.kernel.org
100                 n9k@pandora.cz
101                 dev9k@pandora.cz
102                 gsm@pandora.cz
103                 ros-general@reactos.com
104                 ros-kernel@reactos.com
105                 ros-dev@reactos.com
106                 ros-cvs@reactos.com
107                 4cinfo@atrey.karlin.mff.cuni.cz
108                 libtool@gnu.org
109                 libtool-patches@gnu.org
110                 wine-license@winehq.org
111                 wine-devel@winehq.org
112                 wine-patches@winehq.org
113                 gtk-devel-list@gnome.org
114                 gnome-vfs-list@gnome.org
115                 captive-announce-list@jankratochvil.net
116                 captive-list@jankratochvil.net
117                 captive-devel-list@jankratochvil.net
118                 linux-ntfs-announce@lists.sourceforge.net
119                 linux-ntfs-dev@lists.sourceforge.net
120                 orbit-list@gnome.org
121                 devel@kannel.org
122                 automake@gnu.org
123                 autoconf@gnu.org
124                 autoconf-patches@gnu.org
125                 wget-patches@sunsite.dk
126                 wget@sunsite.dk
127                 mailman-developers@python.org
128                 wineconf@winehq.org
129                 prague-pm@pm.org
130                 dev@httpd.apache.org
131                 asterisk-perl@lists.gnuinter.net
132                 isdn4linux@listserv.isdn4linux.de
133                 libc-alpha@sources.redhat.com
134                 squid-dev@squid-cache.org
135                 );
136                 #4c-list@vellum.cz
137
138 # Pathname of the original sendmail(8) binary:
139 our $sendmail_orig=(-x ($_="/usr/sbin/sendmail-orig") ? $_ : "/usr/sbin/sendmail");
140 # List of addresses to locally Bcc all mails to:
141 # Mail-Alias-1.12 defaults to "/etc/mail/aliases" which does not exist on RedHat sendmail-8.12.5-7
142 # Mail-Alias-1.12 will clutter $_ !
143 our @addr_addon=(Mail::Alias->new("/etc/aliases")->exists("sentout") ? ("sentout") : ());
144
145 our $opt_F;     # imported
146 our $is_pgp;    # imported
147 my %lists=map(($_=>1),@lists);
148 # Generate new From address for the target $rcpt of type Mail::Address.
149 # $iserror is true for "MAIL FROM" RFC821 address, false for "From:" RFC822 address.
150 # Returns: Mail::Address instance.
151 sub FromAddress
152 {
153 my($rcpt,$iserror)=@_;
154
155         my $phrase=(defined $opt_F ? $opt_F : "Jan Kratochvil");
156         {
157                 last if !$is_pgp;
158                 last if $iserror;
159                 local *F;
160                 local $_;
161                 my $filename="$HOME/.gnupg/options";
162                 open F,$filename or do { warn "Open \"$filename\": $!"; last; };
163                 local $/="\n";
164                 my @keys=map((/^\s*default-key\s+(\S+)\s*$/),<F>);
165                 @keys==1 or do { warn "Found ".scalar(@keys)." 'default-key's in your \"$filename\", ignoring"; last; };
166                 close F or warn "Close \"$filename\": $!";
167                 my $default_key=$keys[0];
168                 $default_key=~/^[[:xdigit:]]{8}$/ or do { warn "Invalid 'default-key', ignoring: $default_key"; last; };
169                 return Mail::Address->new(
170                                 $phrase,
171                                 'pgp-'.uc($default_key).'@jankratochvil.net',
172                                 );
173                 }
174         return Mail::Address->new($phrase,'lace@jankratochvil.net') if !$lists{$rcpt->address()};
175         return Mail::Address->new(
176                         $phrase,
177                         'rcpt'
178                                         .'-'
179                                         .(defined($rcpt->user()) ? $rcpt->user() : "NOUSER")
180                                         .".AT."
181                                         .(defined($rcpt->host()) ? $rcpt->host() : "LOCAL")
182                                         .'@jankratochvil.net',
183                         );
184 }
185
186 # RedHat sendmail-8.9.3-20/src/conf.c/HdrInfo[]/\Q/* destination fields */\E
187 # FIXME: Recognize "Resent-$_" headers for -t but when we are in 'resent' mode?
188 our @h_rcpt=(   # case in-sensitive!
189                 "To",
190                 "Cc",
191                 "Bcc",
192                 "Apparently-To",
193                 );
194 # ordering matters; first header found is substituted
195 # last header is subsituted if no one is found
196 our @h_from=(
197                 "Resent-From",
198                 "From",
199                 );
200
201
202 # My-Audit
203
204 # Setup profile names.
205 # First element of /^=/ form copies it referenced profile to be extended.
206 # 'did'    =>did() subroutine will return true for it.
207 # 'syslog' =>Use syslog(3).
208 # 'bell'   =>Bell sound.
209 # 'sms=\d+'=>Send SMS by WWW::SMS with specified maximum # of parts
210 our %audit_profile=(
211                 "btw"   =>[],
212                 "silent"=>["=btw"   ,"did"],
213                 "log"   =>["=silent","syslog"],
214                 "bell"  =>["=log"   ,"bell"],
215                 "sms"   =>["=bell"  ,"sms=1"],
216                 "crit"  =>["=sms"   ,"sms=3"],
217                 );
218 # Try the squeezing methods in this order:
219 our @sms_squeezes=(
220                 { "SqueezeControl"=>"noconv"                         },
221                 { "SqueezeControl"=>"conv"  ,"SQZ_OPTIMIZE_LEVEL"=>0 },
222                 { "SqueezeControl"=>"conv"  ,"SQZ_OPTIMIZE_LEVEL"=>1 },
223                 { "SqueezeControl"=>"med"   ,"SQZ_OPTIMIZE_LEVEL"=>0 },
224                 { "SqueezeControl"=>"med"   ,"SQZ_OPTIMIZE_LEVEL"=>1 },
225                 { "SqueezeControl"=>"max"   ,"SQZ_OPTIMIZE_LEVEL"=>0 },
226                 { "SqueezeControl"=>"max"   ,"SQZ_OPTIMIZE_LEVEL"=>1 },
227                 );
228 # Hostnames where we had alternate e-mail addresses:
229 our @alternates_host=(
230                 "jabberwock.ucw.cz",    # short@ucw.cz
231                 "atrey.karlin.mff.cuni.cz",     # short@atrey.karlin.mff.cuni.cz
232                 "k332.feld.cvut.cz",    # short@k332.feld.cvut.cz
233                 );
234 # Override DNS blacklists:
235 our @dnsbl_whitelist=(
236                 "195.250.128.83",       # smtp3.vol.cz; vol.cz.multistage.blackholes.five-ten-sg.com.
237                 "64.49.222.22",         # mail.pm.org: rackspace.com.spam-support.blackholes.five-ten-sg.com.
238                 "208.147.243.5",        # gambit.liquidcomm.net: cw.net.spam-support.blackholes.five-ten-sg.com.
239                 "213.235.135.70",       # smtp.tiscali.cz: tiscali.cz.multistage.blackholes.five-ten-sg.com.
240                 "205.139.198.11",       # eniac.disaster.com: cw.net.spam-support.blackholes.five-ten-sg.com.
241                 "127.0.0.2",                    # 2.0.0.127.relays.ordb.org.
242                 "65.113.40.131",        # bozo.vmware.com: qwest.net.spam-support.blackholes.five-ten-sg.com.
243                 "66.218.85.33",         # mta2.wss.scd.yahoo.com: yahoo.com.spam.blackholes.five-ten-sg.com.
244                 "212.80.76.42",         # mx2.seznam.cz: seznam.cz.free.blackholes.five-ten-sg.com.
245                 "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.
246                 "212.80.76.44",         # mx1.seznam.cz: 44.76.80.212.blackholes.five-ten-sg.com.
247                 "212.80.76.29",         # prace.seznam.cz: 212.80.76.42.seznam.cz.free.blackholes.five-ten-sg.com
248                 "193.252.22.30",        # smtp1.wanadoo.fr: 30.22.252.193.blackholes.five-ten-sg.com
249                 "213.151.87.16",        # posta.dobnet.cz: 16.87.151.213.relays.ordb.org
250                 );
251
252 our $Audit;     # imported
253 our $procmailFROM_MAILER;       # imported
254 our $store_ignorenewmail;       # imported
255 our $store_profile;     # imported
256 our $store_ignore;      # imported
257 sub audit
258 {
259         $store_profile=undef();
260
261         # never spawn new mail if FROM_MAILER
262         # $isFROM_MAILER postponed after maillists as they may look as FROM_MAILER
263         #use re 'debug';
264         my $isFROM_MAILER=$Audit->header()=~/$procmailFROM_MAILER/mio;
265         $store_ignorenewmail=(0
266                         || $isFROM_MAILER
267                         || headerhas "From",'<Regexp:^owner->'
268                         );
269
270         # spam honeypots
271         return if did sub {
272                 local $_;
273                 # Do not local $store_file as it is our-imported
274                 $store_profile="silent";
275                 store "=spam"         if grep /^\Qshort\@k332.feld.cvut.cz\E/i,Received_for();
276                 # TODO: foreign violation of RFC 822 section 4.4.4, Subject:.*Automatick.+odpov.+v.+nep.+tomnosti
277                 store "=spam"         if headeris "From",'<ghandchi@hotmail.com>';
278                 store "=spam"         if headeris "From",'<newsletter@levnapc.cz>';
279                 store "=spam"         if headeris "From",'<Tomas@dtpstudio.cz>';
280                 store "=spam"         if headeris "From",'<BNcom@email.bn.com>';
281                 store "=spam"         if headeris "From",'<e4luck@lists.opt4email.com>';
282                 store "=spam"         if headeris "From",'<mailcontests@lists.servitall.com>';
283                 store "=spam"         if headeris "From",'<canda@lica.cz>';
284                 {
285                         # weak detection: files with text/html w/o text/plain are usually a spam
286                         my @types_linear=map({ mime_type($_); } parts_linear());
287                         store "=spam"       if grep({ $_ eq "text/html"; } @types_linear) && !grep({ $_ eq "text/plain"; } @types_linear);
288                         }
289                 store "=spam"         if ($_=mimehead(body_first())->mime_attr("Content-Type.charset")) && /^big5/i;
290                 };
291         $store_profile=undef();
292
293         # spam detection
294         return if did sub {
295                 # Do not local $store_file as it is our-imported
296                 $store_profile="silent";
297                 local $_;
298                 store "=spam".($_ eq 1 ? "" : ";$_")      if $_=spamassassin();
299                 };
300         $store_profile=undef();
301         return if did sub {
302                 # Do not local $store_file as it is our-imported
303                 $store_profile="silent";
304                 local $_;
305                 store "=spam"                      .";$_","log" if $_=dnsbl '.relays.ordb.org.' ,1;     # all hosts
306                 store "=spam"                      .";$_","log" if $_=dnsbl '.blackholes.mail-abuse.org.' ,1;   # all hosts
307                 # we don't check all hosts as they can be "dialup" category, FIXME: check for it
308 #               store "=spam"                      .";$_","log" if $_=dnsbl '.blackholes.five-ten-sg.com.',0; # just first
309                 # I don't send viruses but viruses propagate mails of mine
310                 store "=spam"                                   if headeris "X-Mailer",'ravmd/8.3.2';
311                 store "=spam"                                   if $isFROM_MAILER && headeris("To",'<short@ucw.cz>');
312                 };
313         $store_profile=undef();
314
315         # special delivery
316         store "=err","bell" and return if headerhas \&Received_for,'<short+err@>';
317
318         # ppl-wished foreign remapping, Reply-To is left untouched!
319         # FIXME: modifications are now being dropped by &write_message!
320         header_remap("From",{
321                         'kerere@post.cz'               =>'kamzik@k332.feld.cvut.cz',
322                         'profes@mbox.vol.cz'           =>'kratochvilova@egp.cz',
323                         'jkrouzek@mbox.vol.cz'         =>'krouzek@mbox.fsv.cuni.cz',
324                         'jakub.gorner@lidovky.cz'      =>'tonda@disnet.cz',
325                         'jan.kolar@videoprogress.cz'   =>'jenda.kolar@volny.cz',
326                         'daniel.rulicek@cponline.cz'   =>'daniel.rulicek@cpress.cz',
327                         'pavel@suse.cz'                =>'pavel@ucw.cz',
328                         });
329
330         # My obsolete e-mail addresses
331         store_muttrc_alternates "=redirect-","btw";
332
333         # nasty public lists with $store_ignore
334         {
335                 # Do not local $store_file as it is our-imported
336                 $store_profile="log";
337                 local $store_ignore;
338                 $store_ignore="smsmail"    if 1==$Audit->body() && length(join "",$Audit->body())<180;  # SMS mail
339                 $store_ignore="sms OS"     if $Audit->subject()=~/^Email pro: /;        # "^Email pro: gsm@sh\.cvut\.cz$";
340                 $store_ignore="list-moron" if grep { headeris "From",$_; } qw(
341                                 <kempny@>
342                                 <help.me@wo.cz>
343                                 <mr.death@mail.cz>
344                                 <danx3@centrum.cz>
345                                 <@mujoskar.cz>
346                                 <satko@quanto.nr.sanet.sk>
347                                 <vithous@attorney.cz> <viroman@attorney.cz>
348                                 <konf@klain.cz>
349                                 <stein@tiscali.cz>
350                                 <barevnej@volny.cz>
351                                 );
352
353                 store "=gsm"               if headeris  "Sender"   ,'<owner-gsm@sh.cvut.cz>';
354                 store "=gsmpand"           if headeris  "List-Post",'<gsm@pandora.cz>';
355                 store "=9kc","log"         if headeris  "List-Post",'<n9k@pandora.cz>';
356                 store "=9kcd","log"        if headeris  "List-Post",'<dev9k@pandora.cz>';
357                 }
358         $store_profile=undef();
359
360         # lists
361         store "=mozillabug","log"    if headeris "From"     ,'<bugzilla-daemon@mozilla.org>';
362         store "=9ku","log"           if headeris "List-Id"  ,'<9000.listman.net>';
363         store "=9kd","log"           if headeris "Sender"   ,'<owner-9000-developers@geekstuff.co.uk>';
364         store "=spong","log"         if headeris "List-Id"  ,'<spong-users.lists.sourceforge.net>';
365         store "=gtkd","silent"       if headeris "List-Id"  ,'<gtk-devel-list.gnome.org>';
366         store "=gnomevfs","log"      if headeris "List-Id"  ,'<gnome-vfs-list.gnome.org>';
367         store "=mffstatnice","bell"  if headeris "List-Post",'<statnice@atrey.karlin.mff.cuni.cz>';
368         store "=hw","log"            if headeris "List-Post",'<hw-news@list.gin.cz>';
369         store "=gnokii","log"        if headeris "List-Id"  ,'<gnokii-users.mail.freesoftware.fsf.org>';
370         store "=winelic","silent"    if headeris "List-Id"  ,'<wine-license.winehq.org>';
371         store "=wined","silent"      if headeris "List-Id"  ,'<wine-devel.winehq.org>';
372         store "=winepat","silent"    if headeris "List-Id"  ,'<wine-patches.winehq.org>';
373         store "=winecvs","silent"    if headeris "List-Id"  ,'<wine-cvs.winehq.org>';
374         store "=wineann","silent"    if headeris "List-Id"  ,'<wine-announce.winehq.org>';
375         store "=wineconf","silent"   if headeris "List-Id"  ,'<wineconf.winehq.org>';
376         store "=ros","silent"        if headeris "List-Id"  ,'<ros-general.reactos.com>';
377         store "=roskernel","silent"  if headeris "List-Id"  ,'<ros-kernel.reactos.com>';
378         store "=rosd","silent"       if headeris "List-Id"  ,'<ros-dev.reactos.com>';
379         store "=roscvs","silent"     if headeris "List-Id"  ,'<ros-cvs.reactos.com>';
380         store "=rosbug","silent"     if headeris "Reply-To" ,'<scarab@reactos.wox.org>';
381         store "=fsd","silent"        if headeris "X-Mailing-List",'<linux-fsdevel@vger.kernel.org>';
382         store "=kerneld","silent"    if headeris "X-Mailing-List",'<linux-kernel@vger.kernel.org>';
383         store "=surprise","sms"      if headeris "List-Post",'<surprise@atrey.karlin.mff.cuni.cz>';
384         store "=surprisesuse","sms"  if headeris "Sender"   ,'<owner-surprise@suse.cz>';
385         store "=tacacs","silent"     if headeris "Sender"   ,'<tacplus-l@disaster.com>';
386         store "=tacacs","silent"     if headeris "Sender"   ,'<owner-tacplus-l@disaster.com>';
387         store "=tacacs","silent"     if headeris "List-Id"  ,'<devel.lists.tacplus.org>';
388         store "=pm","log"            if headeris "Sender"   ,'<owner-prague-pm@pm.org>';
389         store "=radary","log"        if headeris "Reply-To" ,'<pha@radary.cz>';
390         store "=dnet","log"          if headeris "Sender"   ,'<@lists.distributed.net>';
391         store "=linux-input","log"   if headeris "List-Post",'<linux-input@atrey.karlin.mff.cuni.cz>';
392         store "=strom","bell"        if headeris "List-Post",'<vodni-strom@atrey.karlin.mff.cuni.cz>';
393         store "=netinfo","log"       if headeris "Sender"   ,'<owner-netinfo-l@vol.cz>';
394         store "=saintmj","log"       if headeris "From"     ,'<netsaint@kam-enterprise.ms.mff.cuni.cz>';
395         store "=saintmj","log"       if headeris "From"     ,'<netsaint@kam.mff.cuni.cz>';
396         store "=4cerr","bell"        if headeris "From"     ,'<owner-4cinfo@atrey.karlin.mff.cuni.cz>';
397         store "=4c","sms"            if headeris "List-Post",'<4cinfo@atrey.karlin.mff.cuni.cz>';
398         store "=slashdot","bell"     if headeris "From"     ,'<slashdot@slashdot.org>';
399         store "=freshmeat","bell"    if headeris "From"     ,'<noreply@freshmeat.net>';
400         store "=sourceforge","bell"  if headeris "From"     ,'<noreply@sourceforge.net>';
401         store "=gsmperlcvs","silent" if headeris("From"     ,'<johan@intra.tektonica.com>')
402                                         && $Audit->subject()=~/^'.*' has been updated!$/;
403         store "=libtoold","silent"   if headeris "List-Id"  ,'<libtool.gnu.org>';
404         store "=libtoolpat","silent" if headeris "List-Id"  ,'<libtool-patches.gnu.org>';
405         store "=automake","silent"   if headeris "List-Id"  ,'<automake.gnu.org>';
406         store "=autoconf","log"      if headeris "List-Id"  ,'<autoconf.gnu.org>';
407         store "=autoconfpat","log"   if headeris "List-Id"  ,'<autoconf-patches.gnu.org>';
408         my %mailman=(
409                         '<captive-admin@>'=>"=caperr",
410                         '<captive-devel-admin@>'=>"=caperr",
411                         '<captive-announce-admin@>'=>"=caperr",
412                         '<4c-admin@>'=>"=4cerr",
413                         );
414         if (!did sub {
415                         while ((my($mailaddr,$folder)=each(%mailman))) {
416                                 (my $maillistaddr=$mailaddr)=~s/-admin/-list$&/;
417                                 store $folder,"log" if (headeris("From",'<mailman-owner@vellum.cz>')&&headeris("To",$mailaddr))
418                                                 || headeris("From",$maillistaddr)
419                                                 || headeris("To",$maillistaddr)
420                                                 || headeris("From",$mailaddr);
421                                 }
422                         }) {
423                 store "=cap","bell"        if headeris "List-Id"  ,'<captive-list.jankratochvil.net>';
424                 store "=capd","bell"       if headeris "List-Id"  ,'<captive-devel-list.jankratochvil.net>';
425                 store "=capann","bell"     if headeris "List-Id"  ,'<captive-announce-list.jankratochvil.net>';
426                 store "=4c","bell"         if headeris "List-Id"  ,'<4c-list.vellum.cz>';
427                 }
428         store "=ntfsann","silent"    if headeris "List-Id"  ,'<linux-ntfs-announce.lists.sourceforge.net>';
429         store "=ntfsd","silent"      if headeris "List-Id"  ,'<linux-ntfs-dev.lists.sourceforge.net>';
430         store "=orbit","silent"      if headeris "List-Id"  ,'<orbit-list.gnome.org>';
431         store "=kand","log"          if headeris "List-Id"  ,'<devel.kannel.org>';
432         store "=mailmand","silent"   if headeris "List-Id"  ,'<mailman-developers.python.org>';
433         store "=asterisk-perl","log" if headeris "List-Post",'<asterisk-perl@lists.gnuinter.net>';
434         store "=i4l","silent"        if headeris "List-Id"  ,'<isdn4linux.listserv.isdn4linux.de>';
435         store "=glibc","silent"      if headeris "Mailing-List",qr/\b\Qlibc-alpha-help\E@\Qsources.redhat.com\E\b/;
436         store "=fedann","bell"       if headeris "List-Id"  ,'<fedora-announce-list.redhat.com>';
437         store "=fedtools","log"      if headeris "List-Id"  ,'<fedora-tools-list.redhat.com>';
438         # own webs
439         store "=energie","bell"      if headeris "From"     ,qr/^EnergieWeb/;
440         store "=ats","log"           if headeris("From"     ,'<root@ms.atspraha.cz>')
441                                         || (headeris("From",'<online@ringier.cz>') && headerhas("To",'<blesk@atspraha.cz>'));
442         store "=atscasablanca","log" if headeris "From"     ,'<casablanca@ms.atspraha.cz>';
443         store "=www-sms","log"       if headeris "List-Id"  ,'<www-sms-developers.lists.sourceforge.net>';
444         store "=httpdd","log"        if headeris "list-post",'<dev@httpd.apache.org>';
445         store "=mms2log","log"       if headeris "Return-Path",'<root@node0.mms2.org>';
446         store "=hotelgatelog","log"  if headeris "Return-Path",'<root@hotelgate.hotelnet>';
447
448         # Petr Koutecky does not mark his Stuff
449         store "=koutecky","log"      if headeris "Return-Path",'<velkyhroch@seznam.cz>';
450         store "=koutecky","log"      if headeris "Return-Path",'<pk.petr@centrum.cz>';
451         store "=koutecky","log"      if headeris "Return-Path",'<petr.koutecky@premisa.cz>';
452
453         store "=errm","bell"         if $isFROM_MAILER && !did();
454
455         if (!did) {
456                 store "==","sms";
457                 spamassassin "$HOME/bin/sa-learn --ham";
458                 }
459 }
460
461 sub audit_sms_address
462 {
463 my($obj)=@_;
464
465         my $address=$obj->address();
466         if (my $alternates=muttrc_get("alternates")) {
467                 return "I" if $address=~/$alternates/si;
468                 }
469         my %aliases=muttrc_aliases();
470         if (my $alias=$aliases{lc $address}) {
471                 local $_=$alias;
472                 s/\b(Bus)siness$/$1/i;
473                 s/\.ident$//i;
474                 return $_;
475                 }
476         local $_=$address;
477         s/\.cz$//i;
478         return $_;
479 }
480
481 # $args{"from"}
482 # $args{"subject"}
483 # $args{"body"}
484 sub audit_sms
485 {
486 my(%args)=@_;
487
488         my $from=(@{$args{"from"}} ? join(",",map({ audit_sms_address($_); } @{$args{"from"}})) : "?");
489         local $_;
490
491         $_=$args{"subject"};
492         # headers
493         s/(?:Re|Aw|Odp|Fw|Fwd|OT)(?:\[\d+\])?://ig;
494         # former subject
495         s/\bbylo:.*$//i;
496         s/\[\s*WAS:.*\]\s*$//i;
497         # trim
498         s/^\s*//s;
499         s/\s*$//s;
500         my $subject=$_;
501
502         $_=$args{"body"};
503         # max. 9 lines of .sig
504         s/\n-- (?:\n[^\n]*){0,9}$//gs;
505         # "Original Message"/"Puvodni zprava" etc. up to empty line
506         # "- - - Original message: - - -" is by "Lotus Notes Release 5.0.5  September 22, 2000"
507         s/(^|\n)[\s^\n]*(?:-----[\w\s]*-----|- - - Original message: - - -)[\s^\n]*(?:\n[^\n]+)*\n{2,}(?:\s*[^>\s].*$)?/\n/gs;
508         # Remove "..." lines (is it used by anyone except me?)
509         s/^\Q...\E$/*/gm;
510         # quoting "> "
511         s/^(?:\s*[[:upper:]]{0,3}>)+.*$/*/gm;
512         s/(?:^|\n)(?:\*\n+)+/\n*\n/gs;
513         # attributions
514         s/^.*\b(?:wrote|writes|napsal jste):\s*$//gm;
515         my $body=$_;
516
517         return [$from,"($subject)$body"];
518 }
519
520 1;