rh state
[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 @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 use Carp qw(confess cluck);
44
45
46 BEGIN {
47         for (qw(headerhas store headeris did dnsbl store_muttrc_alternates Received_for parts_linear mime_type
48                         body_first body_simple is_multipart mimehead mimebody spamassassin clamscan header_remap lmtp_deliver)) {
49                 eval 'sub '.$_.' { return ::'.$_.'(@_); }';
50                 }
51         }
52
53
54 # perlmail-accept & perlmail-sendmail
55
56 # Various configuration files location is derived from it:
57 our $HOME="/home/jkratoch";
58
59
60 # perlmail-accept
61
62 # Mail folder:
63 our $Mail="$HOME/Mail";
64 # Users respected for the 'idle' state (see $IdleMax):
65 our @ValidUsers=qw(root lace short kratochvil _local jkratoch);
66 # Maximum number of local console idle seconds while still considered as 'active user':
67 our $IdleMax=10;
68 # Maxium number of bytes to pass to Lingua::EN::Squeeze (performance optimization):
69 our $MaxBodySMS=0x1000;
70 # Telephone number to send SMSes by WWW::SMS to:
71 our @SMSwebRcpt=qw(420 602 431329);
72 # Some WWW::SMS modules require username:
73 our $SMSwebRcpt_username="lace2";
74 our $lmtp_admin="cyrus";
75 our $lmtp_pwd;
76 #{
77 #       local *F;
78 #       open F,"$HOME/priv/lmtp.${lmtp_admin}.pwd" or die;
79 #       $lmtp_pwd=<F>;
80 #       chomp $lmtp_pwd;
81 #       close F or die;
82 #       }
83 our $lmtp_user_from="lace";
84 our $lmtp_user_to="lacemail";
85 our $clamscan_waitpid_timeout=3;
86
87
88 # perlmail-submit
89
90 # Global system lock for exclusive $DB_table access:
91 our $Lock_pathname="/tmp/PerlMail.lock";
92 # 'workstation' hostname and port. Hostname may be dyndns:
93 our $PeerAddr="kashome.dyn.jankratochvil.net.:852";
94 #our $PeerAddr="127.0.0.1:2852";
95 # 15sec is NOT enough as the remote peer must complete mail store:
96 our $Socket_timeout=7600;
97 # MySQL table name:
98 our $DB_table="PerlMail_folder";
99 # MySQL database name:
100 our $DBI_database="short";
101 # MySQL user name:
102 our $DBI_user="short";
103 # MySQL user password:
104 our $DBI_pwd=$HOME."/priv/mysql.".$DBI_user.".pwd";
105
106
107 # Pathname of the original sendmail(8) binary:
108 our $sendmail_orig=(-x ($_="/usr/sbin/sendmail-orig") ? $_ : "/usr/sbin/sendmail");
109 # List of addresses to locally Bcc all mails to:
110 # Mail-Alias-1.12 defaults to "/etc/mail/aliases" which does not exist on RedHat sendmail-8.12.5-7
111 # Mail-Alias-1.12 will clutter $_ !
112 our @addr_addon=(Mail::Alias->new("/etc/aliases")->exists("sentout") ? ("sentout") : ());
113
114 our $opt_F;     # imported
115 our $is_pgp;    # imported
116 # Generate new From address for the target $rcpt of type Mail::Address.
117
118 # RedHat sendmail-8.9.3-20/src/conf.c/HdrInfo[]/\Q/* destination fields */\E
119 # FIXME: Recognize "Resent-$_" headers for -t but when we are in 'resent' mode?
120 our @h_rcpt=(   # case in-sensitive!
121                 "To",
122                 "Cc",
123                 "Bcc",
124                 "Apparently-To",
125                 );
126 # ordering matters; first header found is substituted
127 # last header is subsituted if no one is found
128 our @h_from=(
129                 "Resent-From",
130                 "From",
131                 );
132
133
134 # My-Audit
135
136 # Setup profile names.
137 # First element of /^=/ form copies it referenced profile to be extended.
138 # 'did'    =>did() subroutine will return true for it.
139 # 'syslog' =>Use syslog(3).
140 # 'bell'   =>Bell sound.
141 # 'sms=\d+'=>Send SMS by WWW::SMS with specified maximum # of parts
142 our %audit_profile=(
143                 "btw"   =>["syslog"],
144                 "silent"=>["=btw"   ,"did"],
145                 "log"   =>["=silent","syslog"],
146                 "bell"  =>["=log"   ,"bell"],
147                 "sms"   =>["=bell"  ,"sms=1"],
148                 "crit"  =>["=sms"   ,"sms=3"],
149                 );
150 # Try the squeezing methods in this order:
151 our @sms_squeezes=(
152                 { "SqueezeControl"=>"noconv"                         },
153                 { "SqueezeControl"=>"conv"  ,"SQZ_OPTIMIZE_LEVEL"=>0 },
154                 { "SqueezeControl"=>"conv"  ,"SQZ_OPTIMIZE_LEVEL"=>1 },
155                 { "SqueezeControl"=>"med"   ,"SQZ_OPTIMIZE_LEVEL"=>0 },
156                 { "SqueezeControl"=>"med"   ,"SQZ_OPTIMIZE_LEVEL"=>1 },
157                 { "SqueezeControl"=>"max"   ,"SQZ_OPTIMIZE_LEVEL"=>0 },
158                 { "SqueezeControl"=>"max"   ,"SQZ_OPTIMIZE_LEVEL"=>1 },
159                 );
160 # Hostnames where we had alternate e-mail addresses:
161 our @alternates_host=(
162                 "jabberwock.ucw.cz",    # short@ucw.cz
163                 "atrey.karlin.mff.cuni.cz",     # short@atrey.karlin.mff.cuni.cz
164                 "k332.feld.cvut.cz",    # short@k332.feld.cvut.cz
165                 );
166 # Override DNS blacklists:
167 our @dnsbl_whitelist=(
168                 "195.250.128.83",       # smtp3.vol.cz; vol.cz.multistage.blackholes.five-ten-sg.com.
169                 "64.49.222.22",         # mail.pm.org: rackspace.com.spam-support.blackholes.five-ten-sg.com.
170                 "208.147.243.5",        # gambit.liquidcomm.net: cw.net.spam-support.blackholes.five-ten-sg.com.
171                 "213.235.135.70",       # smtp.tiscali.cz: tiscali.cz.multistage.blackholes.five-ten-sg.com.
172                 "205.139.198.11",       # eniac.disaster.com: cw.net.spam-support.blackholes.five-ten-sg.com.
173                 "127.0.0.2",                    # 2.0.0.127.relays.ordb.org.
174                 "65.113.40.131",        # bozo.vmware.com: qwest.net.spam-support.blackholes.five-ten-sg.com.
175                 "66.218.85.33",         # mta2.wss.scd.yahoo.com: yahoo.com.spam.blackholes.five-ten-sg.com.
176                 "212.80.76.42",         # mx2.seznam.cz: seznam.cz.free.blackholes.five-ten-sg.com.
177                 "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.
178                 "212.80.76.44",         # mx1.seznam.cz: 44.76.80.212.blackholes.five-ten-sg.com.
179                 "212.80.76.29",         # prace.seznam.cz: 212.80.76.42.seznam.cz.free.blackholes.five-ten-sg.com
180                 "193.252.22.30",        # smtp1.wanadoo.fr: 30.22.252.193.blackholes.five-ten-sg.com
181                 "213.151.87.16",        # posta.dobnet.cz: 16.87.151.213.relays.ordb.org
182                 "70.71.0.212",          # Red Hat
183                 );
184
185 our $Audit;     # imported
186 our $procmailFROM_MAILER;       # imported
187 our $store_ignorenewmail;       # imported
188 our $store_profile;     # imported
189 our $store_ignore;      # imported
190 sub audit
191 {
192         $store_profile=undef();
193
194         # never spawn new mail if FROM_MAILER
195         # $isFROM_MAILER postponed after maillists as they may look as FROM_MAILER
196         #use re 'debug';
197         my $isFROM_MAILER=$Audit->header()=~/$procmailFROM_MAILER/mio;
198         $store_ignorenewmail=(0
199                         || $isFROM_MAILER
200                         || headerhas "From",'<Regexp:^owner->'
201                         );
202
203         # spam honeypots
204         return if did sub {
205                 local $_;
206                 # Do not local $store_file as it is our-imported
207                 $store_profile="silent";
208                 store "=spam"         if grep /^\Qshort\@k332.feld.cvut.cz\E/i,Received_for();
209                 # TODO: foreign violation of RFC 822 section 4.4.4, Subject:.*Automatick.+odpov.+v.+nep.+tomnosti
210                 store "=spam"         if headeris "From",'<ghandchi@hotmail.com>';
211                 store "=spam"         if headeris "From",'<newsletter@levnapc.cz>';
212                 store "=spam"         if headeris "From",'<Tomas@dtpstudio.cz>';
213                 store "=spam"         if headeris "From",'<BNcom@email.bn.com>';
214                 store "=spam"         if headeris "From",'<e4luck@lists.opt4email.com>';
215                 store "=spam"         if headeris "From",'<mailcontests@lists.servitall.com>';
216                 store "=spam"         if headeris "From",'<canda@lica.cz>';
217                 store "=spam"         if headeris "From",'<newsletter@thecareernews.com>';
218                 store "=spam"         if headeris "From",'<newsletter@jobseekerweekly.com>';
219                 store "=spam"         if headeris "From",'<newsletter@jobmarketweekly.com>';
220                 store "=spam"         if headeris "From",'<newsletter@career-digest.com>';
221                 for my $header (qw(To Cc)) {
222                         store "=spam" if headerhas $header,'<st@jankratochvil.net>';
223                         store "=spam" if headerhas $header,'<est@jankratochvil.net>';
224                         store "=spam" if headerhas $header,'<uest@jankratochvil.net>';
225                         store "=spam" if headerhas $header,'<kratochvil.net@jankratochvil.net>';
226                         }
227                 {
228                         # weak detection: files with text/html w/o text/plain are usually a spam
229                         my @types_linear=map({ mime_type($_); } parts_linear());
230                         store "=spamhtml" if grep({ $_ eq "text/html"; } @types_linear) && !grep({ $_ eq "text/plain"; } @types_linear);
231                         }
232 ###             store "=spambig5" if ($_=mimehead(body_first())->mime_attr("Content-Type.charset")) && /^big5/i;
233                 };
234         $store_profile=undef();
235
236         my $nonrh;
237         for ($Audit->get("Received")) {
238                 $nonrh=1 if /\sby\s+mx\d+\Q.redhat.com\E\s/s;
239         }
240         $nonrh=1 if !headeris("From",qr/[@]redhat.com/i);
241         # spam detection
242         return if did sub {
243                 # Internal RH mails are never spam.
244                 return if !$nonrh;
245                 # It is too expensive to scan the huge =caperr announcements by spamassassin(1).
246                 return if headeris("From",qr/^captive-[a-z]*@/);
247                 # Do not local $store_file as it is our-imported
248                 $store_profile="log";
249                 local $_;
250 ###             store "=spam".";virus=$_"            if $_=clamscan();
251                 store "=spam".";spamassassin".($_ eq 1 ? "" : "=$_") if $_=spamassassin();
252 # Down?
253 ###             store "=spam".";$_"                  if $_=dnsbl '.relays.ordb.org.' ,1;        # all hosts
254 if (0) {
255                 store "=spam".";$_"                  if $_=dnsbl '.blackholes.mail-abuse.org.' ,1;      # all hosts
256                 # we don't check all hosts as they can be "dialup" category, FIXME: check for it
257 #               store "=spam".";$_"                  if $_=dnsbl '.blackholes.five-ten-sg.com.',0; # just first
258                 # I don't send viruses but viruses propagate mails of mine
259 }
260                 store "=spam".";ravmd"               if headeris "X-Mailer",'ravmd/8.3.2';
261                 store "=spam".';short@ucw.cz+MAILER' if $isFROM_MAILER && headeris("To",'<short@ucw.cz>');
262                 if (!is_multipart()) {
263                         local $_=mimebody(body_first());
264                         my %sites=map(($_=>1),qw(
265                                         brandenburg.rz.fhtw-berlin.de
266                                         forum.gofeminin.de
267                                         service.spiegel.de
268                                         www.aufenthaltstitel.de
269                                         www.berlinonline.de
270                                         www.deutschlandchronik.de
271                                         www.heise.de
272                                         www.leverkusener-aufbruch.com
273                                         www.libasoli.de
274                                         www.mjoelnirsseite.de
275                                         www.npd-nrw.net
276                                         www.npd.de
277                                         www.rp-online.de
278                                         www.spiegel.de
279                                         www.taz.de
280                                         www.unserforum.com
281                                         www.zdf.de
282                                         ));
283                         my $found;
284                         while (m{http://([^/]+)/}g) {
285                                 do { $found=1; next; } if $sites{$1};
286                                 $found=0;
287                                 last;
288                                 }
289                         $found=1 if /^\s*Lese selbst:\n/s;
290                         store "=spam".';german-news' if $found;
291                         }
292                 };
293         $store_profile=undef();
294
295         # special delivery
296         store "=err","bell" and return if headerhas \&Received_for,'<short+err@>';
297         store "=host1","bell" and return if headerhas \&Received_for,qr/\Qjan.kratochvil+\E\S*\Q.at.host1.dyn.jankratochvil.net\E@/;
298
299 #       if (headeris "X-Calendar-Attachment",qr/./) {
300 #               store "=zimbra","btw";
301 #               my $headless=$::Message;
302 #               $headless=~s{^From .*?\n}{} or cluck "No From header for Zimbra";
303 #               local *CHILD;
304 #               if (!$::Dry) {
305 #                       open CHILD,q{|sendmail jkratoch@calendar.corp.redhat.com}
306 #                                       or cluck "Cannot forward to Zimbra";
307 #                       print CHILD $headless or cluck;
308 #                       close CHILD or cluck;
309 #               }
310 #       }
311
312         # lists
313         store "=mozillabug","log"    if headeris "From"     ,'<bugzilla-daemon@mozilla.org>';
314         store "=9ku","log"           if headeris "List-Id"  ,'<9000.listman.net>';
315         store "=9kd","log"           if headeris "Sender"   ,'<owner-9000-developers@geekstuff.co.uk>';
316         store "=spong","log"         if headeris "List-Id"  ,'<spong-users.lists.sourceforge.net>';
317         store "=gtkd","silent"       if headeris "List-Id"  ,'<gtk-devel-list.gnome.org>';
318         store "=gnomevfs","log"      if headeris "List-Id"  ,'<gnome-vfs-list.gnome.org>';
319         store "=hw","log"            if headeris "List-Post",'<hw-news@list.gin.cz>';
320         store "=gnokii","log"        if headeris "List-Id"  ,'<gnokii-users.mail.freesoftware.fsf.org>';
321         store "=winelic","silent"    if headeris "List-Id"  ,'<wine-license.winehq.org>';
322         store "=wined","silent"      if headeris "List-Id"  ,'<wine-devel.winehq.org>';
323         store "=winepat","silent"    if headeris "List-Id"  ,'<wine-patches.winehq.org>';
324         store "=winecvs","silent"    if headeris "List-Id"  ,'<wine-cvs.winehq.org>';
325         store "=wineann","silent"    if headeris "List-Id"  ,'<wine-announce.winehq.org>';
326         store "=wineconf","silent"   if headeris "List-Id"  ,'<wineconf.winehq.org>';
327         store "=ros","silent"        if headeris "List-Id"  ,'<ros-general.reactos.com>';
328         store "=roskernel","silent"  if headeris "List-Id"  ,'<ros-kernel.reactos.com>';
329         store "=rosd","silent"       if headeris "List-Id"  ,'<ros-dev.reactos.com>';
330         store "=roscvs","silent"     if headeris "List-Id"  ,'<ros-cvs.reactos.com>';
331         store "=rossvn","silent"     if headeris "List-Id"  ,'<ros-svn.reactos.com>';
332         store "=rosbug","silent"     if headeris "Reply-To" ,'<scarab@reactos.wox.org>';
333         store "=fsd","silent"        if headeris "X-Mailing-List",'<linux-fsdevel@vger.kernel.org>';
334         store "=kernel","silent"     if headeris "X-Mailing-List",'<linux-kernel@vger.kernel.org>';
335         store "=kernelnet","silent"  if headeris "X-Mailing-List",'<linux-net@vger.kernel.org>';
336         store "=ia64","silent"       if headeris "X-Mailing-List",'<linux-ia64@vger.kernel.org>';
337         store "=linuxjap","silent"   if headeris "X-Mailing-List",'<linux-japanese@vger.kernel.org>';
338         store "=kernelann","silent"  if headeris "X-Mailing-List",'<linux-kernel-announce@vger.kernel.org>';
339         store "=sparse","silent"     if headeris "X-Mailing-List",'<linux-sparse@vger.kernel.org>';
340         store "=smp","silent"        if headeris "X-Mailing-List",'<linux-smp@vger.kernel.org>';
341         store "=tacacs","silent"     if headeris "Sender"   ,'<tacplus-l@disaster.com>';
342         store "=tacacs","silent"     if headeris "Sender"   ,'<owner-tacplus-l@disaster.com>';
343         store "=tacacs","silent"     if headeris "List-Id"  ,'<devel.lists.tacplus.org>';
344         store "=pm","log"            if headeris "List-Id"  ,'<prague-pm.pm.org>';
345         store "=radary","log"        if headeris "Reply-To" ,'<pha@radary.cz>';
346         store "=dnet","log"          if headeris "Sender"   ,'<@lists.distributed.net>';
347         store "=netinfo","log"       if headeris "Sender"   ,'<owner-netinfo-l@vol.cz>';
348         store "=slashdot","bell"     if headeris "From"     ,'<slashdot@slashdot.org>';
349         store "=freshmeat","bell"    if headeris "From"     ,'<noreply@freshmeat.net>';
350         store "=sourceforge","bell"  if headeris "From"     ,'<noreply@sourceforge.net>';
351         store "=gsmperlcvs","silent" if headeris("From"     ,'<johan@intra.tektonica.com>')
352                                         && $Audit->subject()=~/^'.*' has been updated!$/;
353         store "=libtoold","silent"   if headeris "List-Id"  ,'<libtool.gnu.org>';
354         store "=libtoolpat","silent" if headeris "List-Id"  ,'<libtool-patches.gnu.org>';
355         store "=automake","silent"   if headeris "List-Id"  ,'<automake.gnu.org>';
356         store "=autoconf","log"      if headeris "List-Id"  ,'<autoconf.gnu.org>';
357         store "=autoconfpat","log"   if headeris "List-Id"  ,'<autoconf-patches.gnu.org>';
358         store "=hurd","log"          if headeris "List-Id"  ,'<l4-hurd.gnu.org>';
359         store "=gccbug","silent"     if headeris "List-Post",'<gcc-bugs@gcc.gnu.org>';
360         store "=gccann","log"        if headeris "List-Post",'<gcc-announce@gcc.gnu.org>';
361         store "=gcc","silent"        if headeris "List-Post",'<gcc@gcc.gnu.org>';
362         store "=gccpat","silent"     if headeris "List-Post",'<gcc-patches@gcc.gnu.org>';
363         store "=ntfsann","silent"    if headeris "List-Id"  ,'<linux-ntfs-announce.lists.sourceforge.net>';
364         store "=ntfsd","silent"      if headeris "List-Id"  ,'<linux-ntfs-dev.lists.sourceforge.net>';
365         store "=orbit","silent"      if headeris "List-Id"  ,'<orbit-list.gnome.org>';
366         store "=kannel","log"        if headeris "List-Id"  ,'<users.kannel.org>';
367         store "=kanneld","log"       if headeris "List-Id"  ,'<devel.kannel.org>';
368         store "=mailmand","silent"   if headeris "List-Id"  ,'<mailman-developers.python.org>';
369         store "=asterisk-perl","log" if headeris "List-Post",'<asterisk-perl@lists.gnuinter.net>';
370         store "=i4l","silent"        if headeris "List-Id"  ,'<isdn4linux.listserv.isdn4linux.de>';
371         store "=glibc","silent"      if headeris "List-Post",'<libc-alpha@sourceware.org>';
372         store "=fedann","bell"       if headeris("List-Id"  ,'<announce.lists.fedoraproject.org>')
373                                      || headeris("List-Id"  ,'<fedora-announce-list.redhat.com>');
374         store "=fedpkg","bell"       if headeris "List-Id"  ,'<fedora-package-announce.redhat.com>';
375         store "=federrata","log"     if headeris "Return-Path",'<root@app5.fedora.phx.redhat.com>';
376         store "=fedtools","log"      if headeris "List-Id"  ,'<fedora-tools-list.post-office.corp.redhat.com>';
377         store "=freleng","log"       if headeris "List-Id"  ,'<rel-eng.lists.fedoraproject.org>';
378         if (headeris("List-Id"  ,'<fedora-devel-list.redhat.com>')
379          || headeris("List-Id"  ,'<devel.lists.fedoraproject.org>')) {
380           store "=fedd","log";
381           store "=feddgdb","log"       if body_simple()=~/\bgdb\b/i;
382           store "=feddlibunwind","log" if body_simple()=~/libunwind/i;
383         }
384         store "=bashbug","log"       if headeris "List-Id"  ,'<bug-bash.gnu.org>';
385         store "=zaurus","silent"     if headeris "List-Id"  ,'<openzaurus-users.lists.sourceforge.net>';
386         store "=zaurusann","log"     if headeris "List-Id"  ,'<openzaurus-announce.lists.sourceforge.net>';
387         store "=zaurusd","silent"    if headeris "List-Id"  ,'<openzaurus-devel.lists.sourceforge.net>';
388         store "=zaurussoft","silent" if headeris "List-Id"  ,'<openzaurus-software.lists.sourceforge.net>';
389         store "=iptperl","silent"    if headeris "List-Id"  ,'<iptperl-general.lists.sourceforge.net>';
390         store "=www-sms","log"       if headeris "List-Id"  ,'<www-sms-developers.lists.sourceforge.net>';
391         store "=httpdd","log"        if headeris "list-post",'<dev@httpd.apache.org>';
392         store "=imja","log"          if headeris "List-Id"  ,'<im-ja-devel.lists.sourceforge.net>';
393         store "=wince","log"         if headeris "List-Post",'<wince@pandora.cz>';
394         store "=mysqlperl","log"     if headeris "List-Id"  ,'<perl.mysql.com>';
395         store "=whiteann","log"      if headeris "List-Id"  ,'<whitebox-announce.beau.org>';
396         store "=white","log"         if headeris "List-Id"  ,'<whitebox-users.beau.org>';
397         store "=centos","log"        if headeris "List-Id"  ,'<centos.centos.org>';
398         store "=centann","log"       if headeris "List-Id"  ,'<centos-announce.centos.org>';
399         store "=modperldoc","log"    if headeris "List-Id"  ,'<docs-dev.perl.apache.org>';
400         store "=qemud","log"         if headeris "List-Id"  ,'<qemu-devel.nongnu.org>';
401         store "=diamond","log"       if headeris "X-Replicator-Inst",'"www.diamondcard.us"';
402         store "=soap","log"          if headeris "Sender"   ,'<owner-soap@DISCUSS.DEVELOP.COM>';
403         store "=nagiosd","log"       if headeris "List-Id"  ,'<nagios-devel.lists.sourceforge.net>';
404         store "=nagios","log"        if headeris "List-Id"  ,'<nagios-users.lists.sourceforge.net>';
405         store "=grub","log"          if headeris "List-Id"  ,'<grub-devel.gnu.org>';
406         store "=gdb","log"           if headeris "Mailing-List",'contact gdb-help@sourceware.org; run by ezmlm';
407         store "=gdbia64","log"       if headeris("Mailing-List",'contact gdb-help@sourceware.org; run by ezmlm')
408                                      && body_simple()=~/\b(?:ia64|itanium)\b/i;
409         store "=gdbpr","log"         if headeris "Mailing-List",'contact gdb-prs-help@sourceware.org; run by ezmlm';
410         store "=gdbpria64","log"     if headeris("Mailing-List",'contact gdb-prs-help@sourceware.org; run by ezmlm')
411                                      && body_simple()=~/\b(?:ia64|itanium)\b/i;
412         store "=gdbpat","log"        if headeris "Mailing-List",'contact gdb-patches-help@sourceware.org; run by ezmlm';
413         store "=gdbpatia64","log"    if headeris("Mailing-List",'contact gdb-patches-help@sourceware.org; run by ezmlm')
414                                      && body_simple()=~/\b(?:ia64|itanium)\b/i;
415         store "=gdbann","log"        if headeris "Mailing-List",'contact gdb-announce-help@sourceware.org; run by ezmlm';
416         store "=gdbcvs","log"        if headeris "Mailing-List",'contact gdb-cvs-help@sourceware.org; run by ezmlm';
417         store "=gdbcvsall","log"     if headeris "Mailing-List",'contact src-cvs-help@sourceware.org; run by ezmlm';
418         store "=binutils","log"      if headeris "Mailing-List",'contact binutils-help@sourceware.org; run by ezmlm';
419         store "=binutilsbug","log"   if headeris "List-Id"  ,'<bug-binutils.gnu.org>';
420         store "=buggnome","log"      if headeris "From"     ,'<bugzilla@gnome.org>';
421         store "=bugdesktop","log"    if headeris "From"     ,'<bugzilla-daemon@freedesktop.org>';
422
423         # Red Hat
424         store "=wslog","log"         if headeris("From"     ,'<logwatch@jankratochvil.net>')
425                                      && headeris("Return-Path",'<root@lace.redhat.com>');
426         store "=rhos","log"          if headeris "List-Id"  ,'<os-dept-list.redhat.com>';
427         store "=rhosd","log"         if headeris "List-Id"  ,'<os-devel-list.redhat.com>';
428         store "=rhmemo","silent"     if headeris "List-Id"  ,'<memo-list.redhat.com>';
429         store "=rhann","log"         if headeris "List-Id"  ,'<announce-list.redhat.com>';
430         store "=rheng","log"         if headeris "List-Id"  ,'<eng-list.redhat.com>';
431         store "=rheurope","log"      if headeris("List-Id"  ,'<brno-list.redhat.com>')
432                                      && headeris("X-loop"   ,'<europe-list@redhat.com>');
433         store "=rhbrno","log"        if headeris("List-Id"  ,'<brno-list.redhat.com>')
434                                      &&!headeris("X-loop"   ,'<europe-list@redhat.com>');
435         store "=rhbrnomemo","log"    if headeris "List-Id"  ,'<brno-memo-list.redhat.com>';
436         store "=rhbrnopto","log"     if headeris "List-Id"  ,'<brno-pto-list.redhat.com>';
437         store "=rhbase","log"        if headeris "List-Id"  ,'<base-os-dept-list.redhat.com>';
438         if (!did sub {
439         store "=rhrhel","log"        if headeris "X-BeenThere",'<rhel-product-org@post-office.corp.redhat.com>';
440         store "=rhrhel","log"        if headeris "X-BeenThere",'<prod-dept@post-office.corp.redhat.com>';
441         store "=rheng","log"         if headeris "X-BeenThere",'<eng-dept@post-office.corp.redhat.com>';
442         }) {
443         store "=rhtoolsteam","log"   if headeris "List-Id"  ,'<tools-team.redhat.com>';
444         }
445         store "=rhtools","log"       if headeris "List-Id"  ,'<tools.redhat.com>';
446         store "=rhosteam","log"      if headeris "List-Id"  ,'<tools-dept-list.redhat.com>';
447         store "=rhbug","log"         if headeris "X-BeenThere",'<bugzilla@redhat.com>';
448         store "=rhgdb","log"         if headeris "List-Id"  ,'<tools-gdb.post-office.corp.redhat.com>';
449         store "=rhit","log"          if headeris "Return-Path",'<tao@redhat.com>';
450         store "=rhcommit","log"      if headeris("List-Id"  ,'<cvs-commits-list.redhat.com>')
451                                      || headeris("X-CVS-Server",'<cvs-int.fedora.redhat.com>');
452         store "=rhcommitgdb","log"   if headeris "X-CVS-Directory",qr{^rpms/gdb(?:/.*)?$};
453         store "=rhcommitgcc","log"   if headeris "X-CVS-Directory",qr{^rpms/gcc(?:/.*)?$};
454         store "=rhcommitlibunwind","log" if headeris "X-CVS-Directory",qr{^rpms/libunwind(?:/.*)?$};
455         store "=rhcommitstrace","log" if headeris "X-CVS-Directory",qr{^rpms/strace(?:/.*)?$};
456         store "=rhcommitbinutils","log" if headeris "X-CVS-Directory",qr{^rpms/binutils(?:/.*)?$};
457         store "=rhcommitinsight","log" if headeris "X-CVS-Directory",qr{^rpms/insight(?:/.*)?$};
458         store "=rhcommitptrace","log" if headeris "X-CVS-Directory",qr{^tests/kernel/syscalls/ptrace(?:/.*)? };
459         store "=rhcommitgdbtest","log" if headeris "X-CVS-Directory",qr{^tests/gdb/gdb-any(?:/.*)? };
460         store "=rhbrnowiki","log"    if headeris("Return-Path",'<noreply@redhat.com>')
461                                      && headeris("From"     ,'<noreply@redhat.com>')
462                                      && headeris("To"       ,'<noreply@redhat.com>')
463                                      # `\Q=?' causes: Can't modify constant item in concatenation (.) or string
464                                      && headeris("Subject"  ,qr{^(?:\Q[Red Hat Czech] \E(?:Trivial )?Update of |=\Q?utf-8?q?=5BRed_Hat_Czech=5D_\E(?:Trivial_)?Update_of_)});
465         store "=rhts","log"          if headeris "List-Id"  ,'<test-auto.redhat.com>';
466         store "=rhts","log"          if headeris("List-Id"  ,'<rhts-dev-list.post-office.corp.redhat.com>')
467                                      || headeris("List-Id"  ,'<beaker-dev-list.post-office.corp.redhat.com>');
468         store "=rhwiki","log"        if headeris "Return-Path",'<interch@redhat.com>';
469         store "=rhinet","log"        if headeris "List-id"  ,'<intranet-taskforce.redhat.com>';
470         if (headeris "Return-Path",'<test-auto@redhat.com>') {
471                 if (body_simple()=~/(?:jkratoch|jan.kratochvil)[@]\Qredhat.com\E/s) {
472                         store "=rhtsme","log";
473                         }
474                 else {
475                         store "=rhtsbogus","log";
476                         }
477                 }
478         store "=rherrata","log"      if $Audit->get("X-Erratatool-Component")
479                                      || (headeris("Return-Path",'<bugzilla@redhat.com>')
480                                       && headeris("Subject",qr{^Changed Errata Request }));
481         if (headeris "Subject"  ,qr{^\Q[rpmdiff] INSPECTION: Erratum \E\d{4}:\d{4} .*\btest results\b}) {
482                 store "=rherrata","log";
483         # `[rpmdiff] INSPECTION:' came from `root@rpmdiff3.test.redhat.com'.
484         } elsif ((headeris("To",'<jan.kratochvil@redhat.com>') || !$Audit->get("To") || $Audit->get("To") eq "undisclosed-recipients:;")
485                  && headeris("Return-Path",qr{^\Qroot@\E.*[.](?:(?:lab|rhts|eng).(?:bos|boston)|z900|test|englab.brq|nay)\Q.redhat.com\E$})) {
486                 store "=rhtsme","log";
487         }
488         store "=rhtsme"              if headeris "Subject"  ,qr{^\Q[Beaker Job Completion] \E};
489         store "=buggcc","log"        if headeris("Return-Path",'<bugzilla-noreply@gcc.gnu.org>')
490                                      || headeris("Return-Path",'<gcc-bugzilla@gcc.gnu.org>');
491         store "=frysk","log"         if headeris "Mailing-List",'contact frysk-help@sourceware.org; run by ezmlm';
492         store "=fryskcvs","log"      if headeris "List-Id"  ,'<frysk-cvs.sourceware.org>';
493         store "=bugsrc","log"        if headeris "Return-Path",'<bugzilla-noreply@sourceware.org>';
494         store "=rhwc","log"          if headeris "Subject"  ,'Cron <jkratoch@host0> $HOME/redhat/bin/rhwc';
495         store "=dwarf","log"         if headeris "List-Id"  ,'<dwarf-discuss.lists.freestandards.org>';
496         store "=dwarf","log"         if headeris "List-Id"  ,'<dwarf-discuss-dwarfstd.org>';
497         store "=libunwind","log"     if headeris "List-Id"  ,'<libunwind.linux.hpl.hp.com>';
498         store "=libunwindd","log"    if headeris "List-Id"  ,'<libunwind-devel.nongnu.org>';
499         store "=rhsip","log"         if headeris "List-Id"  ,'<sip-test.redhat.com>';
500         store "=fedaccount","log"    if headeris("Return-Path",'<root@redhat.com>')
501                                      && headeris("To",      '<jkratoch@redhat.com>')
502                                      && headeris("From",    '<accounts@fedora.redhat.com>')
503                                      && headeris("Subject"  ,'You need to create a bugzilla account for jkratoch@redhat.com');
504         store "=straced","log"       if headeris "List-Id"  ,'<strace-devel.lists.sourceforge.net>';
505         if (headeris "Return-Path",'<buildsys@fedoraproject.org>') {
506                 if ($Audit->subject()=~/^\d+ builds? marked for deletion$/) {
507                         store "=fkojidel","log";
508                 } else {
509                         store "=fkoji","log";
510                 }
511         }
512         if (headeris "Return-Path",'<buildsys@redhat.com>') {
513                 if ($Audit->subject()=~/^\d+ builds? marked for deletion$/) {
514                         store "=rhbrewdel","log";
515                 } else {
516                         store "=rhbrew","log";
517                 }
518         }
519         store "=utrace","log"        if headeris "List-Id"  ,'<utrace-devel.redhat.com>';
520         store "=eud","log"           if headeris "List-Id"  ,'<elfutils-devel.post-office.corp.redhat.com>';
521         store "=eud","log"           if headeris "List-Id"  ,'<elfutils-devel.lists.fedorahosted.org>';
522         store "=dup","log"           if headeris "List-Id"  ,'<duplicity-talk.nongnu.org>';
523         store "=dupbug","log"        if headeris "List-Id"  ,'<duplicity-tracker.nongnu.org>';
524         store "=rheclipse","log"     if headeris "List-Id"  ,'<eclipse-list.redhat.com>';
525         store "=rhtech","log"        if headeris "List-Id"  ,'<tech-list.redhat.com>';
526         store "=rhgdb","log"         if headeris "List-Id"  ,'<gdb-local.redhat.com>';
527         store "=rhperf","log"        if headeris "List-Id"  ,'<perftools-list.redhat.com>';
528         store "=rhdebug","log"       if headeris "List-Id"  ,'<debug-list.redhat.com>';
529         store "=rhsip","log"         if headeris "List-Id"  ,'<sip-users.redhat.com>';
530         store "=fupdate","log"       if headeris "Return-Path",'<updates@fedoraproject.org>';
531         store "=rhmedia","log"       if headerhas "List-Id",'<media-monitor.redhat.com>';
532         store "=fia64","log"         if headeris "List-Id"  ,'<fedora-ia64-list.redhat.com>';
533         store "=archer","log"        if headeris "List-Id"  ,'<archer.sourceware.org>';
534         store "=archergit","log"     if headeris "List-Post"  ,'<archer-commits@sourceware.org>';
535         store "=flive","log"         if headeris("List-Id"  ,'<livecd.lists.fedoraproject.org>')
536                                      || headeris("List-Id"  ,'<fedora-livecd-list.redhat.com>');
537         store "=fspin","log"         if headeris "List-Id"  ,'<spins.lists.fedoraproject.org>';
538         store "=rhstatus","log"      if headeris "List-Id"  ,'<rhel-people-status.post-office.corp.redhat.com>';
539         store "=rhstatusteam","log"  if headeris "List-Id"  ,'<rhel-team-status-list.post-office.corp.redhat.com>';
540         store "=fcrash","log"        if headeris "List-Id"  ,'<crash-catcher.lists.fedorahosted.org>';
541         store "=gabi","log"          if headeris "List-Id"  ,'<generic-abi.googlegroups.com>';
542         store "=fupload","log"       if headeris("X-Fedora-Upload",qr//)
543                                      && headeris("Subject"  ,qr/^File\s\S+\suploaded\sto\slookaside\scache\sby\s/);
544         store "=rhpkg","log"         if headeris "Return-Path",'<pkwrangler-list@redhat.com>';
545         store "=gdbmail","log"       if headeris "From"     ,qr{^\Qdiffgdbdaymail by Jan Kratochvil <jan.kratochvil\E@\Qredhat.com>\E$};
546         store "=vpx","log"           if headeris("List-Id"  ,'<codec-devel.webmproject.org>')
547                                      || headeris("List-Id"  ,'<gerrit-libvpx.review.webmproject.org>');
548
549
550         if (($isFROM_MAILER && !did) || !did) {
551 #               lmtp_deliver $lmtp_admin,$lmtp_pwd,$lmtp_user_from,$lmtp_user_to;
552                 }
553
554 #       store "=errm","bell"         if $isFROM_MAILER && !did();
555
556         if (!did) {
557                 store "==","sms";
558                 spamassassin "sa-learn --ham";
559                 }
560 }
561
562 sub audit_sms_address
563 {
564 my($obj)=@_;
565
566         my $address=$obj->address();
567         if (my $alternates=muttrc_get("alternates")) {
568                 return "I" if $address=~/$alternates/si;
569                 }
570         my %aliases=muttrc_aliases();
571         if (my $alias=$aliases{lc $address}) {
572                 local $_=$alias;
573                 s/\b(Bus)siness$/$1/i;
574                 s/\.ident$//i;
575                 return $_;
576                 }
577         local $_=$address;
578         s/\.cz$//i;
579         return $_;
580 }
581
582 # $args{"from"}
583 # $args{"subject"}
584 # $args{"body"}
585 sub audit_sms
586 {
587 my(%args)=@_;
588
589         my $from=(@{$args{"from"}} ? join(",",map({ audit_sms_address($_); } @{$args{"from"}})) : "?");
590         local $_;
591
592         $_=$args{"subject"};
593         # headers
594         s/(?:Re|Aw|Odp|Fw|Fwd|OT)(?:\[\d+\])?://ig;
595         # former subject
596         s/\bbylo:.*$//i;
597         s/\[\s*WAS:.*\]\s*$//i;
598         # trim
599         s/^\s*//s;
600         s/\s*$//s;
601         my $subject=$_;
602
603         $_=$args{"body"};
604         # max. 9 lines of .sig
605         s/\n-- (?:\n[^\n]*){0,9}$//gs;
606         # "Original Message"/"Puvodni zprava" etc. up to empty line
607         # "- - - Original message: - - -" is by "Lotus Notes Release 5.0.5  September 22, 2000"
608         s/(^|\n)[\s^\n]*(?:-----[\w\s]*-----|- - - Original message: - - -)[\s^\n]*(?:\n[^\n]+)*\n{2,}(?:\s*[^>\s].*$)?/\n/gs;
609         # Remove "..." lines (is it used by anyone except me?)
610         s/^\Q...\E$/*/gm;
611         # quoting "> "
612         s/^(?:\s*[[:upper:]]{0,3}>)+.*$/*/gm;
613         s/(?:^|\n)(?:\*\n+)+/\n*\n/gs;
614         # attributions
615         s/^.*\b(?:wrote|writes|napsal jste):\s*$//gm;
616         my $body=$_;
617
618         return [$from,"($subject)$body"];
619 }
620
621 1;