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

Deal the Apple Unsubscribe Notification as an ARF #516

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 25 additions & 6 deletions lib/Sisimai/ARF.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,23 @@ sub is_arf {
my $heads = shift || return 0;
my $match = 0;

state $reportfrom = ['staff@hotmail.com', 'complaints@email-abuse.amazonses.com'];
if( Sisimai::String->aligned(\$heads->{'content-type'}, ['report-type=', 'feedback-report']) ) {
# Content-Type: multipart/report; report-type=feedback-report; ...
$match = 1;
# Content-Type: multipart/report; report-type=feedback-report; ...
return 1 if Sisimai::String->aligned(\$heads->{'content-type'}, ['report-type=', 'feedback-report']);

} elsif( index($heads->{'content-type'}, 'multipart/mixed') > -1 ) {
if( index($heads->{'content-type'}, 'multipart/mixed') > -1 ) {
# Microsoft (Hotmail, MSN, Live, Outlook) uses its own report format.
# Amazon SES Complaints bounces
if( index($heads->{'subject'}, 'complaint about message from ') > -1 ) {
# From: staff@hotmail.com
# From: complaints@email-abuse.amazonses.com
# Subject: complaint about message from 192.0.2.1
my $rf = ['staff@hotmail.com', 'complaints@email-abuse.amazonses.com'];
my $cv = Sisimai::Address->s3s4($heads->{'from'});
$match = 1 if grep { index($cv, $_) > -1 } @$reportfrom;
$match = 1 if grep { index($cv, $_) > -1 } @$rf;
}
}
$match = 1 if ($heads->{'x-apple-unsubscribe'} // '') eq 'true'; # X-Apple-Unsubscribe: true

return $match;
}

Expand Down Expand Up @@ -285,6 +286,24 @@ sub inquire {
$commondata->{'diagnosis'} = sprintf(
"This is a Microsoft email abuse report for an email message received from IP %s on %s",
$arfheaders->{'rhost'}, $mhead->{'date'});

} elsif( index($mhead->{'subject'}, 'unsubscribe') > -1 ) {
# Apple Mail sent this email to unsubscribe from the message
while(1) {
# Subject: unsubscribe
# Content-Type: text/plain; charset=UTF-8
# Auto-Submitted: auto-replied
# X-Apple-Unsubscribe: true
#
# Apple Mail sent this email to unsubscribe from the message
last unless $mhead->{'x-apple-unsubscribe'};
last unless $mhead->{'x-apple-unsubscribe'} eq 'true';
last unless index($$mbody, 'Apple Mail sent this email to unsubscribe from the message') > -1;

$dscontents->[-1]->{'recipient'} = Sisimai::Address->s3s4($mhead->{'from'});
$dscontents->[-1]->{'feedbacktype'} = 'opt-out';
last;
}
}

for my $e ( @$dscontents ) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Sisimai/Message.pm
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ sub sift {
unless( $haveloaded->{'Sisimai::ARF'} ) {
# Feedback Loop message
require Sisimai::ARF;
$havesifted = Sisimai::ARF->inquire($mailheader, $bodystring) if Sisimai::ARF->is_arf($mailheader);
$havesifted = Sisimai::ARF->inquire($mailheader, $bodystring);
last(PARSER) if $havesifted;
}

Expand Down
27 changes: 27 additions & 0 deletions set-of-emails/maildir/bsd/arf-26.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Date: Thu, 2 May 2024 17:48:55 +0000 (UTC)
From: example@icloud.com
Reply-To: example@icloud.com
To: opt-out-100731.e75std53hz8rnmy4r@example.org
Message-ID: <898B6152-36BC-4F4B-ABF8-2694A88CB5FC@icloud.com>
Subject: unsubscribe
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com;
s=1a1hai; t=1714672136; bh=63IYtxpNtEan90vzJQT9iqnMeWHy9rlx8iFLnco1rRc=;
h=Content-Type:From:Mime-Version:Date:Subject:Message-Id:To;
b=AoovfvadwxCx8Pp5yD62kw1AcKMQV32RhSrBsyw4qLr/CVsQo1tIh+xCUPdI7So9i
paxzn20YdVvHuP3f8CxT/q3x9WaQV3NDAmbbQumYwOpJk7yNXRkuWNjIlt6isZM0tb
FK8v+Tq3j3Va83mZ6OeR8ZjvfY8ImjewEOTEZ79sNxToaaHvRuDWRbzt4uaktRuL44
j1wEjiKxgy6f7bOC2XJyRaf41BtCm4V6TGtcBF9hOEMzn6LulaLgashs3yGQ92wkb9
OLSy1uP0iA4nj/qAM+QaauAFzmqYmqa9r7rUFCjqf01q4gvn1QfO4QVqiRQXiMXc8e
QPSqskbSbsIQA==
X-Proofpoint-GUID: fiybgv3DewxSxApGH8GnpeSw3OZld4ll
Auto-Submitted: auto-replied
X-Apple-Unsubscribe: true
X-Proofpoint-ORIG-GUID: fiybgv3DewxSxApGH8GnpeSw3OZld4ll
X-Virus-Status: Clean

Apple Mail sent this email to unsubscribe from the message =E2=80=9Cunsubsc=
ribe=E2=80=9D.

2 changes: 1 addition & 1 deletion t/022-mail-maildir.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ my $Methods = {
'class' => ['new'],
'object' => ['path', 'dir', 'file', 'size', 'offset', 'handle', 'read'],
};
my $MaildirSize = 526;
my $MaildirSize = 527;
my $SampleEmail = './set-of-emails/maildir/bsd';
my $NewInstance = $Package->new($SampleEmail);

Expand Down
1 change: 1 addition & 0 deletions t/899-arf.t
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ my $isexpected = {
'23' => [['', '', 'feedback', 0, 'abuse' ]],
'24' => [['', '', 'feedback', 0, 'abuse' ]],
'25' => [['', '', 'feedback', 0, 'abuse' ]],
'26' => [['', '', 'feedback', 0, 'opt-out' ]],
};

$enginetest->($enginename, $isexpected);
Expand Down
Loading