zendframework/zf2 — pull request #5422 by wccoder (2013-11-05 23:28:11+00:00)
Title: Fix emails that contain lines that start with periods

This pull request contains a unit test (which fails under the current master) and patch for the following problem:

When sending an email via SMTP that has a line in the message body that starts with a period character ("."), the message body gets chopped off at that line and the remote SMTP server closes the connection.

Although escaping code exists in Zend\Mail\Protocol\Smtp's data() method, it doesn't work since it splits the string on "\r\n" but the MimeMessage class uses "\n" for newlines.

Lines 285-291 of Mail/Protocol/Smtp.php:

foreach (explode(self::EOL, $data) as $line) {
if (strpos($line, '.') === 0) {
// Escape lines prefixed with a '.'
$line = '.' . $line;
}
$this->_send($line);

}

https://github.com/zendframework/zf2/blob/master/library/Zend/Mail/Protocol/Smtp.php#L285-L290

Since $data is delimited on "\n" the period escaping never happens, so the message ends prematurely.