diff --git a/src/MIMEWriter.php b/src/MIMEWriter.php index dc90d58..53086fb 100644 --- a/src/MIMEWriter.php +++ b/src/MIMEWriter.php @@ -322,8 +322,10 @@ protected function createMultipartBoundaryName(string $prefix): string */ protected function escapeHeaderValue(string $value): string { + $quoted_value = quoted_printable_encode($value); + $quoted_value = str_replace("=\x0d\x0a",'', $quoted_value); return preg_match('/[\x80-\xFF]/', $value) === 1 - ? "=?UTF-8?Q?" . quoted_printable_encode($value) . "?=" + ? "=?UTF-8?Q?" . $quoted_value . "?=" : $value; // as-is } diff --git a/tests/TestMessageFactory.php b/tests/TestMessageFactory.php index cea7b36..d01cd84 100644 --- a/tests/TestMessageFactory.php +++ b/tests/TestMessageFactory.php @@ -218,7 +218,7 @@ public function createMessageWithCustomHeaders(): Message $message = new Message( new Address("blip@test.org"), new Address("blub@test.org"), - "Hey, Rasmus!", + "We need a special character - Ø - so that quoted_printable_encode is used, and more than 75 characters - see documentation for quoted_printable_encode()", "Hello!" ); diff --git a/tests/unit/MIMEWriterCest.php b/tests/unit/MIMEWriterCest.php index 90935dd..06fe48b 100644 --- a/tests/unit/MIMEWriterCest.php +++ b/tests/unit/MIMEWriterCest.php @@ -341,7 +341,7 @@ public function writeMessageWithCustomHeaders(UnitTester $I): void Date: Thu, 15 Sep 2016 17:20:54 +0200 To: blip@test.org From: blub@test.org - Subject: Hey, Rasmus! + Subject: =?UTF-8?Q?We need a special character - =C3=98 - so that quoted_printable_encode is used, and more than 75 characters - see documentation for quoted_printable_encode()?= MIME-Version: 1.0 X-Custom-Header: custom-value Content-Type: text/plain; charset=UTF-8