Normalise line breaks in S/MIME signed messages
openssl_pkcs7_sign() returns its headers and body with bare LF line breaks. They were copied into the message verbatim, so signed mail was rejected by SMTP servers that enforce RFC 5321 line endings with 550 5.6.11 SMTPSEND.BareLinefeedsAreIllegal. Fixes #3067
This commit is contained in:
1 parent
c138873d49
commit
709e2d5b62
2 files changed
+8
-2
No files matched your search
+3
-2
@@ -3320,8 +3320,9 @@ class PHPMailer
|
||||
@unlink($signed);
|
||||
//The message returned by openssl contains both headers and body, so need to split them up
|
||||
$parts = explode("\n\n", $body, 2);
|
||||
$this->MIMEHeader .= $parts[0] . static::$LE . static::$LE;
|
||||
$body = $parts[1];
|
||||
//openssl emits bare LF breaks, which SMTP servers may reject
|
||||
$this->MIMEHeader .= static::normalizeBreaks($parts[0]) . static::$LE . static::$LE;
|
||||
$body = static::normalizeBreaks($parts[1]);
|
||||
} else {
|
||||
@unlink($signed);
|
||||
throw new Exception(self::lang('signing') . openssl_error_string());
|
||||
|
||||
@@ -971,6 +971,11 @@ EOT;
|
||||
|
||||
$msg = $this->Mail->getSentMIMEMessage();
|
||||
self::assertStringNotContainsString("\r\n\r\nMIME-Version:", $msg, 'Incorrect MIME headers');
|
||||
self::assertSame(
|
||||
0,
|
||||
preg_match_all("/(?<!\r)\n/", $msg),
|
||||
'Signed message contains bare line feeds'
|
||||
);
|
||||
unlink($certfile);
|
||||
unlink($keyfile);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user