Skip to content

Commit 24c09ff

Browse files
committed
Merge branch 'patch-1' of https://github.com/glensc/zend-mail into glensc-patch-1
2 parents 6d1b788 + c9fb65b commit 24c09ff

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

src/Headers.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,11 @@ public function toString()
430430
/**
431431
* Return the headers container as an array
432432
*
433-
* @todo determine how to produce single line headers, if they are supported
433+
* @param bool $format Return the values in Mime::Encoded or in Raw format
434434
* @return array
435+
* @todo determine how to produce single line headers, if they are supported
435436
*/
436-
public function toArray()
437+
public function toArray($format = Header\HeaderInterface::FORMAT_RAW)
437438
{
438439
$headers = [];
439440
/* @var $header Header\HeaderInterface */
@@ -443,9 +444,9 @@ public function toArray()
443444
if (!isset($headers[$name])) {
444445
$headers[$name] = [];
445446
}
446-
$headers[$name][] = $header->getFieldValue();
447+
$headers[$name][] = $header->getFieldValue($format);
447448
} else {
448-
$headers[$header->getFieldName()] = $header->getFieldValue();
449+
$headers[$header->getFieldName()] = $header->getFieldValue($format);
449450
}
450451
}
451452
return $headers;

test/HeadersTest.php

+37
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,43 @@ public function testCastingToStringReturnsAllMultiHeaderValues()
309309
$this->assertEquals($expected, $string);
310310
}
311311

312+
/**
313+
* @test that toArray can take format parameter
314+
* @link https://github.com/zendframework/zend-mail/pull/61
315+
*/
316+
public function testToArrayFormatRaw()
317+
{
318+
$raw_subject = '=?ISO-8859-2?Q?PD=3A_My=3A_Go=B3?= =?ISO-8859-2?Q?blahblah?=';
319+
$headers = new Mail\Headers();
320+
$subject = Header\Subject::fromString("Subject: $raw_subject");
321+
$headers->addHeader($subject);
322+
// default
323+
$array = $headers->toArray(Header\HeaderInterface::FORMAT_RAW);
324+
$expected = [
325+
'Subject' => 'PD: My: Gołblahblah',
326+
];
327+
$this->assertEquals($expected, $array);
328+
}
329+
330+
/**
331+
* @test that toArray can take format parameter
332+
* @link https://github.com/zendframework/zend-mail/pull/61
333+
*/
334+
public function testToArrayFormatEncoded()
335+
{
336+
$raw_subject = '=?ISO-8859-2?Q?PD=3A_My=3A_Go=B3?= =?ISO-8859-2?Q?blahblah?=';
337+
$headers = new Mail\Headers();
338+
$subject = Header\Subject::fromString("Subject: $raw_subject");
339+
$headers->addHeader($subject);
340+
341+
// encoded
342+
$array = $headers->toArray(Header\HeaderInterface::FORMAT_ENCODED);
343+
$expected = [
344+
'Subject' => '=?UTF-8?Q?PD:=20My:=20Go=C5=82blahblah?=',
345+
];
346+
$this->assertEquals($expected, $array);
347+
}
348+
312349
public static function expectedHeaders()
313350
{
314351
return [

0 commit comments

Comments
 (0)