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

Commit

Permalink
Merge pull request #105 from samsonasik/hotfix/99
Browse files Browse the repository at this point in the history
Fixes #99 : Header value 0 gets discarded in Zend\Mail
  • Loading branch information
weierophinney committed Feb 14, 2017
2 parents 756fe45 + 7399e06 commit 4406f0d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Header/GenericHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __construct($fieldName = null, $fieldValue = null)
$this->setFieldName($fieldName);
}

if ($fieldValue) {
if ($fieldValue !== null) {
$this->setFieldValue($fieldValue);
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/Header/GenericHeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,11 @@ public function testCastingToStringHandlesContinuationsProperly()
$this->assertEquals($encoded, $header->getFieldValue(GenericHeader::FORMAT_ENCODED));
$this->assertEquals('Foo: ' . $encoded, $header->toString());
}

public function testAllowZeroInHeaderValueInConstructor()
{
$header = new GenericHeader('Foo', 0);
$this->assertEquals(0, $header->getFieldValue());
$this->assertEquals('Foo: 0', $header->toString());
}
}
15 changes: 15 additions & 0 deletions test/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -838,4 +838,19 @@ public function testCanParseMultipartReport()
$contentType = $headers->get('Content-Type');
$this->assertEquals('multipart/report', $contentType->getType());
}

public function testMailHeaderContainsZeroValue()
{
$message =
"From: someone@example.com\r\n"
."To: someone@example.com\r\n"
."Subject: plain text email example\r\n"
."X-Spam-Score: 0\r\n"
."X-Some-Value: 1\r\n"
."\r\n"
."I am a test message\r\n";

$msg = Message::fromString($message);
$this->assertContains('X-Spam-Score: 0', $msg->toString());
}
}

0 comments on commit 4406f0d

Please sign in to comment.