Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement some classes in Sisimai::Rhost::* #523

Merged
merged 13 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Sisimai/Fact.pm
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
# Decide the reason of email bounce
if( $o->{'reason'} eq '' || exists $retryindex->{ $o->{'reason'} } ) {
# The value of "reason" is empty or is needed to check with other values again
$o->{'reason'} = '' if $o->{'reason'} eq 'undefined' || $o->{'reason'} eq 'onhold';
my $re; my $de = $o->{'destination'};
$re = Sisimai::Rhost->get($o) if Sisimai::Rhost->match($o->{'rhost'});
$re ||= Sisimai::Rhost->get($o, $de) if Sisimai::Rhost->match($de);
Expand Down Expand Up @@ -403,7 +404,7 @@
sub softbounce {
# Emulate "softbounce" accessor for the backward compatible
# @return [Integer]
warn ' ***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead';

Check failure on line 407 in lib/Sisimai/Fact.pm

View workflow job for this annotation

GitHub Actions / Make Test with Perl 5.26

***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead

Check failure on line 407 in lib/Sisimai/Fact.pm

View workflow job for this annotation

GitHub Actions / Make Test with Perl 5.26

***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead

Check failure on line 407 in lib/Sisimai/Fact.pm

View workflow job for this annotation

GitHub Actions / Make Test with Perl 5.26

***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead

Check failure on line 407 in lib/Sisimai/Fact.pm

View workflow job for this annotation

GitHub Actions / Make Test with Perl 5.26

***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead

Check failure on line 407 in lib/Sisimai/Fact.pm

View workflow job for this annotation

GitHub Actions / Make Test with Perl 5.26

***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead

Check failure on line 407 in lib/Sisimai/Fact.pm

View workflow job for this annotation

GitHub Actions / Make Test with Perl 5.26

***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead

Check failure on line 407 in lib/Sisimai/Fact.pm

View workflow job for this annotation

GitHub Actions / Make Test with Perl 5.26

***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead

Check failure on line 407 in lib/Sisimai/Fact.pm

View workflow job for this annotation

GitHub Actions / Make Test with Perl 5.26

***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead

Check failure on line 407 in lib/Sisimai/Fact.pm

View workflow job for this annotation

GitHub Actions / Make Test with Perl 5.26

***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead

Check failure on line 407 in lib/Sisimai/Fact.pm

View workflow job for this annotation

GitHub Actions / Make Test with Perl 5.38

***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead

Check failure on line 407 in lib/Sisimai/Fact.pm

View workflow job for this annotation

GitHub Actions / Make Test with Perl 5.38

***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead

Check failure on line 407 in lib/Sisimai/Fact.pm

View workflow job for this annotation

GitHub Actions / Make Test with Perl 5.38

***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead

Check failure on line 407 in lib/Sisimai/Fact.pm

View workflow job for this annotation

GitHub Actions / Make Test with Perl 5.38

***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead

Check failure on line 407 in lib/Sisimai/Fact.pm

View workflow job for this annotation

GitHub Actions / Make Test with Perl 5.38

***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead

Check failure on line 407 in lib/Sisimai/Fact.pm

View workflow job for this annotation

GitHub Actions / Make Test with Perl 5.38

***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead

Check failure on line 407 in lib/Sisimai/Fact.pm

View workflow job for this annotation

GitHub Actions / Make Test with Perl 5.38

***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead

Check failure on line 407 in lib/Sisimai/Fact.pm

View workflow job for this annotation

GitHub Actions / Make Test with Perl 5.38

***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead

Check failure on line 407 in lib/Sisimai/Fact.pm

View workflow job for this annotation

GitHub Actions / Make Test with Perl 5.38

***warning: Sisimai::Fact->softbounce will be removed at v5.1.0. Use Sisimai::Fact->hardbounce instead
my $self = shift;
return 0 if $self->hardbounce == 1;
return -1 if $self->reason eq 'delivered' || $self->reason eq 'feedback' || $self->reason eq 'vacation';
Expand Down
2 changes: 2 additions & 0 deletions lib/Sisimai/Rhost.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use strict;
use warnings;

state $RhostClass = {
'Apple' => ['.mail.icloud.com', '.apple.com', '.me.com'],
'Cox' => ['cox.net'],
'FrancePTT' => ['.laposte.net', '.orange.fr', '.wanadoo.fr'],
'GoDaddy' => ['smtp.secureserver.net', 'mailstore1.secureserver.net'],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'GoDaddy' => ['.secureserver.net'],

Expand All @@ -15,6 +16,7 @@ state $RhostClass = {
'NTTDOCOMO' => ['mfsmax.docomo.ne.jp'],
'Spectrum' => ['charter.net'],
'Tencent' => ['.qq.com'],
'YahooInc' => ['.yahoodns.net'],
};

sub match {
Expand Down
124 changes: 124 additions & 0 deletions lib/Sisimai/Rhost/Apple.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package Sisimai::Rhost::Apple;
use v5.26;
use strict;
use warnings;

sub get {
# Detect bounce reason from Apple iCloud Mail
# @param [Sisimai::Fact] argvs Parsed email object
# @return [String] The bounce reason for Apple
# @see https://support.apple.com/en-us/102322
# https://www.postmastery.com/icloud-postmastery-page/
# https://smtpfieldmanual.com/provider/apple
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@since v5.0.4

my $class = shift;
my $argvs = shift // return undef;
return $argvs->{'reason'} if $argvs->{'reason'};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code above should be removed and checked at Sisimai::Rhost->get method.


state $messagesof = {
'authfailure' => [
# - 554 5.7.1 Your message was rejected due to example.jp's DMARC policy.
# See https://support.apple.com/en-us/HT204137 for
# - 554 5.7.1 [HME1] This message was blocked for failing both SPF and DKIM authentication
# checks. See https://support.apple.com/en-us/HT204137 for mailing best practices
's dmarc policy',
'blocked for failing both spf and dkim autentication checks',
],
'blocked' => [
# - 550 5.7.0 Blocked - see https://support.proofpoint.com/dnsbl-lookup.cgi?ip=192.0.1.2
# - 550 5.7.1 Your email was rejected due to having a domain present in the Spamhaus
# DBL -- see https://www.spamhaus.org/dbl/
# - 550 5.7.1 Mail from IP 192.0.2.1 was rejected due to listing in Spamhaus SBL.
# For details please see http://www.spamhaus.org/query/bl?ip=x.x.x.x
# - 554 ****-smtpin001.me.com ESMTP not accepting connections
'rejected due to having a domain present in the spamhaus',
'rejected due to listing in spamhaus',
'blocked - see https://support.proofpoint.com/dnsbl-lookup',
'not accepting connections',
],
'hasmoved' => [
# - 550 5.1.6 recipient no longer on server: *****@icloud.com
'recipient no longer on server',
],
'mailboxfull' => [
# - 552 5.2.2 <****@icloud.com>: user is over quota (in reply to RCPT TO command)
'user is over quota',
],
'norelaying' => [
# - 554 5.7.1 <*****@icloud.com>: Relay access denied
'relay access denied',
],
'notaccept' => ['host/domain does not accept mail'],
'policyviolation' => [
# - 550 5.7.1 [CS01] Message rejected due to local policy.
# Please visit https://support.apple.com/en-us/HT204137
'due to local policy',
],
'rejected' => [
# - 450 4.1.8 <kijitora@example.jp>: Sender address rejected: Domain not found
'sender address rejected',
],
'speeding' => [
# - 421 4.7.1 Messages to ****@icloud.com deferred due to excessive volume.
# Try again later - https://support.apple.com/en-us/HT204137
'due to excessive volume',
],
'userunknown' => [
# - 550 5.1.1 <****@icloud.com>: inactive email address (in reply to RCPT TO command)
# - 550 5.1.1 unknown or illegal alias: ****@icloud.com
'inactive email address',
'user does not exist',
'unknown or illegal alias',
],
};

my $issuedcode = lc $argvs->{'diagnosticcode'};
my $reasontext = '';

for my $e ( keys %$messagesof ) {
# Try to find the error message matches with the given error message string
next unless grep { index($issuedcode, $_) > -1 } $messagesof->{ $e }->@*;
$reasontext = $e;
last;
}
return $reasontext;
}

1;
__END__

=encoding utf-8

=head1 NAME

Sisimai::Rhost::Apple - Detect the bounce reason returned from Apple iCloud Mail

=head1 SYNOPSIS

use Sisimai::Rhost;

=head1 DESCRIPTION

Sisimai::Rhost detects the bounce reason from the content of Sisimai::Fact object as an argument
of get() method when the value of C<rhost> of the object end with "mail.icloud.com" or "apple.com".
This class is called only Sisimai::Fact class.

=head1 CLASS METHODS

=head2 C<B<get(I<Sisimai::Fact Object>)>>

C<get()> detects the bounce reason.

=head1 AUTHOR

azumakuniyuki

=head1 COPYRIGHT

Copyright (C) 2024 azumakuniyuki, All rights reserved.

=head1 LICENSE

This software is distributed under The BSD 2-Clause License.

=cut

133 changes: 133 additions & 0 deletions lib/Sisimai/Rhost/YahooInc.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package Sisimai::Rhost::YahooInc;
use v5.26;
use strict;
use warnings;

sub get {
# Detect bounce reason from Yahoo Inc. (*.yahoodns.net)
# @param [Sisimai::Fact] argvs Parsed email object
# @return [String] The bounce reason for YahooInc
# @see https://senders.yahooinc.com/smtp-error-codes
# https://smtpfieldmanual.com/provider/yahoo
# https://www.postmastery.com/yahoo-postmaster/
my $class = shift;
my $argvs = shift // return undef;
return $argvs->{'reason'} if $argvs->{'reason'};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code above should be removed and checked at Sisimai::Rhost->get method.


state $messagesof = {
'authfailure' => [
# - 550 5.7.9 This mail has been blocked because the sender is unauthenticated. Yahoo
# requires all senders to authenticate with either SPF or DKIM.
'yahoo requires all senders to authenticate with either spf or dkim',
],
'badreputation' => [
# - 421 4.7.0 [TSS04] Messages from 192.0.2.25 temporarily deferred due to unexpected
# volume or user complaints - 4.16.55.1;
# see https://postmaster.yahooinc.com/error-codes (in reply to MAIL FROM command))
'temporarily deferred due to unexpected volume or user complaints',
],
'blocked' => [
# - 553 5.7.1 [BL21] Connections will not be accepted from 192.0.2.25,
# because the ip is in Spamhaus's list; see http://postmaster.yahoo.com/550-bl23.html
# - 553 5.7.1 [BL23] Connections not accepted from IP addresses on Spamhaus XBL;
# see http://postmaster.yahoo.com/errors/550-bl23.html [550]",
" because the ip is in spamhaus's list;",
'not accepted from ip addresses on spamhaus xbl',
],
'norelaying' => [
# - 550 relaying denied for <***@yahoo.com>
'relaying denied for ',
],
'notcomplaintrfc' => ['headers are not rfc compliant'],
'policyviolation' => [
# - 554 Message not allowed - [PH01] Email not accepted for policy reasons.
# Please visit https://postmaster.yahooinc.com/error-codes
# - 554 5.7.9 Message not accepted for policy reasons.
# See https://postmaster.yahooinc.com/error-codes
'not accepted for policy reasons',
],
'rejected' => [
# - 553 5.7.2 [TSS09] All messages from 192.0.2.25 will be permanently deferred;
# Retrying will NOT succeed. See https://postmaster.yahooinc.com/error-codes
# - 553 5.7.2 [TSS11] All messages from 192.0.2.25 will be permanently deferred;
# Retrying will NOT succeed. See https://postmaster.yahooinc.com/error-codes
' will be permanently deferred',
],
'speeding' => [
# - 450 User is receiving mail too quickly
'User is receiving mail too quickly',
],
'suspend' => [
# - 554 delivery error: dd ****@yahoo.com is no longer valid.
# - 554 30 Sorry, your message to *****@aol.jp cannot be delivered.
# This mailbox is disabled (554.30)
' is no longer valid.',
'This mailbox is disabled',
],
'syntaxerror' => [
# - 501 Syntax error in parameters or arguments
'syntax error in parameters or arguments',
],
'toomanyconn' => [
# - 421 Max message per connection reached, closing transmission channel
'max message per connection reached',
],
'userunknown' => [
# - 554 delivery error: dd This user doesn't have a yahoo.com account (***@yahoo.com)
# - 552 1 Requested mail action aborted, mailbox not found (in reply to end of DATA command)
"dd this user doesn't have a ",
'mailbox not found',
],
};

my $issuedcode = lc $argvs->{'diagnosticcode'};
my $reasontext = '';

for my $e ( keys %$messagesof ) {
# Try to find the error message matches with the given error message string
next unless grep { index($issuedcode, $_) > -1 } $messagesof->{ $e }->@*;
$reasontext = $e;
last;
}
return $reasontext;
}

1;
__END__

=encoding utf-8

=head1 NAME

Sisimai::Rhost::YahooInc - Detect the bounce reason returned from Yahoo Inc.

=head1 SYNOPSIS

use Sisimai::Rhost;

=head1 DESCRIPTION

Sisimai::Rhost detects the bounce reason from the content of Sisimai::Fact object as an argument
of get() method when the value of C<rhost> of the object end with ".yahoodns.net". This class is
called only Sisimai::Fact class.

=head1 CLASS METHODS

=head2 C<B<get(I<Sisimai::Fact Object>)>>

C<get()> detects the bounce reason.

=head1 AUTHOR

azumakuniyuki

=head1 COPYRIGHT

Copyright (C) 2024 azumakuniyuki, All rights reserved.

=head1 LICENSE

This software is distributed under The BSD 2-Clause License.

=cut

79 changes: 79 additions & 0 deletions set-of-emails/maildir/bsd/rhost-apple-01.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
Return-path: <>
Envelope-to: nekonyaan@example.com
Delivery-date: Thu, 17 Jul 2014 23:34:45 -0500
Received: from mail-in2.apple.com ([192.0.2.1]:1111)
by neko.example.com with esmtp (Exim 4.80)
id 20000A-00000B-NN
for nekonyaan@example.com; Thu, 17 Jul 2014 23:34:45 -0500
From: <Mailer-Daemon@mail-in2.apple.com> (Mail Delivery System)
Message-ID: <AA.BB.00000.00000CCC@mail-in2.apple.com>
To: nekonyaan@example.com
Subject: Undelivered Mail Returned to Sender
Date: Thu, 17 Jul 2014 23:34:45 -0700
MIME-Version: 1.0
Content-Type: multipart/report; report-type=delivery-status;
boundary="RnJpIEp1bCAxMyAyMjowNzoyMyBKU1QgMjAxOAo="

This is a MIME-encapsulated message.

--RnJpIEp1bCAxMyAyMjowNzoyMyBKU1QgMjAxOAo=
Content-Description: Notification
Content-Type: text/plain

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to <postmaster@example.jp>

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

<kijitora@example.jp>: 550 5.1.6 recipient no longer on server: kijitora@example.jp


--RnJpIEp1bCAxMyAyMjowNzoyMyBKU1QgMjAxOAo=
Content-Description: Delivery report
Content-Type: message/delivery-status

X-Symantec-Messaging-Gateway-Queue-ID: AA/AA-00000-00000000
X-Symantec-Messaging-Gateway-Sender: rfc822; nekonyaan@example.com
Reporting-MTA: dns; mail-in2.apple.com
Arrival-Date: Thu, 17 Jul 2014 23:34:45 -0700

Final-Recipient: rfc822; kijitora@example.jp
Status: 5.1.6
Action: failed
Last-Attempt-Date: Thu, 17 Jul 2014 23:34:45 -0700
Diagnostic-Code: smtp; 550 5.1.6 recipient no longer on server: kijitora@example.jp

--RnJpIEp1bCAxMyAyMjowNzoyMyBKU1QgMjAxOAo=
Content-Description: Undelivered Message
Content-Type: message/rfc822

Received: from r1.example.com (r1.example.com [203.0.113.4])
by mail-in2.apple.com (Apple Secure Mail Relay) with SMTP id AA.AA.00000.00000000; Thu, 17 Jul 2014 23:34:45 -0700 (PDT)
Received: by r1.example.com (Postfix, from userid 2202)
id AAAAAAAACCCCC; Thu, 17 Jul 2014 23:34:45 -0500 (CDT)
Received: from smtp2.example.com (smtp.example.com [192.0.2.225])
by r1.example.com (Postfix) with ESMTP id BBBBBBBB22222
for <kijitora@example.jp>; Thu, 17 Jul 2014 23:34:45 -0500 (CDT)
Received: by smtp2.example.com (Postfix, from userid 2220)
id AAAAAAAA00000; Thu, 17 Jul 2014 23:34:45 -0500 (CDT)
Received: from neko.example.com (neko.example.com [198.51.100.198])
by smtp2.example.com (Postfix) with ESMTP id EEEEEEEE11112
for <kijitora@example.jp>; Thu, 17 Jul 2014 23:34:45 -0500 (CDT)
Received: from neko22 by neko.example.com with local (Exim 4.80)
(envelope-from <nekonyaan@example.com>)
id 2Aneko-00022X-BB
for kijitora@example.jp; Thu, 17 Jul 2014 23:34:45 -0500
To: kijitora@example.jp
Subject: Nyaan
Date: Thu, 17 Jul 2014 23:34:45 -0500
From: "Neko, Nyaan" <nekonyaan@example.com>
Message-ID: <c15e793e1c6acf9fbc39d1547bbd98b4@example.com>
MIME-Version: 1.0
Content-Type: text/plain

Nyaan

--RnJpIEp1bCAxMyAyMjowNzoyMyBKU1QgMjAxOAo=--
Loading
Loading