/**
  * @param object $to
  * @return array|string
  */
 protected function getRecipient($to)
 {
     if ($to instanceof EmailDestinationInterface) {
         $name = $to->getRecipientName();
         $to = $to->getRecipientEmail();
     } else {
         $name = $this->annotationDriver->getName($to);
         $to = $this->annotationDriver->getEmail($to);
     }
     if (null !== $name && '' !== $name) {
         $to = array($to => $name);
     }
     return $to;
 }
 /**
  * Create a swift message
  *
  * @param EmailInterface $email
  * @param mixed          $to
  * @param array          $parameters
  * @param string         $locale
  *
  * @return \Swift_Message
  */
 public function generateMessage(EmailInterface $email, $to, array $parameters = array(), $locale = null)
 {
     if (null === $locale) {
         $locale = $this->options['default_locale'];
     }
     // Check for annotations
     if (is_object($to)) {
         $name = $this->annotationDriver->getName($to);
         $to = $this->annotationDriver->getEmail($to);
         if (null !== $name && '' !== $name) {
             $to = array($to => $name);
         }
     }
     try {
         $email->setLocale($locale);
         $this->renderer->loadTemplates($email);
         $message = $this->createMessageInstance()->setSubject($this->renderTemplate('subject', $parameters, $email->getChecksum()))->setFrom($this->renderFromAddress($email, $parameters), $this->renderTemplate('from_name', $parameters, $email->getChecksum()))->setTo($to)->setBody($this->renderTemplate('html_content', $parameters, $email->getChecksum()), 'text/html');
         $textContent = $this->renderTemplate('text_content', $parameters, $email->getChecksum());
         if (null !== $textContent && '' !== $textContent) {
             $message->addPart($textContent, 'text/plain');
         }
         foreach ($email->getBccs() as $bcc) {
             $message->addBcc($bcc);
         }
         if (count($email->getHeaders()) > 0) {
             $headers = $message->getHeaders();
             foreach ($email->getHeaders() as $header) {
                 if (is_array($header) && isset($header['key'], $header['value'])) {
                     $headers->addTextHeader($header['key'], $header['value']);
                 }
             }
         }
     } catch (NoTranslationException $e) {
         $message = new NoTranslationMessage($email->getReference(), $locale);
         $message->setFrom($this->options['admin_email']);
         $message->setTo($this->options['admin_email']);
     } catch (\Twig_Error_Runtime $e) {
         $message = new UndefinedVariableMessage($e->getMessage(), $email->getReference());
         $message->setFrom($this->options['admin_email']);
         $message->setTo($this->options['admin_email']);
     } catch (\Twig_Error $e) {
         $message = new TwigErrorMessage($e->getRawMessage(), $email->getReference());
         $message->setFrom($this->options['admin_email']);
         $message->setTo($this->options['admin_email']);
     }
     return $message;
 }