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

Exclude HTML from allowed attachment subtype #212

Merged
merged 1 commit into from
Oct 2, 2017
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
11 changes: 5 additions & 6 deletions src/Message/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,10 @@ private function isAttachment(\stdClass $part)
{
// Attachment with correct Content-Disposition header
if (isset($part->disposition)) {
if (('attachment' === strtolower($part->disposition)
|| 'inline' === strtolower($part->disposition))
&& strtoupper($part->subtype) != 'PLAIN'
if (
('attachment' === strtolower($part->disposition) || 'inline' === strtolower($part->disposition))
&& strtoupper($part->subtype) !== self::SUBTYPE_PLAIN
&& strtoupper($part->subtype) !== self::SUBTYPE_HTML
) {
return true;
}
Expand All @@ -323,9 +324,7 @@ private function isAttachment(\stdClass $part)
// Attachment without Content-Disposition header
if (isset($part->parameters)) {
foreach ($part->parameters as $parameter) {
if ('name' === strtolower($parameter->attribute)
|| 'filename' === strtolower($parameter->attribute)
) {
if ('name' === strtolower($parameter->attribute) || 'filename' === strtolower($parameter->attribute)) {
return true;
}
}
Expand Down
13 changes: 13 additions & 0 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,4 +478,17 @@ public function testAttachmentOnlyEmail()

$this->assertCount(1, $message->getAttachments());
}

/**
* @see https://github.com/ddeboer/imap/issues/142
*/
public function testIssue142()
{
$fixture = $this->getFixture('issue_142');
$this->mailbox->addMessage($fixture);

$message = $this->mailbox->getMessage(1);

$this->assertCount(1, $message->getAttachments());
}
}
23 changes: 23 additions & 0 deletions tests/fixtures/issue_142.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
From: mytaxi Payment <[email protected]>
To: [email protected]
Message-ID: <00000144c8445931-be533ff5-c8b9-4257-a4cd-3c280b2f3854-000000@email.amazonses.com>
Subject: Ihre mytaxi Quittung (49M6J)
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_27875_991041197.1394929323292"
Date: Sun, 16 Mar 2014 00:22:06 +0000

------=_Part_27875_991041197.1394929323292
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

<body>Hi</body>

------=_Part_27875_991041197.1394929323292
Content-Type: application/pdf
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=2014-03-49M6J.pdf

XS9JbmZvIDE3IDAgUi9TaXplIDE4Pj4Kc3RhcnR4cmVmCjE0MDIxMQolJUVPRgo=
------=_Part_27875_991041197.1394929323292--