Skip to content

Commit

Permalink
Message headers: skip records with unsupported characters (ddeboer#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanghisleni authored Aug 26, 2022
1 parent c2e4d72 commit c8e26a0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
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

)

0 comments on commit c8e26a0

Please sign in to comment.