From: Jan Schneider Date: Thu, 27 Jan 2011 14:17:23 +0000 (+0100) Subject: Send alarms as multipart messages. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=6287e02ce8484cd6bfb7f15a41635db5d467b460;p=horde.git Send alarms as multipart messages. --- diff --git a/nag/docs/CHANGES b/nag/docs/CHANGES index f121f411e..558b3a60d 100644 --- a/nag/docs/CHANGES +++ b/nag/docs/CHANGES @@ -2,6 +2,7 @@ v3.0-git -------- +[jan] Send alarm notifications with HTML part and convert to Horde_View. [jan] Default task lists no longer have the user name as the ID. [jan] Create a default task list if the user doesn't own any yet. [jan] Add start date to possible colums in task list (Joel Smith diff --git a/nag/lib/Nag.php b/nag/lib/Nag.php index 6d3e9fdba..37076d0ee 100644 --- a/nag/lib/Nag.php +++ b/nag/lib/Nag.php @@ -1020,6 +1020,59 @@ class Nag } /** + * Builds the body MIME part of a multipart message. + * + * @param Horde_View $view A view to render the HTML and plain text + * templates for the messate. + * @param string $template The template base name for the view. + * @param Horde_Mime_Part $image The MIME part of a related image. + * + * @return Horde_Mime_Part A multipart/alternative MIME part. + */ + public static function buildMimeMessage(Horde_View $view, $template, + Horde_Mime_Part $image) + { + $multipart = new Horde_Mime_Part(); + $multipart->setType('multipart/alternative'); + $bodyText = new Horde_Mime_Part(); + $bodyText->setType('text/plain'); + $bodyText->setCharset('UTF-8'); + $bodyText->setContents($view->render($template . '.plain.php')); + $bodyText->setDisposition('inline'); + $multipart->addPart($bodyText); + $bodyHtml = new Horde_Mime_Part(); + $bodyHtml->setType('text/html'); + $bodyHtml->setCharset('UTF-8'); + $bodyHtml->setContents($view->render($template . '.html.php')); + $bodyHtml->setDisposition('inline'); + $related = new Horde_Mime_Part(); + $related->setType('multipart/related'); + $related->setContentTypeParameter('start', $bodyHtml->setContentId()); + $related->addPart($bodyHtml); + $related->addPart($image); + $multipart->addPart($related); + return $multipart; + } + + /** + * Returns a MIME part for an image to be embedded into a HTML document. + * + * @param string $file An image file name. + * + * @return Horde_Mime_Part A MIME part representing the image. + */ + public static function getImagePart($file) + { + $background = Horde_Themes::img($file); + $image = new Horde_Mime_Part(); + $image->setType('image/png'); + $image->setContents(file_get_contents($background->fs)); + $image->setContentId(); + $image->setDisposition('attachment'); + return $image; + } + + /** * Returns the real name, if available, of a user. */ public static function getUserName($uid) diff --git a/nag/lib/Task.php b/nag/lib/Task.php index bdbc3b961..ace88e244 100644 --- a/nag/lib/Task.php +++ b/nag/lib/Task.php @@ -762,12 +762,20 @@ class Nag_Task { } } if (isset($methods['mail'])) { - $methods['mail']['body'] = sprintf( - _("We would like to remind you of this due task.\n\n%s\n\nDate: %s\nTime: %s\n\n%s"), - $this->name, - strftime($prefs->getValue('date_format'), $this->due), - date($prefs->getValue('twentyFour') ? 'H:i' : 'h:ia', $this->due), - $this->desc); + $image = Nag::getImagePart('big_alarm.png'); + + $view = new Horde_View(array('templatePath' => NAG_TEMPLATES . '/alarm', 'encoding' => 'UTF-8')); + new Horde_View_Helper_Text($view); + $view->task = $this; + $view->imageId = $image->getContentId(); + $view->due = new Horde_Date($this->due); + $view->dateFormat = $prefs->getValue('date_format'); + $view->timeFormat = $prefs->getValue('twentyFour') ? 'H:i' : 'h:ia'; + if (!$prefs->isLocked('task_alarms')) { + $view->prefsUrl = Horde::url(Horde::getServiceLink('prefs', 'nag'), true)->remove(session_name()); + } + + $methods['mail']['mimepart'] = Nag::buildMimeMessage($view, 'mail', $image); } return array( 'id' => $this->uid, diff --git a/nag/templates/alarm/mail.html.php b/nag/templates/alarm/mail.html.php new file mode 100644 index 000000000..f35ea01c3 --- /dev/null +++ b/nag/templates/alarm/mail.html.php @@ -0,0 +1,36 @@ +

h($this->task->name) ?>

+ + + + +
+ + + + + + > + + + + + + task->desc)): ?> + + > + + + + + + +
+ +  due->strftime($this->dateFormat) ?>, due->format($this->timeFormat) ?>
+ +  getInstance('Horde_Core_Factory_TextFilter')->filter($this->task->desc, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO, 'callback' => null)) ?>
+
+ +prefsUrl): ?> +

prefsUrl . '">', '') ?>

+ diff --git a/nag/templates/alarm/mail.plain.php b/nag/templates/alarm/mail.plain.php new file mode 100644 index 000000000..9c5647ad0 --- /dev/null +++ b/nag/templates/alarm/mail.plain.php @@ -0,0 +1,12 @@ + + + +task->name ?> + + + due->strftime($this->dateFormat) ?> + + due->format($this->timeFormat) ?> + + +task->desc ?> diff --git a/nag/themes/default/graphics/big_alarm.png b/nag/themes/default/graphics/big_alarm.png new file mode 100644 index 000000000..641a1ddc1 Binary files /dev/null and b/nag/themes/default/graphics/big_alarm.png differ