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

Message headers: skip records with unsupported characters #546

Merged
merged 6 commits into from
Aug 26, 2022
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/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ public function __construct(\stdClass $headers)
$headers = \array_change_key_case((array) $headers);

foreach ($headers as $key => $value) {
$this[$key] = $this->parseHeader($key, $value);
try {
$this[$key] = $this->parseHeader($key, $value);
} catch (\Ddeboer\Imap\Exception\UnsupportedCharsetException $e) {
// safely skip header with unsupported charset
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1067,4 +1067,20 @@ public function testGbkCharsetDecoding(): void

static::assertSame('Hi', \trim($message->getDecodedContent()));
}

public function testUndefinedCharset(): void
{
$this->mailbox->addMessage($this->getFixture('undefined_charset_header'));

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

$headers = $message->getHeaders();

static::assertCount(1, $message->getTo());
static::assertSame('<[email protected]>', $headers['message_id']);
static::assertArrayNotHasKey('subject', $headers);
static::assertArrayNotHasKey('from', $headers);
static::assertNull($message->getSubject());
static::assertNull($message->getFrom());
}
}
20 changes: 20 additions & 0 deletions tests/fixtures/undefined_charset_header.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
X-Real-To: <[email protected]>
X-Stored-In: BlaBla
Return-Path: <[email protected]>
Received: from <[email protected]>
by bla.bla (CommuniGate Pro RULE 6.1.13)
with RULE id 14057804; Mon, 27 Feb 2017 13:21:44 +0930
X-Autogenerated: Mirror
Resent-From: <[email protected]>
Resent-Date: Mon, 27 Feb 2017 13:21:44 +0930
Message-Id: <[email protected]>
From: =?X-IAS-German?B?bXlHb3Y=?=<[email protected]>
To: [email protected]
Subject: =?X-IAS-German?B?U3VibWl0IHlvdXIgdGF4IHJlZnVuZCB8IEF1c3RyYWxpYW4gVGF4YXRpb24gT2ZmaWNlLg==?=
Date: 27 Feb 2017 04:51:29 +0100
MIME-Version: 1.0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

)