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

Mail\Message::getSubject() should return value the way it was set #2334

Merged
merged 2 commits into from Sep 13, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/Zend/Mail/Message.php
Expand Up @@ -354,7 +354,7 @@ public function getSubject()
return null;
}
$header = $headers->get('subject');
return $header->getFieldValue(Header\HeaderInterface::FORMAT_ENCODED);
return $header->getFieldValue();
}

/**
Expand Down
7 changes: 6 additions & 1 deletion library/Zend/Mail/Transport/Sendmail.php
Expand Up @@ -179,7 +179,12 @@ protected function prepareRecipients(Mail\Message $message)
*/
protected function prepareSubject(Mail\Message $message)
{
return $message->getSubject();
$headers = $message->getHeaders();
if (!$headers->has('subject')) {
return null;
}
$header = $headers->get('subject');
return $header->getFieldValue(HeaderInterface::FORMAT_ENCODED);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also be done for SMTP and/or File transports? or is it an issue only for the Sendmail transport?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Message::getSubject() was used only in sendmail.
I will check if getters for other properties proxied to Headers are used in transports and replace them with direct access too.

}

/**
Expand Down
7 changes: 7 additions & 0 deletions tests/ZendTest/Mail/MessageTest.php
Expand Up @@ -602,6 +602,13 @@ public function testEncodingIsMutable()
$this->assertEquals('UTF-8', $this->message->getEncoding());
}

public function testMessageReturnsNonEncodedSubject()
{
$this->message->setSubject('This is a subject');
$this->message->setEncoding('UTF-8');
$this->assertEquals('This is a subject', $this->message->getSubject());
}

public function testSettingNonAsciiEncodingForcesMimeEncodingOfSomeHeaders()
{
$this->message->addTo('zf-devteam@zend.com', 'ZF DevTeam');
Expand Down
8 changes: 8 additions & 0 deletions tests/ZendTest/Mail/Transport/SendmailTest.php
Expand Up @@ -124,4 +124,12 @@ public function testLinesStartingWithFullStopsArePreparedProperlyForWindows()
$this->transport->send($message);
$this->assertContains("line.\n.. This", trim($this->message));
}

public function testAssertSubjectEncoded()
{
$message = $this->getMessage();
$message->setEncoding('UTF-8');
$this->transport->send($message);
$this->assertEquals('=?UTF-8?Q?Testing=20Zend\Mail\Transport\Sendmail?=', $this->subject);
}
}