ZF-8511: Zend_Mail_Protocol_Abstract - truncates server response when SMTP server responds with umultiple line error message

Description

h2. Bug Description

SMTP servers may respond to commands with multi-line responses. A response is not complete until a response message NOT prefixed by '-' is found. However, Zend_Mail_Protocol_Abstract throws an exception before reading the entire response, leading to a truncated error message being included in the exception and the object being left in an unusable state (when it could/should be left usable).

h2. Example multi-line SMTP response to an SMTP RCPT command

550-5.1.1 The email account that you tried to reach does not exist. Please try
550-5.1.1 double-checking the recipient's email address for typos or
550-5.1.1 unnecessary spaces. Learn more at                             
550 5.1.1 http://mail.google.com/support/bin/… xxxxxxxxxx.xx

The _expect() method of Zend_Mail_Protocol_Abstract throws an exception upon encountering the first "550" line rather than reading the entire multi-line response before throwing the exception. This causes two problems:

(1) The exception thrown does not contain the full response from the SMTP server, making troubleshooting and logging difficult, and

(2) If the exception is caught, the protocol adapter remains in an unusable state because there are (in this case) three response lines trapped in the receive buffer. Subsequent attempts to issue commands (an SMTP RSET command, for example) will fail because the next call to _expect() will receive the "550-5.1.1 double-checking the recipient..." line from the buffer which does not make sense.

h2. Code to reproduce


$transport = new Zend_Mail_Transport_Smtp('ASPMX2.GOOGLEMAIL.com');
$mail      = new Zend_Mail;
$mail->setBodyText('foo')
     ->setFrom('foo@bar.com', 'foo')
     ->setSubject('foo')
     ->addTo('nobody@invalid-domain');
try {
    $transport->send($mail);
} catch (Zend_Mail_Protocol_Exception $e) {
    echo $e->getMessage();
}

h2. Expected Output

550-5.1.1 The email account that you tried to reach does not exist. Please try
550-5.1.1 double-checking the recipient's email address for typos or
550-5.1.1 unnecessary spaces. Learn more at                             
550 5.1.1 http://mail.google.com/support/bin/…

h2. Actual output

550-5.1.1 The email account that you tried to reach does not exist. Please try

h2. Solution

See attached patch

Comments

Patch for Zend/Mail/Protocol/Abstract.php

Thank You for report , Marc. I solved this at SVN trunk r19629

Change to next mini. SVN r19916 in 1.9 branch.