/** * * @global <type> $conf * @param <type> $story_part * @param <type> $from * @param <type> $recipients * @param <type> $subject * @param <type> $note * @return <type> */ function _mail($story_part, $from, $recipients, $subject, $note) { throw new Jonah_Exception('Needs refactoring.'); global $conf; /* Create the MIME message. */ $mail = new Horde_Mime_Mail(array('Subject' => $subject, 'To' => $recipients, 'From' => $from, 'User-Agent' => 'Jonah ' . $GLOBALS['registry']->getVersion())); /* If a note has been provided, add it to the message as a text part. */ if (strlen($note) > 0) { $message_note = new MIME_Part('text/plain', null, 'UTF-8'); $message_note->setContents($message_note->replaceEOL($note)); $message_note->setDescription(_("Note")); $mail->addMIMEPart($message_note); } /* Get the story as a MIME part and add it to our message. */ $mail->addMIMEPart($story_part); /* Log the pending outbound message. */ Horde::log(sprintf('<%s> is sending "%s" to (%s)', $from, $subject, $recipients), 'INFO'); /* Send the message and return the result. */ return $mail->send(Horde::getMailerConfig()); }
/** * Returns the provided story as a MIME part. * * @param array $story A data array representing a story. * * @return MIME_Part The MIME message part containing the story parts. * @TODO: Refactor to use new Horde MIME library */ protected function getStoryAsMessage($story) { require_once 'Horde/MIME/Part.php'; /* Add the story to the message based on the story's body type. */ switch ($story['body_type']) { case 'richtext': /* Get a plain text version of a richtext story. */ $body_html = $story['body']; $body_text = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($body_html, 'html2text'); /* Add description. */ $body_html = '<p>' . $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($story['desc'], 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO, 'callback' => null)) . "</p>\n" . $body_html; $body_text = Horde_String::wrap(' ' . $story['description'], 70) . "\n\n" . $body_text; /* Add the text version of the story to the base message. */ $message_text = new MIME_Part('text/plain'); $message_text->setCharset('UTF-8'); $message_text->setContents($message_text->replaceEOL($body_text)); $message_text->setDescription(_("Plaintext Version of Story")); /* Add an HTML version of the story to the base message. */ $message_html = new MIME_Part('text/html', Horde_String::wrap($body_html), 'UTF-8', 'inline'); $message_html->setDescription(_("HTML Version of Story")); /* Add the two parts as multipart/alternative. */ $basepart = new MIME_Part('multipart/alternative'); $basepart->addPart($message_text); $basepart->addPart($message_html); return $basepart; case 'text': /* This is just a plain text story. */ $message_text = new MIME_Part('text/plain'); $message_text->setContents($message_text->replaceEOL($story['description'] . "\n\n" . $story['body'])); $message_text->setCharset('UTF-8'); return $message_text; } }