diff --git a/src/Message.php b/src/Message.php index e35f623..2906f68 100644 --- a/src/Message.php +++ b/src/Message.php @@ -107,6 +107,9 @@ public function getMime() public function generateMessage($EOL = Mime::LINEEND) { if (!$this->isMultiPart()) { + if (empty($this->parts)) { + return ''; + } $part = current($this->parts); $body = $part->getContent($EOL); } else { diff --git a/test/MessageTest.php b/test/MessageTest.php index d3c60f7..a5ef573 100644 --- a/test/MessageTest.php +++ b/test/MessageTest.php @@ -124,4 +124,15 @@ public function testNonMultipartMessageShouldNotRemovePartFromMessage() $test = current($parts); $this->assertSame($part, $test); } + + /** + * @group ZF2-5962 + */ + public function testPassEmptyArrayIntoSetPartsShouldReturnEmptyString() + { + $mimeMessage = new Mime\Message(); + $mimeMessage->setParts(array()); + + $this->assertEquals('', $mimeMessage->generateMessage()); + } }