X-Git-Url: http://git.jankratochvil.net/?p=PerlMail.git;a=blobdiff_plain;f=perlmail-accept;h=30e7833254fcf66aef09b191937c0445db69a28a;hp=f51f0db190b9711eb33cf2cfec0e6476c1ed9a3b;hb=9d03569bd26dfb0f54f21063445fc9d28ed1c4d3;hpb=dc95c42776248b09813d8722216e1cef47310163 diff --git a/perlmail-accept b/perlmail-accept index f51f0db..30e7833 100755 --- a/perlmail-accept +++ b/perlmail-accept @@ -10,7 +10,7 @@ use warnings; INIT { require Sys::Syslog; - Sys::Syslog::openlog("lacemail","pid","mail"); + Sys::Syslog::openlog("perlmail","pid","mail"); my @syslogging_stack; sub syslogging_on_save { @@ -27,13 +27,18 @@ INIT { } +use File::Basename; +BEGIN { + use lib $ENV{"PERLMAIL_BASEDIR"} || File::Basename::dirname($0); + use PerlMail::Config; + } + use Mail::Audit qw(MAPS); require IO::Handle; use Carp qw(cluck confess); use POSIX qw(WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG WIFSTOPPED WSTOPSIG); require POSIX; # for ceil use User::Utmp; -require File::Basename; use Getopt::Long; require Mail::Address; require MIME::Words; @@ -49,19 +54,10 @@ use URI::Escape 'uri_escape'; require WWW::SMS; -my $HOME="/home/lace"; -my $Mail="$HOME/Mail"; -my @ValidUsers=qw(root lace short kratochvil _local); -my $IdleMax=120; -my $MaxBodySMS=0x1000; # max bytes to pass to Lingua::EN::Squeeze -my $SMSmailError='short+err@ucw.cz'; -my @SMSwebRcpt=qw(420 602 431329); -my $SMSwebRcpt_username="lace2"; -my $SMScontact=''; - our($Message,$Audit,@AuditStored,$store_ignore,$store_ignorenewmail,$store_profile,$DoBell); -our(%audit_profile,@sms_squeezes,@alternates_host); # imported +our(%audit_profile,@sms_squeezes,@alternates_host,@dnsbl_whitelist); # imported my %alternates_host; # from @alternates_host +my %dnsbl_whitelist; # from @dnsbl_whitelist # from RedHat "procmail-3.22-5" # /i should be only $procmailFROM_DAEMON but how it can hurt to /i all? @@ -99,7 +95,7 @@ sub stdin exit 0; } -# FIXME: separate 'lacemail'-transfer together with lacemail-submit away +# FIXME: separate 'perlmail'-transfer together with perlmail-submit away sub inetd { die "Excessive arguments" if @ARGV; @@ -142,7 +138,7 @@ sub bell sub useridle { - return 0 if ! -e $ENV{"HOME"}."/idle"; + return 0 if ! -e "$HOME/away"; my %valid_users=map(($_=>1),@ValidUsers); my($idlebest,$linebest); for my $utmp (User::Utmp::getut(),{ "ut_line"=>"psaux" }) { @@ -254,7 +250,7 @@ my($ignorenewmail,$smscount,%args)=@_; return map({ my $l=160; if (!$ignorenewmail) { # send by mail - $l-=length("Z emailu $SMSmailError: "); + $l-=length("Z emailu FIXME SMSmailError: "); $l-=length(smsbuild($_,$smscount)); } else { # send by web @@ -406,7 +402,7 @@ my($folder,$profile,%args)=@_; push @AuditStored,$folder if $do{"did"}; return if $store_ignore || $opt_dry; $DoBell++ if $do{"bell"}; - write_message($folder); + write_message($folder) or die; smssend_tryall $store_ignorenewmail,$do{"sms"},%args if $do{"sms"}; } @@ -457,12 +453,12 @@ my($message)=@_; local $Audit=Mail::Audit->new( "emergency"=>"$Mail/emergency", "data"=>[map("$_\n",split("\n",$message))], - "log"=>"$HOME/.lacemail.log", + "log"=>"$HOME/.perlmail.log", "loglevel"=>99, ); local @AuditStored=(); do { smssend 0,$opt_smstest; return; } if $opt_smstest; - write_message("$Mail/input"); + write_message("$Mail/input") or die; audit(); warn 'Corrupted $_, repaired' if defined($save_)!=defined($_) || (defined($_) && $save_ ne $_); } @@ -480,7 +476,7 @@ sub razor2 open CHILD,'|' .'('.'(razor-check 2>&1;echo >&3 $?)' .'|sed "s/^/razor-check: /"' - .'|logger -t "lacemail['.$$.']" -p mail.crit' + .'|logger -t "perlmail['.$$.']" -p mail.crit' .') 3>&1' .'|exit `cat`' or return 0; @@ -514,10 +510,6 @@ sub Received_for return @r; } -my %dnsbl_whitelist=map(($_=>1),( - "195.250.128.83" # smtp3.vol.cz; 83.128.250.195.blackholes.five-ten-sg.com - )); - # Extended Mail::Audit::MAPS # $domain,$full,[$timeout] sub dnsbl @@ -527,8 +519,9 @@ my($domain,$full,$timeout)=@_; $timeout||=30; # sec $Mail::Audit::MAPS::host=$domain; my @hosts=map({ s/^.*://; "[$_]"; } # strip DNS part - grep({ /^([^:@]*):/ && !$alternates_host{$1} # leave only foreign hosts - && !$dnsbl_whitelist{$1}; } (Received_for())) + grep({ /^([^:@]*):/ # $1 is DNS name, $' is IP address + && !$alternates_host{$1} # leave only foreign hosts + && !$dnsbl_whitelist{$'}; } (Received_for())) ); splice @hosts,1 if !$full && @hosts; # "&& @hosts" to prevent: WARN: splice() offset past end of array { @@ -626,7 +619,7 @@ sub muttrc_aliases } # FIXME: Unify -# BEGIN lacemail-sendmail +# BEGIN perlmail-sendmail # return: Mail::Address instance or undef() sub parseone { @@ -637,7 +630,7 @@ my($line)=@_; warn "Got ".scalar(@r)." addresses while wanting just one; when parsing: $line" if 1!=@r; return $r[0]; } -# END lacemail-sendmail +# END perlmail-sendmail # FIXME: host may get multiple recipients and thus not showing "for <...>" # FIXME: muttrc_get("from") is too strict @@ -731,14 +724,13 @@ my($header,$map)=@_; $text=~s/\b\Q$from\E\b/$to/gsi; } return if $text eq $orig; - $Audit->put_header("X-LaceMail-header_remap-$header",$orig); + $Audit->put_header("X-PerlMail-header_remap-$header",$orig); $Audit->replace_header($header,$text); } # MAIN -my $basedir=File::Basename::dirname($0); $Getopt::Long::ignorecase=0; die "GetOptions error" if !Getopt::Long::GetOptions( "inetd" ,sub { $opt_mode=\&inetd; }, @@ -748,20 +740,13 @@ die "GetOptions error" if !Getopt::Long::GetOptions( "idle!" ,\$opt_idle, "idletest" ,sub { syslogging_restore(); print((defined($_=useridle()) ? $_ : "")."\n"); exit 0; }, "muttrc" ,sub { syslogging_restore(); print scalar muttrc(); exit 0; }, - "d|basedir=s",\&basedir, ); # "Excessive arguments" checked in &inetd die "Missing mode" if !$opt_mode; -my $filenameMyAudit="$basedir/My-Audit.pm"; -open AUDIT,$filenameMyAudit or die "open \"$filenameMyAudit\": $!"; -{ - local $/=undef(); - eval or die "eval \"$filenameMyAudit\": $@"; - audit_init(); - %alternates_host=map((lc($_)=>1),@alternates_host); - } -close AUDIT or warn "close \"$filenameMyAudit\": $!"; +PerlMail::Config::audit_init(); +%alternates_host=map((lc($_)=>1),@alternates_host); +%dnsbl_whitelist=map(( $_ =>1),@dnsbl_whitelist); &$opt_mode(); die "NOTREACHED";