Request #9028: Forgotten attachment checking (hook example)
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 19 Nov 2010 22:18:36 +0000 (15:18 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 19 Nov 2010 22:18:36 +0000 (15:18 -0700)
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
imp/docs/CHANGES
imp/lib/Compose.php

index fe7c894..27c7994 100644 (file)
@@ -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?');
+//            }
+//        }
 //    }
 
 
index 3d830d3..3d4ad0d 100644 (file)
@@ -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
index cfab512..872333a 100644 (file)
@@ -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) {}
         }