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

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing 12 changed files with 42 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/Header/GenericHeader.php
Original file line number Diff line number Diff line change
@@ -37,11 +37,11 @@ class GenericHeader implements HeaderInterface, UnstructuredInterface
public static function fromString($headerLine)
{
$decodedLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8');
$parts = explode(': ', $decodedLine, 2);
$parts = explode(':', $decodedLine, 2);
if (count($parts) != 2) {
throw new Exception\InvalidArgumentException('Header must match with the format "name: value"');
}
$header = new static($parts[0], $parts[1]);
$header = new static($parts[0], ltrim($parts[1]));
if ($decodedLine != $headerLine) {
$header->setEncoding('UTF-8');
}
@@ -140,6 +140,6 @@ public function toString()
$name = $this->getFieldName();
$value = $this->getFieldValue(HeaderInterface::FORMAT_ENCODED);

return $name. ': ' . $value;
return $name . ': ' . $value;
}
}
2 changes: 1 addition & 1 deletion src/Header/GenericMultiHeader.php
Original file line number Diff line number Diff line change
@@ -65,6 +65,6 @@ public function toStringMultipleHeaders(array $headers)
}
$values[] = $header->getFieldValue(HeaderInterface::FORMAT_ENCODED);
}
return $name. ': ' . implode(',', $values);
return $name . ': ' . implode(',', $values);
}
}
1 change: 1 addition & 0 deletions src/Header/MessageId.php
Original file line number Diff line number Diff line change
@@ -69,6 +69,7 @@ public function toString()
/**
* Set the message id
*
* @param string|null $id
* @return MessageId
*/
public function setId($id = null)
2 changes: 1 addition & 1 deletion src/Message.php
Original file line number Diff line number Diff line change
@@ -354,7 +354,7 @@ public function getSubject()
return null;
}
$header = $headers->get('subject');
return $header->getFieldValue(Header\HeaderInterface::FORMAT_ENCODED);
return $header->getFieldValue();
}

/**
2 changes: 1 addition & 1 deletion src/Protocol/Imap.php
Original file line number Diff line number Diff line change
@@ -379,7 +379,7 @@ public function escapeString($string)
public function escapeList($list)
{
$result = array();
foreach ($list as $k => $v) {
foreach ($list as $v) {
if (!is_array($v)) {
// $result[] = $this->escapeString($v);
$result[] = $v;
2 changes: 1 addition & 1 deletion src/Protocol/Smtp.php
Original file line number Diff line number Diff line change
@@ -166,7 +166,7 @@ public function __construct($host = '127.0.0.1', $port = null, array $config = n
*/
public function connect()
{
return $this->_connect($this->transport . '://' . $this->host . ':'. $this->port);
return $this->_connect($this->transport . '://' . $this->host . ':' . $this->port);
}


2 changes: 1 addition & 1 deletion src/Storage/Maildir.php
Original file line number Diff line number Diff line change
@@ -302,7 +302,7 @@ protected function _getMaildirFiles($dh, $dirname, $default_flags = array())

ErrorHandler::start(E_NOTICE);
list($uniq, $info) = explode(':', $entry, 2);
list(,$size) = explode(',', $uniq, 2);
list(, $size) = explode(',', $uniq, 2);
ErrorHandler::stop();
if ($size && $size[0] == 'S' && $size[1] == '=') {
$size = substr($size, 2);
7 changes: 6 additions & 1 deletion src/Transport/Sendmail.php
Original file line number Diff line number Diff line change
@@ -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);
}

/**
1 change: 1 addition & 0 deletions src/Transport/Smtp.php
Original file line number Diff line number Diff line change
@@ -199,6 +199,7 @@ public function disconnect()
* developer to add a custom adapter if required before mail is sent.
*
* @param Message $message
* @throws Exception\RuntimeException
*/
public function send(Message $message)
{
11 changes: 11 additions & 0 deletions test/HeadersTest.php
Original file line number Diff line number Diff line change
@@ -39,6 +39,17 @@ public function testHeadersFromStringFactoryCreatesSingleObject()
$this->assertEquals('foo-bar', $header->getFieldValue());
}

public function testHeadersFromStringFactoryHandlesMissingWhitespace()
{
$headers = Mail\Headers::fromString("Fake:foo-bar");
$this->assertEquals(1, $headers->count());

$header = $headers->get('fake');
$this->assertInstanceOf('Zend\Mail\Header\GenericHeader', $header);
$this->assertEquals('Fake', $header->getFieldName());
$this->assertEquals('foo-bar', $header->getFieldValue());
}

public function testHeadersFromStringFactoryCreatesSingleObjectWithContinuationLine()
{
$headers = Mail\Headers::fromString("Fake: foo-bar,\r\n blah-blah");
7 changes: 7 additions & 0 deletions test/MessageTest.php
Original file line number Diff line number Diff line change
@@ -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');
8 changes: 8 additions & 0 deletions test/Transport/SendmailTest.php
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 66790e4

Please sign in to comment.