Skip to content

Commit

Permalink
Fix SMTP Transparency (RFC5321 4.5.2. first line period)
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki committed May 7, 2012
1 parent fe0c7d3 commit db20600
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
3 changes: 0 additions & 3 deletions lib/Cake/Network/Email/CakeEmail.php
Expand Up @@ -1238,9 +1238,6 @@ protected function _wrap($message) {
$formatted[] = '';
continue;
}
if ($line[0] === '.') {
$line = '.' . $line;
}
if (!preg_match('/\<[a-z]/i', $line)) {
$formatted = array_merge($formatted, explode("\n", wordwrap($line, self::LINE_LENGTH_SHOULD, "\n")));
continue;
Expand Down
11 changes: 10 additions & 1 deletion lib/Cake/Network/Email/SmtpTransport.php
Expand Up @@ -168,7 +168,16 @@ protected function _sendData() {

$headers = $this->_cakeEmail->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'subject'));
$headers = $this->_headersToString($headers);
$message = implode("\r\n", $this->_cakeEmail->message());
$lines = $this->_cakeEmail->message();
$messages = array();
foreach ($lines as $line) {
if ((! empty($line)) && ($line[0] === '.')) {
$messages[] = '.' . $line;
} else {
$messages[] = $line;
}
}
$message = implode("\r\n", $messages);
$this->_smtpSend($headers . "\r\n\r\n" . $message . "\r\n\r\n\r\n.");
$this->_content = array('headers' => $headers, 'message' => $message);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Cake/Test/Case/Network/Email/DebugTransportTest.php
Expand Up @@ -51,7 +51,7 @@ public function testSend() {
$email->subject('Testing Message');
$date = date(DATE_RFC2822);
$email->setHeaders(array('X-Mailer' => DebugCakeEmail::EMAIL_CLIENT, 'Date' => $date));
$email->expects($this->any())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '')));
$email->expects($this->any())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', '')));

$headers = "From: CakePHP Test <noreply@cakephp.org>\r\n";
$headers .= "To: CakePHP <cake@cakephp.org>\r\n";
Expand All @@ -66,6 +66,7 @@ public function testSend() {

$data = "First Line\r\n";
$data .= "Second Line\r\n";
$data .= ".Third Line\r\n"; // Not use 'RFC5321 4.5.2.Transparency' in DebugTransport.

$result = $this->DebugTransport->send($email);

Expand Down
3 changes: 2 additions & 1 deletion lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php
Expand Up @@ -221,7 +221,7 @@ public function testSendData() {
$email->subject('Testing SMTP');
$date = date(DATE_RFC2822);
$email->setHeaders(array('X-Mailer' => SmtpCakeEmail::EMAIL_CLIENT, 'Date' => $date));
$email->expects($this->any())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '')));
$email->expects($this->any())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', '')));

$data = "From: CakePHP Test <noreply@cakephp.org>\r\n";
$data .= "Return-Path: CakePHP Return <pleasereply@cakephp.org>\r\n";
Expand All @@ -237,6 +237,7 @@ public function testSendData() {
$data .= "\r\n";
$data .= "First Line\r\n";
$data .= "Second Line\r\n";
$data .= "..Third Line\r\n"; // RFC5321 4.5.2.Transparency
$data .= "\r\n";
$data .= "\r\n\r\n.\r\n";

Expand Down

0 comments on commit db20600

Please sign in to comment.