Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/93'
Browse files Browse the repository at this point in the history
Close #93
  • Loading branch information
weierophinney committed Feb 14, 2017
2 parents 0ac2d12 + 373fea7 commit 756fe45
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#93](https://github.com/zendframework/zend-mail/pull/93) fixes a situation
whereby `getSender()` was unintentionally creating a blank `Sender` header,
instead of returning `null` if none exists, fixing an issue in the SMTP
transport.

## 2.7.2 - 2016-12-19

Expand Down
4 changes: 4 additions & 0 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ public function setSender($emailOrAddress, $name = null)
*/
public function getSender()
{
$headers = $this->getHeaders();
if (! $headers->has('sender')) {
return null;
}
$header = $this->getHeaderByName('sender', __NAMESPACE__ . '\Header\Sender');
return $header->getAddress();
}
Expand Down
7 changes: 7 additions & 0 deletions test/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ public function testSenderIsNullByDefault()
$this->assertNull($this->message->getSender());
}

public function testNullSenderDoesNotCreateHeader()
{
$sender = $this->message->getSender();
$headers = $this->message->getHeaders();
$this->assertFalse($headers->has('sender'));
}

public function testSettingSenderCreatesAddressObject()
{
$this->message->setSender('zf-devteam@example.com');
Expand Down
64 changes: 44 additions & 20 deletions test/Transport/SmtpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,21 @@ public function setUp()
public function getMessage()
{
$message = new Message();
$message->addTo('zf-devteam@zend.com', 'ZF DevTeam')
->addCc('matthew@zend.com')
->addBcc('zf-crteam@lists.zend.com', 'CR-Team, ZF Project')
->addFrom([
'zf-devteam@zend.com',
'matthew@zend.com' => 'Matthew',
])
->setSender('ralph.schindler@zend.com', 'Ralph Schindler')
->setSubject('Testing Zend\Mail\Transport\Sendmail')
->setBody('This is only a test.');
$message->addTo('zf-devteam@zend.com', 'ZF DevTeam');
$message->addCc('matthew@zend.com');
$message->addBcc('zf-crteam@lists.zend.com', 'CR-Team, ZF Project');
$message->addFrom([
'zf-devteam@zend.com',
'matthew@zend.com' => 'Matthew',
]);
$message->setSender('ralph.schindler@zend.com', 'Ralph Schindler');
$message->setSubject('Testing Zend\Mail\Transport\Sendmail');
$message->setBody('This is only a test.');

$message->getHeaders()->addHeaders([
'X-Foo-Bar' => 'Matthew',
]);

return $message;
}

Expand Down Expand Up @@ -135,18 +137,40 @@ public function testSendMinimalMail()
{
$headers = new Headers();
$headers->addHeaderLine('Date', 'Sun, 10 Jun 2012 20:07:24 +0200');

$message = new Message();
$message->setHeaders($headers);
$message->setSender('ralph.schindler@zend.com', 'Ralph Schindler');
$message->setBody('testSendMailWithoutMinimalHeaders');
$message->addTo('zf-devteam@zend.com', 'ZF DevTeam');

$expectedMessage = "Date: Sun, 10 Jun 2012 20:07:24 +0200\r\n"
. "Sender: Ralph Schindler <ralph.schindler@zend.com>\r\n"
. "To: ZF DevTeam <zf-devteam@zend.com>\r\n"
. "\r\n"
. "testSendMailWithoutMinimalHeaders";

$this->transport->send($message);

$this->assertContains($expectedMessage, $this->connection->getLog());
}

public function testSendMinimalMailWithoutSender()
{
$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')
->addTo('zf-devteam@zend.com', 'ZF DevTeam')
;
$message->setHeaders($headers);
$message->setFrom('ralph.schindler@zend.com', 'Ralph Schindler');
$message->setBody('testSendMinimalMailWithoutSender');
$message->addTo('zf-devteam@zend.com', 'ZF DevTeam');

$expectedMessage = "Date: Sun, 10 Jun 2012 20:07:24 +0200\r\n"
. "Sender: Ralph Schindler <ralph.schindler@zend.com>\r\n"
. "To: ZF DevTeam <zf-devteam@zend.com>\r\n"
. "\r\n"
. "testSendMailWithoutMinimalHeaders";
. "From: Ralph Schindler <ralph.schindler@zend.com>\r\n"
. "To: ZF DevTeam <zf-devteam@zend.com>\r\n"
. "\r\n"
. "testSendMinimalMailWithoutSender";

$this->transport->send($message);

Expand Down

0 comments on commit 756fe45

Please sign in to comment.