Skip to content

Commit

Permalink
Message: From header can be absent (#242)
Browse files Browse the repository at this point in the history
Close #241
  • Loading branch information
Slamdunk committed Oct 12, 2017
2 parents 63d472b + f8b4d15 commit 034d0f9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Message/AbstractMessage.php
Expand Up @@ -26,9 +26,9 @@ final public function getId(): string
/**
* Get message sender (from headers).
*
* @return EmailAddress
* @return null|EmailAddress
*/
final public function getFrom(): EmailAddress
final public function getFrom()
{
return $this->getHeaders()->get('from');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Message/BasicMessageInterface.php
Expand Up @@ -39,9 +39,9 @@ public function getId(): string;
/**
* Get message sender (from headers).
*
* @return EmailAddress
* @return null|EmailAddress
*/
public function getFrom(): EmailAddress;
public function getFrom();

/**
* Get To recipients.
Expand Down
8 changes: 8 additions & 0 deletions tests/MessageTest.php
Expand Up @@ -650,6 +650,14 @@ public function testInlineAttachment()
$this->assertNull($inline->getFilename());
}

public function testMissingFromHeader()
{
$this->mailbox->addMessage($this->getFixture('missing_from'));
$message = $this->mailbox->getMessage(1);

$this->assertNull($message->getFrom());
}

public function testAttachmentMustNotBeCharsetDecoded()
{
$parts = [];
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/missing_from.eml
@@ -0,0 +1,7 @@
To: to@here.com
Subject: Nuu
Date: Wed, 13 Sep 2017 13:05:45 +0200
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hi

0 comments on commit 034d0f9

Please sign in to comment.