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

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 36 changed files with 539 additions and 851 deletions.
14 changes: 0 additions & 14 deletions .travis/run-tests.sh

This file was deleted.

7 changes: 0 additions & 7 deletions .travis/skipped-components

This file was deleted.

61 changes: 0 additions & 61 deletions .travis/tested-components

This file was deleted.

6 changes: 3 additions & 3 deletions src/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct($email, $name = null)

/**
* Retrieve email
*
*
* @return string
*/
public function getEmail()
Expand All @@ -64,7 +64,7 @@ public function getEmail()

/**
* Retrieve name
*
*
* @return string
*/
public function getName()
Expand All @@ -74,7 +74,7 @@ public function getName()

/**
* String representation of address
*
*
* @return string
*/
public function toString()
Expand Down
34 changes: 17 additions & 17 deletions src/AddressList.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AddressList implements Countable, Iterator
{
/**
* List of Address objects we're managing
*
*
* @var array
*/
protected $addresses = array();
Expand Down Expand Up @@ -97,9 +97,9 @@ public function addMany(array $addresses)
}

/**
* Merge another address list into this one
*
* @param AddressList $addressList
* Merge another address list into this one
*
* @param AddressList $addressList
* @return AddressList
*/
public function merge(AddressList $addressList)
Expand All @@ -112,8 +112,8 @@ public function merge(AddressList $addressList)

/**
* Does the email exist in this list?
*
* @param string $email
*
* @param string $email
* @return bool
*/
public function has($email)
Expand All @@ -124,8 +124,8 @@ public function has($email)

/**
* Get an address by email
*
* @param string $email
*
* @param string $email
* @return boolean|Address\AddressInterface
*/
public function get($email)
Expand All @@ -140,7 +140,7 @@ public function get($email)

/**
* Delete an address from the list
*
*
* @param string $email
* @return bool
*/
Expand All @@ -157,7 +157,7 @@ public function delete($email)

/**
* Return count of addresses
*
*
* @return int
*/
public function count()
Expand All @@ -179,7 +179,7 @@ public function rewind()

/**
* Return current item in iteration
*
*
* @return Address
*/
public function current()
Expand All @@ -189,7 +189,7 @@ public function current()

/**
* Return key of current item of iteration
*
*
* @return string
*/
public function key()
Expand All @@ -211,7 +211,7 @@ public function next()

/**
* Is the current item of iteration valid?
*
*
* @return bool
*/
public function valid()
Expand All @@ -221,10 +221,10 @@ public function valid()
}

/**
* Create an address object
*
* @param string $email
* @param string|null $name
* Create an address object
*
* @param string $email
* @param string|null $name
* @return Address
*/
protected function createAddress($email, $name)
Expand Down
59 changes: 13 additions & 46 deletions src/Header/AbstractAddressList.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,15 @@ abstract class AbstractAddressList implements HeaderInterface
protected $encoding = 'ASCII';

/**
* @var string lowercased field name
* @var string lower case field name
*/
protected static $type;

/**
* Parse string to create header object
*
* @param string $headerLine
* @throws Exception\InvalidArgumentException
* @return AbstractAddressList
*/
public static function fromString($headerLine)
{
$headerLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);

$decodedLine = iconv_mime_decode($headerLine, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8');
// split into name/value
list($fieldName, $fieldValue) = explode(': ', $headerLine, 2);
list($fieldName, $fieldValue) = explode(': ', $decodedLine, 2);

if (strtolower($fieldName) !== static::$type) {
throw new Exception\InvalidArgumentException(sprintf(
Expand All @@ -78,7 +70,9 @@ public static function fromString($headerLine)
));
}
$header = new static();

if ($decodedLine != $headerLine) {
$header->setEncoding('UTF-8');
}
// split value on ","
$fieldValue = str_replace(Headers::FOLDING, ' ', $fieldValue);
$values = explode(',', $fieldValue);
Expand All @@ -97,8 +91,6 @@ public static function fromString($headerLine)
}
if (empty($name)) {
$name = null;
} else {
$name = iconv_mime_decode($name, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
}

if (isset($matches['namedEmail'])) {
Expand All @@ -112,26 +104,15 @@ public static function fromString($headerLine)
// populate address list
$addressList->add($email, $name);
}

return $header;
}

/**
* Get field name of this header
*
* @return string
*/
public function getFieldName()
{
return $this->fieldName;
}

/**
* Get field value of this header
*
* @return string
*/
public function getFieldValue()
public function getFieldValue($format = HeaderInterface::FORMAT_RAW)
{
$emails = array();
$encoding = $this->getEncoding();
Expand All @@ -145,33 +126,24 @@ public function getFieldValue()
$name = sprintf('"%s"', $name);
}

if ('ASCII' !== $encoding) {
if ($format == HeaderInterface::FORMAT_ENCODED
&& 'ASCII' !== $encoding
) {
$name = HeaderWrap::mimeEncodeValue($name, $encoding);
}
$emails[] = sprintf('%s <%s>', $name, $email);
}
}
$string = implode(',' . Headers::FOLDING, $emails);
return $string;

return implode(',' . Headers::FOLDING, $emails);
}

/**
* Set header encoding
*
* @param string $encoding
* @return AbstractAddressList
*/
public function setEncoding($encoding)
{
$this->encoding = $encoding;
return $this;
}

/**
* Get header encoding
*
* @return string
*/
public function getEncoding()
{
return $this->encoding;
Expand Down Expand Up @@ -200,15 +172,10 @@ public function getAddressList()
return $this->addressList;
}

/**
* Serialize to string
*
* @return string
*/
public function toString()
{
$name = $this->getFieldName();
$value = $this->getFieldValue();
$value = $this->getFieldValue(HeaderInterface::FORMAT_ENCODED);
return (empty($value)) ? '' : sprintf('%s: %s', $name, $value);
}
}
Loading

0 comments on commit 5cbe79f

Please sign in to comment.