Skip to content

Commit

Permalink
Strictly checks the valuie of "smtpcommand": Imported from #442
Browse files Browse the repository at this point in the history
  • Loading branch information
azumakuniyuki committed Nov 19, 2021
1 parent 0998d1a commit 57b468f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
11 changes: 7 additions & 4 deletions lib/Sisimai/Reason/Filtered.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ sub true {

require Sisimai::Reason::UserUnknown;
my $alterclass = 'Sisimai::Reason::UserUnknown';
my $commandtxt = $argvs->smtpcommand // '';
my $diagnostic = lc $argvs->diagnosticcode // '';

if( $tempreason eq 'filtered' ) {
# Delivery status code points "filtered".
return 1 if( $alterclass->match($diagnostic) || __PACKAGE__->match($diagnostic) );
return 1 if $alterclass->match($diagnostic);
return 1 if __PACKAGE__->match($diagnostic);

} elsif( $commandtxt ne 'RCPT' && $commandtxt ne 'MAIL' ) {
# Check the value of Diagnostic-Code and the last SMTP command
} else {
# The value of "reason" isn't "filtered" when the value of "smtpcommand" is an SMTP command
# to be sent before the SMTP DATA command because all the MTAs read the headers and the
# entire message body after the DATA command.
return 0 if $argvs->{'smtpcommand'} =~ /\A(?:CONN|EHLO|HELO|MAIL|RCPT)\z/;
return 1 if __PACKAGE__->match($diagnostic);
return 1 if $alterclass->match($diagnostic);
}
Expand Down
11 changes: 3 additions & 8 deletions lib/Sisimai/Reason/NoRelaying.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,9 @@ sub true {
my $class = shift;
my $argvs = shift // return undef;

if( my $r = $argvs->reason // '' ) {
# Do not overwrite the reason
return 0 if( $r eq 'securityerror' || $r eq 'systemerror' || $r eq 'undefined' );
} else {
# Check the value of Diagnosic-Code: header with patterns
return 1 if __PACKAGE__->match(lc $argvs->diagnosticcode);
}
return 0;
return 0 if $argvs->{'reason'} =~ /\A(?:securityerror|systemerror|undefined)\z/;
return 0 if $argvs->{'smtpcommand'} =~ /\A(?:CONN|EHLO|HELO)\z/;
return 1 if __PACKAGE__->match(lc $argvs->{'diagnosticcode'});return 0;
}

1;
Expand Down
5 changes: 5 additions & 0 deletions lib/Sisimai/Reason/SpamDetected.pm
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ sub true {
return undef unless $argvs->deliverystatus;
return 1 if $argvs->reason eq 'spamdetected';
return 1 if (Sisimai::SMTP::Status->name($argvs->deliverystatus) || '') eq 'spamdetected';

# The value of "reason" isn't "spamdetected" when the value of "smtpcommand" is an SMTP command
# to be sent before the SMTP DATA command because all the MTAs read the headers and the entire
# message body after the DATA command.
return 0 if $argvs->{'smtpcommand'} =~ /\A(?:CONN|EHLO|HELO|MAIL|RCPT)\z/;
return 1 if __PACKAGE__->match(lc $argvs->diagnosticcode);
return 0;
}
Expand Down
13 changes: 11 additions & 2 deletions lib/Sisimai/Reason/VirusDetected.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,16 @@ sub true {
# 0: virus was not detected
# @since v4.22.0
# @see http://www.ietf.org/rfc/rfc2822.txt
return undef;
my $class = shift;
my $argvs = shift // return undef;

# The value of "reason" isn't "virusdetected" when the value of "smtpcommand" is an SMTP com-
# mand to be sent before the SMTP DATA command because all the MTAs read the headers and the
# entire message body after the DATA command.
return 1 if $argvs->{'reason'} eq 'virusdetected';
return 0 if $argvs->{'smtpcommand'} =~ /\A(?:CONN|EHLO|HELO|MAIL|RCPT)\z/;
return 1 if __PACKAGE__->match(lc $argvs->{'diagnosticcode'});
return 0;
}

1;
Expand Down Expand Up @@ -90,7 +99,7 @@ azumakuniyuki
=head1 COPYRIGHT
Copyright (C) 2017-2019 azumakuniyuki, All rights reserved.
Copyright (C) 2017-2019,2021 azumakuniyuki, All rights reserved.
=head1 LICENSE
Expand Down
2 changes: 1 addition & 1 deletion xt/619-lhost-ezweb.t
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ my $isexpected = [
{ 'n' => '01105', 'r' => qr/filtered/ },
{ 'n' => '01106', 'r' => qr/userunknown/ },
{ 'n' => '01107', 'r' => qr/filtered/ },
{ 'n' => '01108', 'r' => qr/userunknown/ },
{ 'n' => '01108', 'r' => qr/norelaying/ },
{ 'n' => '01109', 'r' => qr/userunknown/ },
{ 'n' => '01110', 'r' => qr/filtered/ },
{ 'n' => '01111', 'r' => qr/suspend/ },
Expand Down

0 comments on commit 57b468f

Please sign in to comment.