Using Return-Path email address in MAIL FROM instead of a header in SmtpTransport.

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.
This commit is contained in:
Renan Gonçalves 2013-06-12 11:31:49 +02:00
parent bbcc7b2335
commit 796e4b45dd
2 changed files with 27 additions and 3 deletions

View file

@ -161,7 +161,10 @@ class SmtpTransport extends AbstractTransport {
* @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 @@ class SmtpTransport extends AbstractTransport {
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();

View file

@ -270,6 +270,28 @@ class SmtpTransportTest extends CakeTestCase {
$this->SmtpTransport->sendRcpt();
}
/**
* 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
*
@ -290,7 +312,6 @@ class SmtpTransportTest extends CakeTestCase {
$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";