Skip to content

Commit

Permalink
Add fromString() to restore mail message from string
Browse files Browse the repository at this point in the history
  • Loading branch information
Xerkus committed Sep 9, 2012
1 parent bcc6ee9 commit 13d47e5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions library/Zend/Mail/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,4 +535,20 @@ public function toString()
. Headers::EOL
. $this->getBodyText();
}

/**
* Set from serialized string
*
* @param string $rawMessage
* @return Message
*/
public function fromString($rawMessage)
{
$headers = null;
$content = null;
Mime\Decode::splitMessage($rawMessage, $headers, $content);
$this->setHeaders($headers);
$this->setBody($content);
return $this;
}
}
14 changes: 14 additions & 0 deletions tests/ZendTest/Mail/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,4 +647,18 @@ public function testDefaultDateHeaderEncodingIsAlwaysAscii()
$test = substr($test, 0, 16);
$this->assertEquals($date, $test);
}

public function testRestoreFromSerializedString()
{
$this->message->addTo('[email protected]', 'ZF DevTeam');
$this->message->addFrom('[email protected]', "Matthew Weier O'Phinney");
$this->message->addCc('[email protected]', 'ZF Contributors List');
$this->message->setSubject('This is a subject');
$this->message->setBody('foo');

$serialized = $this->message->toString();
$restoredMessage = new Message();
$restoredMessage->fromString($serialized);
$this->assertEquals($serialized, $restoredMessage->toString());
}
}

0 comments on commit 13d47e5

Please sign in to comment.