From 0f55fbdf041d68c76cee04c6bd170627808f03ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Thu, 20 Jul 2017 22:04:55 +0300 Subject: [PATCH] Workaround for Zend\Mail\Storage\Message parser https://github.com/zendframework/zend-mail/pull/159 Current workaround is to split headers+body ourselves from raw message. --- src/Mail/MailMessage.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Mail/MailMessage.php b/src/Mail/MailMessage.php index c9e85f854a..bcbd95efcd 100644 --- a/src/Mail/MailMessage.php +++ b/src/Mail/MailMessage.php @@ -97,7 +97,22 @@ public static function createNew() */ public static function createFromString($raw) { - $message = new self(['root' => true, 'raw' => $raw]); + // do our own header-body splitting. + // + // \Zend\Mail\Storage\Message is unable to process mails that contain \n\n in text body + // because it has heuristic which headers separator to use + // and that gets out of control + // https://github.com/zendframework/zend-mail/pull/159 + + // use rfc compliant "\r\n" EOL + try { + Mime\Decode::splitMessage($raw, $headers, $content, "\r\n"); + } catch (Mail\Exception\RuntimeException $e) { + // retry with heuristic + Mime\Decode::splitMessage($raw, $headers, $content); + } + + $message = new self(['root' => true, 'headers' => $headers, 'content' => $content]); return $message; }