/** * * @param Message $message * @return ZendMessage */ public static function convert(Message $message) { $mailMessage = new ZendMessage(); $mailMessage->setSubject($message->getSubject()); $mailMessage->setFrom($message->getFrom()); $mailMessage->setTo($message->getTo()); $mailMessage->setCc($message->getCc()); $mailMessage->setBcc($message->getBcc()); $mailMessage->setReplyTo($message->getReplyTo()); $mailMessage->getHeaders()->addHeaders($message->getHeaders()); if ($mailMessage->getSender()) { $mailMessage->setSender($message->getSender()); } if ($message->isMultipart()) { $mimePart = new MimeMessage(); if ($message->getBodyHtml()) { $part = new Part($message->getBodyHtml()); $part->charset = $message->getCharset(); $part->encoding = $message->getEncoding(); $part->type = Mime::TYPE_HTML; $mimePart->addPart($part); } if ($message->getBodyText()) { $part = new Part($message->getBodyText()); $part->charset = $message->getCharset(); $part->encoding = $message->getEncoding(); $part->type = Mime::TYPE_TEXT; $mimePart->addPart($part); } foreach ($message->getAttachments() as $attachment) { $mimePart->addPart($attachment->asMimePart()); } foreach ($message->getParts() as $part) { $mimePart->addPart($part); } $mailMessage->setBody($mimePart); } else { $mailMessage->getHeaders()->addHeaderLine('Content-Type', $message->getContentType()); $mailMessage->setEncoding($message->getEncoding()); $mailMessage->setBody($message->getFilledBody()); } return $mailMessage; }
/** * @covers \ZfExtra\Mail\Message::getBody * @covers \ZfExtra\Mail\Message::setBodyHtml * @covers \ZfExtra\Mail\Message::getBodyHtml * @covers \ZfExtra\Mail\Message::setBodyText * @covers \ZfExtra\Mail\Message::getBodyText */ public function testSetBody() { $message = new Message(); $message->setBody('html', Mime::TYPE_HTML); $this->assertEquals('html', $message->getBody(Mime::TYPE_HTML)); $message->setBody('text', Mime::TYPE_TEXT); $this->assertEquals('text', $message->getBody(Mime::TYPE_TEXT)); $message->setBodyHtml('body html'); $this->assertEquals('body html', $message->getBodyHtml()); $message->setBodyText('body text'); $this->assertEquals('body text', $message->getBodyText()); }