Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,11 @@ public function addHeaderLine($headerFieldNameOrLine, $fieldValue = null)
}

if ($fieldValue === null) {
$this->addHeader(Header\GenericHeader::fromString($headerFieldNameOrLine));
$headers = $this->loadHeader($headerFieldNameOrLine);
$headers = is_array($headers) ? $headers : [$headers];
foreach ($headers as $header) {
$this->addHeader($header);
}
} elseif (is_array($fieldValue)) {
foreach ($fieldValue as $i) {
$this->addHeader(Header\GenericMultiHeader::fromString($headerFieldNameOrLine . ':' . $i));
Expand Down Expand Up @@ -465,6 +469,21 @@ public function forceLoading()
return true;
}

/**
* Create Header object from header line
*
* @param string $headerLine
* @return \Zend\Mail\Header\HeaderInterface
*/
public function loadHeader($headerLine)
{
list($name, ) = \Zend\Mail\Header\GenericHeader::splitHeaderLine($headerLine);

$class = ($this->getPluginClassLoader()->load($name)) ?: 'Zend\Mail\Header\GenericHeader';

return $class::fromString($headerLine);
}

/**
* @param $index
* @return mixed
Expand Down
16 changes: 14 additions & 2 deletions test/Storage/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

namespace ZendTest\Mail\Storage;

use Zend\Mime;
use Zend\Mime\Exception as MimeException;
use Zend\Mail\Exception as MailException;
use Zend\Mail\Storage;
use Zend\Mail\Storage\Exception;
use Zend\Mail\Storage\Message;
use Zend\Mime;
use Zend\Mime\Exception as MimeException;

/**
* @group Zend_Mail
Expand All @@ -23,10 +23,12 @@
class MessageTest extends \PHPUnit_Framework_TestCase
{
protected $_file;
protected $_file2;

public function setUp()
{
$this->_file = __DIR__ . '/../_files/mail.txt';
$this->_file2 = __DIR__ . '/../_files/mail_multi_to.txt';
}

public function testInvalidFile()
Expand Down Expand Up @@ -430,6 +432,16 @@ public function testStrictParseMessage()
$message = new Message(['raw' => $raw, 'strict' => true]);
}

public function testMultivalueToHeader()
{
$message = new Message(['file' => $this->_file2]);
/** @var \Zend\Mail\Header\To $header */
$header = $message->getHeader('to');
$addressList = $header->getAddressList();
$this->assertEquals(2, $addressList->count());
$this->assertEquals('nicpoń', $addressList->get('bar@example.pl')->getName());
}

public function filesProvider()
{
$filePath = __DIR__ . '/../_files/mail.txt';
Expand Down
11 changes: 11 additions & 0 deletions test/_files/mail_multi_to.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Return-Path: <sender@example.com>
Date: Sun, 01 Jan 2000 00:00:00 +0000
From: sender@example.com
To: =?ISO-8859-2?Q?nicpo=F1?= <bar@example.pl>, "foo" <foo@example.pl>
Subject: Subject text
Content-Type: text/html; charset=iso-8859-2
Content-Transfer-Encoding: 8bit
Content-Disposition: inline

<div>html content</div>