X-Git-Url: http://git.jankratochvil.net/?p=PerlMail.git;a=blobdiff_plain;f=perlmail-accept;h=7eb3f75ddc0c5f349d34d75d1b2467a6944afe2c;hp=c4fa61ebc8cd022e29ad9187b5aaf48b44ad63f3;hb=3a6777a05ce93e572245ca0753e288c680d1f2a3;hpb=8dbc021592be6992b33afbee6b9d91d1990766bf diff --git a/perlmail-accept b/perlmail-accept index c4fa61e..7eb3f75 100755 --- a/perlmail-accept +++ b/perlmail-accept @@ -89,6 +89,7 @@ my $opt_mode; my $opt_smstest; # 1 or $smscount my $opt_idle; my $opt_dry; +my $opt_single; sub process; @@ -101,7 +102,7 @@ sub stdin local $_; while (<>) { die "Invalid 'From ' line: $_" if $message eq "" && !/^From /; - if (/^From / && $message) { + if (!$opt_single && /^From / && $message) { process $message; $message=""; } @@ -130,8 +131,8 @@ sub inetd $length==($_=read STDIN,$message,$length) or confess "Got $_ out of required $length bytes"; $length==length $message or confess "False read return ".length($message)." instead of $length"; { - local *STDOUT; - local *STDERR; + local *STDOUT; # FIXME: fd's inherited by spawned processes are not closed this way! + local *STDERR; # FIXME: fd's inherited by spawned processes are not closed this way! local $DoBell=0; process $message; if ($DoBell) { @@ -489,12 +490,16 @@ my($message)=@_; # return: true (error-message or "1") if is spam sub spamassassin { +my($cmd)=@_; + + $cmd||="spamassassin --exit-code"; # spamassassin has exit code 1 if IS spam, code 0 if NOT spam local *CHILD; local $SIG{"PIPE"}=sub { warn "spamassassin gave me SIGPIPE: broken pipe"; }; # prevent Razor2's: Can't call method "log" on unblessed reference at Razor2/Client/Agent.pm line 212. local $ENV{"HOME"}=$HOME; - open CHILD,'|spamassassin --exit-code --mbox >/dev/null' + # 2>/dev/null to prevent error messages to corrupt inetd() output of perlmail-accept(1) + open CHILD,"|$cmd --mbox >/dev/null 2>/dev/null" or return 0; print CHILD $Message; my $return=close CHILD; @@ -658,6 +663,7 @@ $Getopt::Long::ignorecase=0; die "GetOptions error" if !Getopt::Long::GetOptions( "inetd" ,sub { $opt_mode=\&inetd; }, "stdin" ,sub { $opt_mode=\&stdin; }, + "single!" ,\$opt_single, "dry" ,\$opt_dry, "smstest:s",sub { $opt_mode=\&stdin; $opt_smstest=($_[1] || 1); }, "idle!" ,\$opt_idle,