Permalink
Browse files

Using Return-Path email address in MAIL FROM instead of a header in S…

…mtpTransport.

The Return-Path header should not be present on the SMTP transaction, this header is set by the time of final delivery.
Quote RFC2821:
> When the delivery SMTP server makes the "final delivery" of a message, it inserts a return-path line at the beginning of the mail data. This use of return-path is required; mail systems MUST support it. The return-path line preserves the information in the from the MAIL command.
  • Loading branch information...
1 parent bbcc7b2 commit 796e4b45dd092c7eb1a0ab128280578523191ef3 @renan renan committed Jun 12, 2013
Showing with 27 additions and 3 deletions.
  1. +5 −2 lib/Cake/Network/Email/SmtpTransport.php
  2. +22 −1 lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php
@@ -161,7 +161,10 @@ protected function _auth() {
* @throws SocketException
*/
protected function _sendRcpt() {
- $from = $this->_cakeEmail->from();
+ $from = $this->_cakeEmail->returnPath();
+ if (empty($from)) {
+ $from = $this->_cakeEmail->from();
+ }
$this->_smtpSend('MAIL FROM:<' . key($from) . '>');
$to = $this->_cakeEmail->to();
@@ -182,7 +185,7 @@ protected function _sendRcpt() {
protected function _sendData() {
$this->_smtpSend('DATA', '354');
- $headers = $this->_cakeEmail->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'subject'));
+ $headers = $this->_cakeEmail->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'to', 'cc', 'subject'));
$headers = $this->_headersToString($headers);
$lines = $this->_cakeEmail->message();
$messages = array();
@@ -271,6 +271,28 @@ public function testRcpt() {
}
/**
+ * testRcptWithReturnPath method
+ *
+ * @return void
+ */
+ public function testRcptWithReturnPath() {
+ $email = new CakeEmail();
+ $email->from('noreply@cakephp.org', 'CakePHP Test');
+ $email->to('cake@cakephp.org', 'CakePHP');
+ $email->returnPath('pleasereply@cakephp.org', 'CakePHP Return');
+
+ $this->socket->expects($this->at(0))->method('write')->with("MAIL FROM:<pleasereply@cakephp.org>\r\n");
+ $this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
+ $this->socket->expects($this->at(2))->method('read')->will($this->returnValue("250 OK\r\n"));
+ $this->socket->expects($this->at(3))->method('write')->with("RCPT TO:<cake@cakephp.org>\r\n");
+ $this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
+ $this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n"));
+
+ $this->SmtpTransport->setCakeEmail($email);
+ $this->SmtpTransport->sendRcpt();
+ }
+
+/**
* testSendData method
*
* @return void
@@ -290,7 +312,6 @@ public function testSendData() {
$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";
$data .= "To: CakePHP <cake@cakephp.org>\r\n";
$data .= "Cc: Mark Story <mark@cakephp.org>, Juan Basso <juan@cakephp.org>\r\n";
$data .= "X-Mailer: CakePHP Email\r\n";

0 comments on commit 796e4b4

Please sign in to comment.