/**
  * @inheritDoc
  */
 public static function toWrappedMessage($message, $transport = null)
 {
     if (!$message instanceof Message) {
         throw new MailWrapperSetupException('Invalid Message');
     }
     $wrappedMessage = new MailWrappedMessage();
     $wrappedMessage->setWrappedMessage($message);
     $subject = $message->getSubject();
     $contentHtml = $message->getBody();
     $contentText = $message->getBodyText();
     $toRecipients = $message->getTo();
     $ccRecipients = $message->getCc();
     $bccRecipients = $message->getBcc();
     $from = $message->getFrom()->current();
     $replyTo = $message->getReplyTo()->current();
     $wrappedMessage->setFrom($from);
     $wrappedMessage->setReplyTo($replyTo);
     $wrappedMessage->setSubject($subject);
     $wrappedMessage->setContentText($contentText);
     $wrappedMessage->setContentHtml($contentHtml);
     foreach ($toRecipients as $address) {
         $wrappedMessage->addToRecipient($address->getEmail());
     }
     foreach ($ccRecipients as $address) {
         $wrappedMessage->addCcRecipient($address->getEmail());
     }
     foreach ($bccRecipients as $address) {
         $wrappedMessage->addBccRecipient($address->getEmail());
     }
     return $wrappedMessage;
 }
 /**
  * @return MailWrappedMessage
  */
 public static function getValid()
 {
     $message = new MailWrappedMessage();
     $message->setFrom(MailWrapperTestBootstrap::$from);
     $message->addToRecipient(MailWrapperTestBootstrap::$toAddresses[0]);
     $message->addToRecipient(MailWrapperTestBootstrap::$toAddresses[1]);
     $message->addCcRecipient(MailWrapperTestBootstrap::$ccAddresses[0]);
     $message->addCcRecipient(MailWrapperTestBootstrap::$ccAddresses[1]);
     $message->addBccRecipient(MailWrapperTestBootstrap::$bccAddresses[0]);
     $message->addBccRecipient(MailWrapperTestBootstrap::$bccAddresses[1]);
     $message->setReplyTo(MailWrapperTestBootstrap::$alternate);
     $message->setSubject(MailWrapperTestBootstrap::$subject);
     $message->setContentText(MailWrapperTestBootstrap::$contentText);
     $message->setContentHtml(MailWrapperTestBootstrap::$contentHtml);
     return $message;
 }
 /**
  *
  */
 public function testWrappedReplyTo()
 {
     $wrappedMessage = new MailWrappedMessage();
     $this->assertNull($wrappedMessage->getReplyTo());
     $wrappedMessage->setReplyTo(MailWrapperTestBootstrap::$alternate);
     $this->assertNotNull($wrappedMessage->getReplyTo());
 }
 /**
  * @inheritDoc
  */
 public static function toWrappedMessage($message)
 {
     if (!$message instanceof MessageBuilder) {
         throw new MailWrapperSetupException('Invalid Message');
     }
     $wrappedMessage = new MailWrappedMessage();
     $wrappedMessage->setWrappedMessage($message);
     $mailgunMessageArray = $message->getMessage();
     if (array_key_exists('from', $mailgunMessageArray)) {
         foreach ($mailgunMessageArray['from'] as $address) {
             $wrappedMessage->setFrom($address);
         }
     }
     if (array_key_exists('to', $mailgunMessageArray)) {
         foreach ($mailgunMessageArray['to'] as $address) {
             $wrappedMessage->addToRecipient($address);
         }
     }
     if (array_key_exists('cc', $mailgunMessageArray)) {
         foreach ($mailgunMessageArray['cc'] as $address) {
             $wrappedMessage->addCcRecipient($address);
         }
     }
     if (array_key_exists('bcc', $mailgunMessageArray)) {
         foreach ($mailgunMessageArray['bcc'] as $address) {
             $wrappedMessage->addBccRecipient($address);
         }
     }
     if (array_key_exists('subject', $mailgunMessageArray)) {
         $wrappedMessage->setSubject($mailgunMessageArray['subject']);
     }
     if (array_key_exists('text', $mailgunMessageArray)) {
         $wrappedMessage->setContentText($mailgunMessageArray['text']);
     }
     if (array_key_exists('html', $mailgunMessageArray)) {
         $wrappedMessage->setContentHtml($mailgunMessageArray['html']);
     }
     if (array_key_exists('h:reply-to', $mailgunMessageArray)) {
         $wrappedMessage->setReplyTo($mailgunMessageArray['h:reply-to']);
     }
     return $wrappedMessage;
 }