/** * Helper to log the email to the database and the file system * * @static * @param Pimcore_Mail $mail */ public static function logEmail(Pimcore_Mail $mail) { $emailLog = new Document_Email_Log(); $document = $mail->getDocument(); if ($document instanceof 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 (!empty($temporaryStorage[$key])) { if (method_exists($emailLog, 'set' . $key)) { $emailLog->{"set{$key}"}(self::formatDebugReceivers($temporaryStorage[$key])); } } } $emailLog->save(); }