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

Commit

Permalink
Merge branch 'hotfix/36'
Browse files Browse the repository at this point in the history
Close #36
  • Loading branch information
michalbundyra committed Oct 16, 2019
2 parents 58879a7 + c103b28 commit 589c103
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#36](https://github.com/zendframework/zend-mime/pull/36) fixes
`Zend\Mime\Decode::splitMessage` to set `Zend\Mail\Headers`
instance always for `$headers` parameter. Before, when messages
without headers was provided, `$headers` was an empty array.

## 2.7.1 - 2018-05-14

Expand Down
2 changes: 1 addition & 1 deletion src/Decode.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static function splitMessage($message, &$headers, &$body, $EOL = Mime::LI
$firstlinePos = strpos($message, "\n");
$firstline = $firstlinePos === false ? $message : substr($message, 0, $firstlinePos);
if (! preg_match('%^[^\s]+[^:]*:%', $firstline)) {
$headers = [];
$headers = new Headers();
// TODO: we're ignoring \r for now - is this function fast enough and is it safe to assume noone needs \r?
$body = str_replace(["\r", "\n"], ['', $EOL], $message);
return;
Expand Down
25 changes: 25 additions & 0 deletions test/DecodeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* @see https://github.com/zendframework/zend-mime for the canonical source repository
* @copyright Copyright (c) 2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-mime/blob/master/LICENSE.md New BSD License
*/

namespace ZendTest\Mime;

use PHPUnit\Framework\TestCase;
use Zend\Mail\Headers;
use Zend\Mime\Decode;

class DecodeTest extends TestCase
{
public function testDecodeMessageWithoutHeaders()
{
$text = 'This is a message body';

Decode::splitMessage($text, $headers, $body);

self::assertInstanceOf(Headers::class, $headers);
self::assertSame($text, $body);
}
}

0 comments on commit 589c103

Please sign in to comment.