Permalink
Browse files

Add fromString() to restore mail message from string

  • Loading branch information...
1 parent bcc6ee9 commit 13d47e5b93db0bd6aa148279111f5b95b3cea9ac @Xerkus Xerkus committed Sep 9, 2012
Showing with 30 additions and 0 deletions.
  1. +16 −0 library/Zend/Mail/Message.php
  2. +14 −0 tests/ZendTest/Mail/MessageTest.php
@@ -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;
+ }
}
@@ -647,4 +647,18 @@ public function testDefaultDateHeaderEncodingIsAlwaysAscii()
$test = substr($test, 0, 16);
$this->assertEquals($date, $test);
}
+
+ public function testRestoreFromSerializedString()
+ {
+ $this->message->addTo('zf-devteam@zend.com', 'ZF DevTeam');
+ $this->message->addFrom('matthew@zend.com', "Matthew Weier O'Phinney");
+ $this->message->addCc('zf-contributors@lists.zend.com', '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.