From 547ab80513f5bc7a7f3d89fddb7987a322bf7576 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 19 Nov 2010 15:18:36 -0700 Subject: [PATCH] Request #9028: Forgotten attachment checking (hook example) Note that the signature of the pre_sent hook has changed - a third parameter, the IMP_Compose object, is now provided. --- imp/config/hooks.php.dist | 22 ++++++++++++++++++++-- imp/docs/CHANGES | 2 ++ imp/lib/Compose.php | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/imp/config/hooks.php.dist b/imp/config/hooks.php.dist index fe7c894cd..27c7994c3 100644 --- a/imp/config/hooks.php.dist +++ b/imp/config/hooks.php.dist @@ -169,12 +169,13 @@ class IMP_Hooks * * @param Horde_Mime_Part $message The message content object. * @param Horde_Mime_Headers $headers The message headers object. + * @param IMP_Compose $compose The compose object. * * @throws IMP_Compose_Exception */ -// public function pre_sent($message, $headers) +// public function pre_sent($message, $headers, $compose) // { -// // Example: Add custom headers to outgoing message. +// // Example #1: Add custom headers to outgoing message. // $custom_hdrs = array(); // $hdr_charset = $message->getHeaderCharset(); // @@ -192,6 +193,23 @@ class IMP_Hooks // foreach ($custom_hdrs as $key => $val) { // $headers->addHeader($key, Horde_String::convertCharset($val, 'UTF-8', $hdr_charset)); // } +// +// +// // Example #2: Check for forgotten attachments when sending. +// if (!count($compose) && +// !$GLOBALS['session']->get('imp', 'attach_check/' . strval($compose))) { +// /* List of words to search for. */ +// $word_list = array( +// 'attachment', 'attached' +// ) +// +// if (preg_match('/\b(' . implode('|', array_map('preg_quote', $word_list)) . ')\b/i', $message->getContents(), $matches)) { +// // Set flag in the session to indicate we should not check +// // this message for attachments again. +// $GLOBALS['session']->set('imp', 'attach_check/' . strval($compose), 1); +// throw new IMP_Compose_Exception('Found the word "' . $matches[1] . '" in the message text although there are no files attached to the message. Did you forget to attach a file?'); +// } +// } // } diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index 3d830d3ae..3d4ad0d81 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -2,6 +2,8 @@ v5.0-git -------- +[mms] Added example in pre_sent hook to do forgotten attachment checking at + send time (Request #9028). [mms] Add subfolder searching (subfolders dynamically determined at time of search). [mms] Refactor inline message image blocking to operate on all messages, not diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index cfab51276..872333a42 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -801,7 +801,7 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator /* Pass to hook to allow alteration of message details. */ if (!is_null($message)) { try { - Horde::callHook('pre_sent', array($message, $headers), 'imp'); + Horde::callHook('pre_sent', array($message, $headers, $this), 'imp'); } catch (Horde_Exception_HookNotSet $e) {} } -- 2.11.0