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