Skip to content

Commit

Permalink
Test treating attached multipart email as files
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnavy committed Jan 26, 2021
1 parent 85a2d91 commit 3697842
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
67 changes: 67 additions & 0 deletions t/data/emails/email-file-attachment-2.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
Return-Path: <[email protected]>
X-Spam-Flag: NO
X-Spam-Score: -2.449
X-Spam-Level:
X-Spam-Status: No, score=-2.449 tagged_above=-99.9 required=10
tests=[AWL=0.250, BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, KHOP_DYNAMIC=0.001,
RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001] autolearn=ham
X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,,
definitions=2017-07-28_05:,, signatures=0
X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0
clxscore=1034 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0
bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1
engine=8.0.1-1701120000 definitions=main-1707280209
From: Jim Brandt <[email protected]>
Content-type: multipart/mixed;
boundary="Apple-Mail=_E5E623A8-7064-4736-9F2E-2A0F35E3635B"
Subject: This is another test
Message-id: <[email protected]>
Date: Fri, 28 Jul 2017 09:21:48 -0400
To: [email protected]
MIME-version: 1.0 (Mac OS X Mail 9.3 \(3124\))
X-Mailer: Apple Mail (2.3124)


--Apple-Mail=_E5E623A8-7064-4736-9F2E-2A0F35E3635B
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=us-ascii
This is a test with a multipart email file attachment.
--Apple-Mail=_E5E623A8-7064-4736-9F2E-2A0F35E3635B
Content-Type: message/rfc822;
charset="ascii";
name="test-email-2.eml"
Content-Disposition: attachment; filename="test-email-2.eml"
X-RT-Original-Encoding: ascii
Content-Length: 0
MIME-Version: 1.0
To: [email protected]
Date: Thu, 5 Dec 2019 06:12:57 +0000 (UTC)
Content-Type: multipart/alternative;
boundary="===============4845098068763498141=="
Reply-To: [email protected]
Content-Length: 0
This is a multi-part message in MIME format...
--===============4845098068763498141==
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Type: text/plain; charset="utf-8"
Content-Length: 11
plain text
--===============4845098068763498141==
X-RT-Original-Encoding: utf-8
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="utf-8"
Content-Length: 18

<p>plain text</p>

--===============4845098068763498141==--
--Apple-Mail=_E5E623A8-7064-4736-9F2E-2A0F35E3635B--
19 changes: 19 additions & 0 deletions t/mail/email-file-attachments.t
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,23 @@ diag "Process email with an email file attached";
is( $attachment->Filename, 'test-email.eml', 'Got a filename for the attached email file' );
}

diag "Process email with a multipart email file attached";
{
my ($ticket) = mail_in_ticket('email-file-attachment-2.eml');
like( first_txn($ticket)->Content , qr/This is a test with a multipart email file attachment/, "Parsed the email body");
is( count_attachs($ticket), 3,
"Has three attachments, presumably multipart/mixed, text-plain, message");

my $attachments = $ticket->Transactions->First->Attachments;

my $attachment = $attachments->Next;
is( $attachment->Subject, 'This is another test', 'Subject is correct' );

$attachment = $attachments->Next;
is( $attachment->ContentType, 'text/plain', 'Got the first part of the main email' );

$attachment = $attachments->Next;
is( $attachment->Filename, 'test-email-2.eml', 'Got a filename for the attached email file' );
}

done_testing();

0 comments on commit 3697842

Please sign in to comment.