mirror of
https://github.com/MailScanner/v5.git
synced 2024-09-20 15:26:08 +08:00
Refactor for multiple emails per session (#305)
* Refactor for multiple emails per session * Add close_callback to milter
This commit is contained in:
parent
e9773ffe44
commit
5521a030ba
|
@ -165,6 +165,45 @@ sub envrcpt_callback
|
|||
# Watch for second callback
|
||||
if ( ${$message_ref} !~ /MailScanner Milter/ ) {
|
||||
|
||||
# Is this a subsequent message? Grab previous message id to reconstruct header
|
||||
if ( ${$message_ref} =~ /^[0-9A-F]{7,20}|[0-9B-DF-HJ-NP-TV-Zb-df-hj-np-tv-z]{8,20}$/ ) {
|
||||
# Read envelope
|
||||
my $queuehandle = new FileHandle;
|
||||
my $incoming = MailScanner::Config::Value('inqueuedir');
|
||||
MailScanner::Log::DebugLog("eoh_callback: incoming = " . @{$incoming}[0]);
|
||||
if ($incoming eq '') {
|
||||
MailScanner::Log::WarnLog("Unable to determine incoming queue!");
|
||||
Sendmail::PMilter::SMFIS_TEMPFAIL;
|
||||
return;
|
||||
}
|
||||
my $file = @{$incoming}[0] . '/temp-' . ${$message_ref};
|
||||
my $file2 = @{$incoming}[0] . '/' . ${$message_ref};
|
||||
|
||||
MailScanner::Log::DebugLog("envrcpt_callback: file = $file");
|
||||
|
||||
my $ret;
|
||||
$ret = MailScanner::Lock::openlock($queuehandle,'+<' . $file, 'w');
|
||||
if ($ret != 1) {
|
||||
MailScanner::Log::WarnLog("Unable to to open temp queue file for reading!");
|
||||
Sendmail::PMilter::SMFIS_TEMPFAIL;
|
||||
return;
|
||||
}
|
||||
|
||||
my $data;
|
||||
my $pos;
|
||||
# Locate predata header
|
||||
while($data = readline $queuehandle) {
|
||||
last if $data !~ /^(O<|S<)/;
|
||||
}
|
||||
|
||||
${$message_ref} = $data;
|
||||
MailScanner::Lock::unlockclose($queuehandle);
|
||||
|
||||
# Done with previous message, make ready for mailscanner
|
||||
move($file, $file2);
|
||||
}
|
||||
|
||||
|
||||
# Capture the Mail From address for further processing
|
||||
if (defined($symbols->{'M'}) && defined($symbols->{'M'}->{'{mail_addr}'})) {
|
||||
$mailfrom=$symbols->{'M'}->{'{mail_addr}'};
|
||||
|
@ -388,6 +427,20 @@ sub eom_callback
|
|||
my $ctx = shift;
|
||||
my $message_ref = $ctx->getpriv();
|
||||
|
||||
# Store reference for subsequent messages in connection or for connection close
|
||||
$ctx->setpriv($message_ref);
|
||||
|
||||
# Send DISCARD signal to accept message and drop from postfix
|
||||
# for mailscanner processing
|
||||
Sendmail::PMilter::SMFIS_DISCARD;
|
||||
|
||||
}
|
||||
|
||||
sub close_callback
|
||||
{
|
||||
my $ctx = shift;
|
||||
my $message_ref = $ctx->getpriv();
|
||||
|
||||
my $incoming = MailScanner::Config::Value('inqueuedir');
|
||||
MailScanner::Log::DebugLog("eom_callback: incoming = " . @{$incoming}[0]);
|
||||
if ($incoming eq '') {
|
||||
|
@ -402,9 +455,7 @@ sub eom_callback
|
|||
|
||||
$ctx->setpriv(undef);
|
||||
|
||||
# Send DISCARD signal to accept message and drop from postfix
|
||||
# for mailscanner processing
|
||||
Sendmail::PMilter::SMFIS_DISCARD;
|
||||
Sendmail::PMilter::SMFIS_CONTINUE;
|
||||
}
|
||||
|
||||
#
|
||||
|
@ -512,6 +563,7 @@ BEGIN {
|
|||
'eoh' => \&eoh_callback,
|
||||
'body' => \&body_callback,
|
||||
'eom' => \&eom_callback,
|
||||
'close' => \&close_callback,
|
||||
);
|
||||
|
||||
my $conn = 'inet:'. $port . '@' . $bind;
|
||||
|
|
Loading…
Reference in a new issue