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

Commit

Permalink
[2.4.8] Backport changes from 2.5 series
Browse files Browse the repository at this point in the history
This commit backports changes from the 2.5 series for the 2.4.8 LTS release.
These include the following:

- [#11](#11) ensures that the
  sender can be a mailbox name, or an email specifying a host that omits the
  TLD.
- [#21](#21) provides a patch to
  allow addresses in the form `Name address@domain.tld` (without angle brackets
  surrounding the actual email addres).
- [#24](#24) fixes parsing of
  mail messagse that contain an initial blank line (prior to any headers), a
  situation observed in particular with GMail.
- [#26](#26) fixes the
  `ContentType` header to properly handle parameters with encoded values.
  • Loading branch information
weierophinney committed Sep 10, 2015
1 parent 0d4f368 commit 393b43c
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 126 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,6 +9,7 @@ nbproject
tmp/

clover.xml
composer.lock
coveralls-upload.json
phpunit.xml
vendor
28 changes: 28 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,28 @@
# Changelog

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.4.8 - 2015-09-10

### Added

- Nothing.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- [#26](https://github.com/zendframework/zend-mail/pull/26) fixes the
`ContentType` header to properly handle parameters with encoded values.
- [#11](https://github.com/zendframework/zend-mail/pull/11) fixes the
behavior of the `Sender` header, ensuring it can handle domains that do not
contain a TLD, as well as addresses referencing mailboxes (no domain).
- [#24](https://github.com/zendframework/zend-mail/pull/24) fixes parsing of
mail messages that contain an initial blank line (prior to the headers), a
situation observed in particular with GMail.
17 changes: 9 additions & 8 deletions composer.json
Expand Up @@ -14,17 +14,18 @@
},
"require": {
"php": ">=5.3.23",
"zendframework/zend-crypt": "self.version",
"zendframework/zend-loader": "self.version",
"zendframework/zend-mime": "self.version",
"zendframework/zend-stdlib": "self.version",
"zendframework/zend-validator": "self.version"
"zendframework/zend-crypt": "~2.4.0",
"zendframework/zend-loader": "~2.4.0",
"zendframework/zend-mime": "~2.4.0",
"zendframework/zend-stdlib": "~2.4.0",
"zendframework/zend-validator": "~2.4.0"
},
"require-dev": {
"zendframework/zend-servicemanager": "self.version",
"zendframework/zend-servicemanager": "~2.4.0",
"fabpot/php-cs-fixer": "1.7.*",
"satooshi/php-coveralls": "dev-master",
"phpunit/PHPUnit": "~4.0"
"phpunit/PHPUnit": "~4.0",
"zendframework/zend-config": "~2.4.0"
},
"suggest": {
"zendframework/zend-servicemanager": "Zend\\ServiceManager component"
Expand All @@ -40,4 +41,4 @@
"ZendTest\\Mail\\": "test/"
}
}
}
}
28 changes: 22 additions & 6 deletions src/Header/ContentType.php
Expand Up @@ -10,14 +10,22 @@
namespace Zend\Mail\Header;

use Zend\Mail\Headers;
use Zend\Mime\Mime;

class ContentType implements HeaderInterface
class ContentType implements UnstructuredInterface
{
/**
* @var string
*/
protected $type;

/**
* Header encoding
*
* @var string
*/
protected $encoding = 'ASCII';

/**
* @var array
*/
Expand Down Expand Up @@ -66,6 +74,12 @@ public function getFieldValue($format = HeaderInterface::FORMAT_RAW)

$values = array($prepared);
foreach ($this->parameters as $attribute => $value) {
if (HeaderInterface::FORMAT_ENCODED === $format && !Mime::isPrintable($value)) {
$this->encoding = 'UTF-8';
$value = HeaderWrap::wrap($value, $this);
$this->encoding = 'ASCII';
}

$values[] = sprintf('%s="%s"', $attribute, $value);
}

Expand All @@ -74,18 +88,18 @@ public function getFieldValue($format = HeaderInterface::FORMAT_RAW)

public function setEncoding($encoding)
{
// This header must be always in US-ASCII
$this->encoding = $encoding;
return $this;
}

public function getEncoding()
{
return 'ASCII';
return $this->encoding;
}

public function toString()
{
return 'Content-Type: ' . $this->getFieldValue();
return 'Content-Type: ' . $this->getFieldValue(HeaderInterface::FORMAT_ENCODED);
}

/**
Expand Down Expand Up @@ -135,8 +149,10 @@ public function addParameter($name, $value)
if (! HeaderValue::isValid($name)) {
throw new Exception\InvalidArgumentException('Invalid content-type parameter name detected');
}
if (! HeaderValue::isValid($value)) {
throw new Exception\InvalidArgumentException('Invalid content-type parameter value detected');
if (! HeaderWrap::canBeEncoded($value)) {
throw new Exception\InvalidArgumentException(
'Parameter value must be composed of printable US-ASCII or UTF-8 characters.'
);
}

$this->parameters[$name] = $value;
Expand Down
2 changes: 2 additions & 0 deletions src/Header/Sender.php
Expand Up @@ -53,6 +53,8 @@ public static function fromString($headerLine)
$senderName = null;
}
$senderEmail = $matches['email'];
} else {
$senderEmail = $value;
}

$header->setAddress($senderEmail, $senderName);
Expand Down
6 changes: 6 additions & 0 deletions src/Message.php
Expand Up @@ -517,6 +517,12 @@ protected function updateAddressList(AddressList $addressList, $emailOrAddressOr
(is_object($emailOrAddressOrList) ? get_class($emailOrAddressOrList) : gettype($emailOrAddressOrList))
));
}

if (is_string($emailOrAddressOrList) && $name === null) {
$addressList->addFromString($emailOrAddressOrList);
return;
}

$addressList->add($emailOrAddressOrList, $name);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Storage/Message.php
Expand Up @@ -42,6 +42,8 @@ public function __construct(array $params)
} else {
$params['raw'] = stream_get_contents($params['file']);
}

$params['raw'] = ltrim($params['raw']);
}

if (!empty($params['flags'])) {
Expand Down

0 comments on commit 393b43c

Please sign in to comment.