Exemplo n.º 1
0
 /**
  * @param MailClient $mail
  * @return Model\Tool\Email\Log
  */
 public static function logEmail(MailClient $mail)
 {
     $emailLog = new Model\Tool\Email\Log();
     $document = $mail->getDocument();
     if ($document instanceof Model\Document) {
         $emailLog->setDocumentId($document->getId());
     }
     $emailLog->setRequestUri(htmlspecialchars($_SERVER['REQUEST_URI']));
     $emailLog->setParams($mail->getParams());
     $emailLog->setSubject($mail->getSubject());
     $emailLog->setSentDate(time());
     $mailFrom = $mail->getFrom();
     if ($mailFrom) {
         $emailLog->setFrom($mailFrom);
     } else {
         $defaultFrom = $mail->getDefaultFrom();
         $tmpString = $defaultFrom['email'];
         if ($defaultFrom['name']) {
             $tmpString .= " (" . $defaultFrom["name"] . ")";
         }
         $emailLog->setFrom($tmpString);
     }
     $html = $mail->getBodyHtml();
     if ($html instanceof \Zend_Mime_Part) {
         $emailLog->setBodyHtml($html->getRawContent());
     }
     $text = $mail->getBodyText();
     if ($text instanceof \Zend_Mime_Part) {
         $emailLog->setBodyText($text->getRawContent());
     }
     $temporaryStorage = $mail->getTemporaryStorage();
     foreach (array('To', 'Cc', 'Bcc') as $key) {
         if (isset($temporaryStorage[$key]) && is_array($temporaryStorage[$key])) {
             if (method_exists($emailLog, 'set' . $key)) {
                 $emailLog->{"set{$key}"}(self::formatDebugReceivers($temporaryStorage[$key]));
             }
         }
     }
     $emailLog->save();
     return $emailLog;
 }