From f2cc9969e37064cf8b4c348af00d8030af54a56c Mon Sep 17 00:00:00 2001 From: Jan Szaszi Date: Mon, 21 Feb 2022 13:32:06 +0100 Subject: [PATCH] fix: match also empty value for decoding --- src/Header/Part/MimeLiteralPart.php | 2 +- tests/MailMimeParser/Header/Part/MimeLiteralPartTest.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Header/Part/MimeLiteralPart.php b/src/Header/Part/MimeLiteralPart.php index 974c2f92..05a8cf63 100644 --- a/src/Header/Part/MimeLiteralPart.php +++ b/src/Header/Part/MimeLiteralPart.php @@ -125,7 +125,7 @@ private function decodeMatchedEntity($matches) */ private function decodeSplitPart($entity) { - if (preg_match('/^=\?([A-Za-z\-_0-9]+)\*?([A-Za-z\-_0-9]+)?\?([QBqb])\?([^\?]+)\?=$/', $entity, $matches)) { + if (preg_match('/^=\?([A-Za-z\-_0-9]+)\*?([A-Za-z\-_0-9]+)?\?([QBqb])\?([^\?]*)\?=$/', $entity, $matches)) { return $this->decodeMatchedEntity($matches); } $decoded = $this->convertEncoding($entity); diff --git a/tests/MailMimeParser/Header/Part/MimeLiteralPartTest.php b/tests/MailMimeParser/Header/Part/MimeLiteralPartTest.php index fee843f7..22f5b3fd 100644 --- a/tests/MailMimeParser/Header/Part/MimeLiteralPartTest.php +++ b/tests/MailMimeParser/Header/Part/MimeLiteralPartTest.php @@ -47,6 +47,13 @@ public function testMimeEncoding() $this->assertDecoded('Kilgore Trout', '=?US-ASCII?Q?Kilgore_Trout?='); } + public function testDecodeEmpty() + { + $this->assertDecoded('', '=?US-ASCII?Q??='); + $this->assertDecoded('', '=?utf-8?Q??='); + } + + public function testMimeEncodingNullLanguage() { $part = $this->assertDecoded('Kilgore Trout', '=?US-ASCII?Q?Kilgore_Trout?=');