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

imap_mime_header_decode may return false #322

Merged
merged 2 commits into from
Mar 19, 2018
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
6 changes: 5 additions & 1 deletion src/Message/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ public function get(string $key)
*/
final protected function decode(string $value): string
{
$decoded = '';
$parts = \imap_mime_header_decode($value);
if (!\is_array($parts)) {
return $value;
}

$decoded = '';
foreach ($parts as $part) {
$text = $part->text;
if ('default' !== $part->charset) {
Expand Down
9 changes: 9 additions & 0 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,15 @@ public function testMixedInlineDisposition()
$this->assertSame('Price4VladDaKar.xlsx', $attachment->getFilename());
}

public function test_imap_mime_header_decode_returns_false()
{
$this->mailbox->addMessage($this->getFixture('imap_mime_header_decode_returns_false'));

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

$this->assertSame('=?UTF-8?B?nnDusSNdG92w6Fuw61fMjAxOF8wMy0xMzMyNTMzMTkzLnBkZg==?=', $message->getSubject());
}

private function resetAttachmentCharset(MessageInterface $message)
{
// Mimic GMAIL behaviour that correctly doesn't report charset
Expand Down
9 changes: 9 additions & 0 deletions tests/fixtures/imap_mime_header_decode_returns_false.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
From: from@there.com
To: to@here.com
Subject: =?UTF-8?B?nnDusSNdG92w6Fuw61fMjAxOF8wMy0xMzMyNTMzMTkzLnBkZg==?=
Date: Wed, 13 Sep 2017 13:05:45 +0200
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hi