Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[Mail] Avoid render To: and Cc: headers if doesn't have addresses

  • Loading branch information...
commit 7fd63f7c8b189d6465e18123b5da65f1d65e1932 1 parent c1273a4
@Maks3w authored
View
17 library/Zend/Mail/Transport/Smtp.php
@@ -305,8 +305,21 @@ protected function prepareHeaders(Mail\Message $message)
{
$headers = new Headers();
foreach ($message->headers() as $header) {
- if ('Bcc' == $header->getFieldName()) {
- continue;
+ switch ($header->getFieldName()) {
+ case 'To':
+ if (0 == $header->getAddressList()->count()) {
+ continue 2;
+ }
+ break;
+ case 'Cc':
+ if (0 == $header->getAddressList()->count()) {
+ continue 2;
+ }
+ break;
+ case 'Bcc':
+ continue 2;
+ // break omitted
+ default:
}
$headers->addHeader($header);
}
View
33 tests/Zend/Mail/Transport/SmtpTest.php
@@ -21,7 +21,8 @@
namespace ZendTest\Mail\Transport;
-use Zend\Mail\Message,
+use Zend\Mail\Headers,
+ Zend\Mail\Message,
Zend\Mail\Transport\Smtp,
Zend\Mail\Transport\SmtpOptions,
ZendTest\Mail\TestAsset\SmtpProtocolSpy;
@@ -36,7 +37,9 @@
*/
class SmtpTest extends \PHPUnit_Framework_TestCase
{
+ /** @var Smtp */
public $transport;
+ /** @var SmtpProtocolSpy */
public $connection;
public function setUp()
@@ -65,6 +68,34 @@ public function getMessage()
return $message;
}
+ public function testSendMailWithoutMinimalHeaders() {
+ $this->setExpectedException(
+ 'Zend\Mail\Transport\Exception\RuntimeException',
+ 'transport expects either a Sender or at least one From address in the Message; none provided'
+ );
+ $message = new Message();
+ $message->setBody('testSendMailWithoutMinimalHeaders');
+ $this->transport->send($message);
+ }
+
+ public function testSendMinimalMail() {
+ $headers = new Headers();
+ $headers->addHeaderLine('Date', 'Sun, 10 Jun 2012 20:07:24 +0200');
+ $message = new Message();
+ $message
+ ->setHeaders($headers)
+ ->setSender('ralph.schindler@zend.com', 'Ralph Schindler')
+ ->setBody('testSendMailWithoutMinimalHeaders')
+ ;
+ $expectedMessage = "Date: Sun, 10 Jun 2012 20:07:24 +0200\r\n"
+ . "Sender: Ralph Schindler <ralph.schindler@zend.com>\r\n"
+ . "\r\ntestSendMailWithoutMinimalHeaders";
+
+ $this->transport->send($message);
+
+ $this->assertSame($expectedMessage, $this->connection->getData());
+ }
+
public function testReceivesMailArtifacts()
{
$message = $this->getMessage();
Please sign in to comment.
Something went wrong with that request. Please try again.