Closed jcbf closed 4 years ago
My questions are:
The code I use should have identified these bounces? Is there any simple code that can?
The most simple and reliable way is to read the entire bounce message at your milter code because each response message in a maillog
is not enough to parse and detect a bounce reason.
Sisimai calls Sisimai::Reason::*
and Sisimai::Rhost::*
modules in addition to Sisimai::Lhost::*
modules to detect a bounce reason as shown in the figure: "Sisimai Architecture" at the bottom of https://libsisimai.org/en/docs/ .
Another way? The following dirty hack code might help you, perhaps...
#!/usr/bin/env perl
use strict;
use warnings;
use Sisimai;
use Sisimai::Data;
use Sisimai::Rhost;
use Sisimai::SMTP::Error;
while(<>) {
# For only a maillog of Postfix
my $logmessage = $1 if $_ =~ /status=bounced (.+)$/ || next;
my $remotehost = $1 if $_ =~ /[(]host[ ]([0-9A-Za-z.-]+?)\[/ || next;
my $diagnostic = $1 if $_ =~ /[ ]said:[ ](.+)$/ || next;
my $logcommand = $1 if $_ =~ /[ ](MAIL|RCPT|DATA)[ ]/;
my $parameters = {
'reason' => '',
'diagnosticcode' => $diagnostic,
'deliverystatus' => Sisimai::SMTP::Status->find($logmessage),
'replycode' => Sisimai::SMTP::Reply->find($logmessage),
'rhost' => $remotehost,
'smtpcommand' => $logcommand,
};
my $dataobject = bless($parameters, 'Sisimai::Data');
my $reasonname = Sisimai::Rhost->get($dataobject) || Sisimai->match($logmessage);
$dataobject->{'reason'} = $reasonname || '';
printf("%s\n", $dataobject->reason);
}
$ cat /var/log/maillog | perl ./script-above.pl`
Regards,
That's perfect. Thanks!
Following the question on #385 , I'm doing an analysis of some responses from a Postfix instance:
I'm having some responses that assumed to be already covered, like
My questions are:
I'm writing a milter to parse the full bounce message but this is only done to have an idea on how may messages will be detected and classified.
Regards