diff --git a/src/Header/HeaderLine.php b/src/Header/HeaderLine.php index e261485..baff0ea 100644 --- a/src/Header/HeaderLine.php +++ b/src/Header/HeaderLine.php @@ -36,12 +36,7 @@ public function __toString(): string $headerName = (string)$this->header->getName(); $headerValue = (string)$this->header->getValue(); - $firstFoldingAt = \strpos($headerValue, "\r\n"); - if ($firstFoldingAt === false) { - $firstFoldingAt = \strlen($headerValue); - } - - if (\strlen($headerName) + $firstFoldingAt > 76) { + if (\strlen($headerName) > 60) { return \sprintf("%s:\r\n %s", $headerName, $headerValue); } diff --git a/src/Stream/OptimalTransferEncodedPhraseStream.php b/src/Stream/OptimalTransferEncodedPhraseStream.php index 1ac38a3..655fac0 100644 --- a/src/Stream/OptimalTransferEncodedPhraseStream.php +++ b/src/Stream/OptimalTransferEncodedPhraseStream.php @@ -48,17 +48,19 @@ public function __construct(string $text, int $lineLength = 78, string $lineBrea */ private function calculateOptimalStream(string $text): StreamInterface { - if (\strcspn($text, self::NON_7BIT_CHARS) === \strlen($text)) { + $length = \strlen($text); + + if (\strcspn($text, self::NON_7BIT_CHARS) === $length) { $this->encoding = '7bit'; return new AsciiEncodedStream($text, $this->lineLength, $this->lineBreak); } - if (\strcspn($text, HeaderValueParameter::RFC_822_T_SPECIAL) !== \strlen($text)) { + if (\strcspn($text, HeaderValueParameter::RFC_822_T_SPECIAL) !== $length) { $this->encoding = 'base64'; return Base64EncodedStream::fromString($text, $this->lineLength, $this->lineBreak); } - if (\preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $text) > (\strlen($text) / 3)) { + if (\preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $text) > ($length / 3)) { $this->encoding = 'base64'; return Base64EncodedStream::fromString($text, $this->lineLength, $this->lineBreak); } diff --git a/src/Stream/OptimalTransferEncodedTextStream.php b/src/Stream/OptimalTransferEncodedTextStream.php index 9c5a63e..1edb693 100644 --- a/src/Stream/OptimalTransferEncodedTextStream.php +++ b/src/Stream/OptimalTransferEncodedTextStream.php @@ -47,12 +47,14 @@ public function __construct(string $text, int $lineLength = 78, string $lineBrea */ private function calculateOptimalStream(string $text): StreamInterface { - if (\strcspn($text, self::NON_7BIT_CHARS) === \strlen($text)) { + $length = \strlen($text); + + if (\strcspn($text, self::NON_7BIT_CHARS) === $length) { $this->encoding = '7bit'; return new AsciiEncodedStream($text, $this->lineLength, $this->lineBreak); } - if (\preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $text) > (\strlen($text) / 3)) { + if (\preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $text) > ($length / 3)) { $this->encoding = 'base64'; return Base64EncodedStream::fromString($text, $this->lineLength, $this->lineBreak); } diff --git a/test/Stub/MessageBodyCollection/attachment-long-filename.eml b/test/Stub/MessageBodyCollection/attachment-long-filename.eml index 8553ac6..48e73f4 100644 --- a/test/Stub/MessageBodyCollection/attachment-long-filename.eml +++ b/test/Stub/MessageBodyCollection/attachment-long-filename.eml @@ -11,8 +11,7 @@ Content-Transfer-Encoding: 7bit --GenkgoMailV2Partfd6a87d339fb Content-Type: text/txt; charset=UTF-8 Content-Transfer-Encoding: base64 -Content-Disposition: - attachment; filename="AAAAAAAA-AAAAAAAAAAAA-AAA_AAAA AAAAAAA AAAAA AAAAA AAAAAAAAAAAA +Content-Disposition: attachment; filename="AAAAAAAA-AAAAAAAAAAAA-AAA_AAAA AAAAAAA AAAAA AAAAA AAAAAAAAAAAA AAAAAAAAAAAAAAAAAA.pdf" dGVzdA==