git://git.jankratochvil.net
/
PerlMail.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Support 9210 CSV contacts format.
[PerlMail.git]
/
perlmail-accept
diff --git
a/perlmail-accept
b/perlmail-accept
index
4f5fcb5
..
55bef4a
100755
(executable)
--- a/
perlmail-accept
+++ b/
perlmail-accept
@@
-71,8
+71,7
@@
use URI::Escape 'uri_escape';
require WWW::SMS;
require WWW::SMS;
-our($Message,$Audit,@AuditStored,$store_ignore,$store_ignorenewmail,$store_profile,$DoBell);
-our(%audit_profile,@sms_squeezes,@alternates_host,@dnsbl_whitelist); # imported
+our($Message,@AuditStored,$DoBell);
my %alternates_host; # from @alternates_host
my %dnsbl_whitelist; # from @dnsbl_whitelist
my %alternates_host; # from @alternates_host
my %dnsbl_whitelist; # from @dnsbl_whitelist
@@
-81,7
+80,7
@@
my %dnsbl_whitelist; # from @dnsbl_whitelist
our $procmailTO_ =qr'^((Original-)?(Resent-)?(To|Cc|Bcc)|(X-Envelope|Apparently(-Resent)?)-To):(.*[^-a-zA-Z0-9_.])?'mio;
our $procmailTO =qr'^((Original-)?(Resent-)?(To|Cc|Bcc)|(X-Envelope|Apparently(-Resent)?)-To):(.*[^a-zA-Z])?'mio;
our $procmailFROM_DAEMON=qr'^(Mailing-List:|Precedence:.*(junk|bulk|list)|To: Multiple recipients of |(((Resent-)?(From|Sender)|X-Envelope-From):|>?From )([^>]*[^(.%@a-z0-9])?(Post(ma?(st(e?r)?|n)|office)|(send)?Mail(er)?|daemon|m(mdf|ajordomo)|n?uucp|LIST(SERV|proc)|NETSERV|o(wner|ps)|r(e(quest|sponse)|oot)|b(ounce|bs\.smtp)|echo|mirror|s(erv(ices?|er)|mtp(error)?|ystem)|A(dmin(istrator)?|MMGR|utoanswer))(([^).!:a-z0-9][-_a-z0-9]*)?[%@> ][^<)]*(\(.*\).*)?)?$([^>]|$))'mio;
our $procmailTO_ =qr'^((Original-)?(Resent-)?(To|Cc|Bcc)|(X-Envelope|Apparently(-Resent)?)-To):(.*[^-a-zA-Z0-9_.])?'mio;
our $procmailTO =qr'^((Original-)?(Resent-)?(To|Cc|Bcc)|(X-Envelope|Apparently(-Resent)?)-To):(.*[^a-zA-Z])?'mio;
our $procmailFROM_DAEMON=qr'^(Mailing-List:|Precedence:.*(junk|bulk|list)|To: Multiple recipients of |(((Resent-)?(From|Sender)|X-Envelope-From):|>?From )([^>]*[^(.%@a-z0-9])?(Post(ma?(st(e?r)?|n)|office)|(send)?Mail(er)?|daemon|m(mdf|ajordomo)|n?uucp|LIST(SERV|proc)|NETSERV|o(wner|ps)|r(e(quest|sponse)|oot)|b(ounce|bs\.smtp)|echo|mirror|s(erv(ices?|er)|mtp(error)?|ystem)|A(dmin(istrator)?|MMGR|utoanswer))(([^).!:a-z0-9][-_a-z0-9]*)?[%@> ][^<)]*(\(.*\).*)?)?$([^>]|$))'mio;
-
our $procmailFROM_MAILER=qr'^(((Resent-)?(From|Sender)|X-Envelope-From):|>?From )[^>]*\b(Post(ma(st(er)?|n)|office)|(send)?Mail(er)?|daemon|mmdf|n?uucp|ops|r(esponse|oot)|(bbs\.)?smtp(error)?|s(erv(ices?|er)|ystem)|A(dmin(istrator)?|MMGR))(([^).!:a-z0-9][-_a-z0-9]*)?[%@>
][^<)]*(\(.*\).*)?)?$([^>]|$)'mio;
+
$procmailFROM_MAILER=qr'^(((Resent-)?(From|Sender)|X-Envelope-From):|>?From )[^>]*\b(Post(ma(st(er)?|n)|office)|(send)?Mail(er)?|daemon|mmdf|n?uucp|ops|r(esponse|oot)|(bbs\.)?smtp(error)?|s(erv(ices?|er)|ystem)|A(dmin(istrator)?|MMGR))(([^).!:a-z0-9][-_a-z0-9]*)?[%@>
][^<)]*(\(.*\).*)?)?$([^>]|$)'mio;
# perl-5.8.0 does not cope w/original FROM_MAILER on the third '?' character
# Thus we did '([^>]*[^(.%@a-z0-9])?' -> '[^>]*\b', I hope it is somehow similiar
# original FROM_MAILER =qr'^(((Resent-)?(From|Sender)|X-Envelope-From):|>?From )([^>]*[^(.%@a-z0-9])?(Post(ma(st(er)?|n)|office)|(send)?Mail(er)?|daemon|mmdf|n?uucp|ops|r(esponse|oot)|(bbs\.)?smtp(error)?|s(erv(ices?|er)|ystem)|A(dmin(istrator)?|MMGR))(([^).!:a-z0-9][-_a-z0-9]*)?[%@> ][^<)]*(\(.*\).*)?)?$([^>]|$)'mio;
# perl-5.8.0 does not cope w/original FROM_MAILER on the third '?' character
# Thus we did '([^>]*[^(.%@a-z0-9])?' -> '[^>]*\b', I hope it is somehow similiar
# original FROM_MAILER =qr'^(((Resent-)?(From|Sender)|X-Envelope-From):|>?From )([^>]*[^(.%@a-z0-9])?(Post(ma(st(er)?|n)|office)|(send)?Mail(er)?|daemon|mmdf|n?uucp|ops|r(esponse|oot)|(bbs\.)?smtp(error)?|s(erv(ices?|er)|ystem)|A(dmin(istrator)?|MMGR))(([^).!:a-z0-9][-_a-z0-9]*)?[%@> ][^<)]*(\(.*\).*)?)?$([^>]|$)'mio;
@@
-90,6
+89,7
@@
my $opt_mode;
my $opt_smstest; # 1 or $smscount
my $opt_idle;
my $opt_dry;
my $opt_smstest; # 1 or $smscount
my $opt_idle;
my $opt_dry;
+my $opt_single;
sub process;
sub process;
@@
-102,7
+102,7
@@
sub stdin
local $_;
while (<>) {
die "Invalid 'From ' line: $_" if $message eq "" && !/^From /;
local $_;
while (<>) {
die "Invalid 'From ' line: $_" if $message eq "" && !/^From /;
- if (/^From / && $message) {
+ if (
!$opt_single &&
/^From / && $message) {
process $message;
$message="";
}
process $message;
$message="";
}
@@
-131,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";
{
$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) {
local $DoBell=0;
process $message;
if ($DoBell) {
@@
-314,7
+314,7
@@
sub smssend
{
my($ignorenewmail,$smscount,%args)=@_;
{
my($ignorenewmail,$smscount,%args)=@_;
- my $text=audit_sms(
+ my $text=
PerlMail::Config::
audit_sms(
"subject"=>unmime($Audit->subject()),
"from"=>[ Mail::Address->parse(unmime($Audit->from())) ],
"body"=>substr(body_simple(),0,$MaxBodySMS*(1+0.25*$smscount)),
"subject"=>unmime($Audit->subject()),
"from"=>[ Mail::Address->parse(unmime($Audit->from())) ],
"body"=>substr(body_simple(),0,$MaxBodySMS*(1+0.25*$smscount)),
@@
-442,7
+442,7
@@
sub write_message
{
my($folder)=@_;
{
my($folder)=@_;
- return
if $opt_dry;
+ return
1 if $opt_dry; # simulate OK
local *F;
open F,">>$folder" or do { warn "Append \"$folder\": $!"; return 0; };
{
local *F;
open F,">>$folder" or do { warn "Append \"$folder\": $!"; return 0; };
{
@@
-466,8
+466,11
@@
my($message)=@_;
local $_=$_;
my $save_=$_;
local $_=$_;
my $save_=$_;
+ $message=~s/(\n)(From )/$1>$2/sg;
local $Message=$message;
local $Message=$message;
- local $Audit=Mail::Audit->new(
+ # Cannot call 'local' for our-imported variable:
+ my $Audit_save=$Audit;
+ $Audit=Mail::Audit->new(
"emergency"=>"$Mail/emergency",
"data"=>[map("$_\n",split("\n",$message))],
"log"=>"$HOME/.perlmail.log",
"emergency"=>"$Mail/emergency",
"data"=>[map("$_\n",split("\n",$message))],
"log"=>"$HOME/.perlmail.log",
@@
-476,39
+479,35
@@
my($message)=@_;
local @AuditStored=();
do { smssend 0,$opt_smstest; return; } if $opt_smstest;
write_message("$Mail/input") or die;
local @AuditStored=();
do { smssend 0,$opt_smstest; return; } if $opt_smstest;
write_message("$Mail/input") or die;
- audit();
+
PerlMail::Config::
audit();
warn 'Corrupted $_, repaired' if defined($save_)!=defined($_) || (defined($_) && $save_ ne $_);
warn 'Corrupted $_, repaired' if defined($save_)!=defined($_) || (defined($_) && $save_ ne $_);
+ # restore:
+ $Audit=$Audit_save;
}
# utility functions:
# return: true (error-message or "1") if is spam
}
# utility functions:
# return: true (error-message or "1") if is spam
-sub
razor2
+sub
spamassassin
{
{
- # razor-check has exit code 1 if NOT spam, code 0 if IS spam
+my($cmd)=@_;
+
+ $cmd||="$HOME/bin/spamassassin --exit-code";
+ # spamassassin has exit code 1 if IS spam, code 0 if NOT spam
local *CHILD;
local *CHILD;
- local $SIG{"PIPE"}=sub { warn "
razor2
gave me SIGPIPE: broken pipe"; };
+ 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;
# prevent Razor2's: Can't call method "log" on unblessed reference at Razor2/Client/Agent.pm line 212.
local $ENV{"HOME"}=$HOME;
- open CHILD,'|'
- .'('.'(razor-check 2>&1;echo >&3 $?)'
- .'|sed "s/^/razor-check: /"'
- .'|logger -t "perlmail['.$$.']" -p mail.crit'
- .') 3>&1'
- .'|exit `cat`'
+ # 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;
or return 0;
print CHILD $Message;
- my $return;
- {
- local $/=undef();
- $return=<CHILD> || 1;
- }
- close CHILD;
+ my $return=close CHILD;
return undef() if !WIFEXITED($?);
return undef() if WIFSIGNALED($?);
return undef() if WIFSTOPPED($?);
return undef() if !WIFEXITED($?);
return undef() if WIFSIGNALED($?);
return undef() if WIFSTOPPED($?);
- return
undef() if WEXITSTATUS($?);
- return
$return; # is
-spam
+ return
1 if WEXITSTATUS($?); # is-spam
+ return
0; # not
-spam
}
# NOTE: returns undef() if !wantarray and the first header is unrecognized
}
# NOTE: returns undef() if !wantarray and the first header is unrecognized
@@
-581,15
+580,10
@@
my($prefix,$profile)=@_;
if $From!~/$alternates/si;
for my $for (reverse Received_for()) {
$for=~s/:.*$//; # strip IP address here
if $From!~/$alternates/si;
for my $for (reverse Received_for()) {
$for=~s/:.*$//; # strip IP address here
- if ($Fromobj->user() ne "prog-mutt") {
- next if lc($for) eq lc($From);
- }
- else {
- my $forobj=parseone $for;
- if ($forobj && $forobj->host()) {
- # it is 'for' our primary address
- next if lc($forobj->host()) eq lc($Fromobj->host()); # or 'return'? shouldn't matter
- }
+ my $forobj=parseone $for;
+ if ($forobj && $forobj->host()) {
+ # it is 'for' our primary address
+ next if lc($forobj->host()) eq lc($Fromobj->host()); # or 'return'? shouldn't matter
}
next if !$alternates_host{lc $for} && $for!~/$alternatesre/si;
store "$prefix\L$for",($profile || []);
}
next if !$alternates_host{lc $for} && $for!~/$alternatesre/si;
store "$prefix\L$for",($profile || []);
@@
-669,6
+663,7
@@
$Getopt::Long::ignorecase=0;
die "GetOptions error" if !Getopt::Long::GetOptions(
"inetd" ,sub { $opt_mode=\&inetd; },
"stdin" ,sub { $opt_mode=\&stdin; },
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,
"dry" ,\$opt_dry,
"smstest:s",sub { $opt_mode=\&stdin; $opt_smstest=($_[1] || 1); },
"idle!" ,\$opt_idle,
@@
-678,7
+673,6
@@
die "GetOptions error" if !Getopt::Long::GetOptions(
# "Excessive arguments" checked in &inetd
die "Missing mode" if !$opt_mode;
# "Excessive arguments" checked in &inetd
die "Missing mode" if !$opt_mode;
-PerlMail::Config::audit_init();
%alternates_host=map((lc($_)=>1),@alternates_host);
%dnsbl_whitelist=map(( $_ =>1),@dnsbl_whitelist);
%alternates_host=map((lc($_)=>1),@alternates_host);
%dnsbl_whitelist=map(( $_ =>1),@dnsbl_whitelist);