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