Add pre_sent hook
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 10 Mar 2010 06:19:15 +0000 (23:19 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 10 Mar 2010 06:19:15 +0000 (23:19 -0700)
imp/config/hooks.php.dist
imp/docs/CHANGES
imp/lib/Compose.php

index 627d864..7b5b64c 100644 (file)
@@ -168,6 +168,18 @@ class IMP_Hooks
 
 
     /**
+     * Perform an action before a message has been sent.
+     *
+     * @param Horde_Mime_Part $message     The message content object.
+     * @param Horde_Mime_Headers $headers  The message headers object.
+     */
+//    function pre_sent($message, $headers)
+//    {
+//        // Do action here -- no return value from this hook.
+//    }
+
+
+    /**
      * Perform an action after a message has been sent successfully.
      *
      * @param Horde_Mime_Part $message     The message content object.
index 24c1e9e..557dea4 100644 (file)
@@ -2,6 +2,7 @@
 v5.0-git
 --------
 
+[mms] Add hook to alter composed message details before sending.
 [mms] DIMP now honors the 'allow_resume_all' configuration option.
 [mms] Remove 'sort_limit' configuration option.
 [mms] Mobile view no longer supports WML output.
index 54588f4..28af5ff 100644 (file)
@@ -747,20 +747,6 @@ class IMP_Compose
     {
         global $conf;
 
-        /* Properly encode the addresses we're sending to. */
-        try {
-            $email = Horde_Mime::encodeAddress($email, null, $_SESSION['imp']['maildomain']);
-        } catch (Horde_Mime_Exception $e) {
-            throw new IMP_Compose_Exception($e);
-        }
-
-        /* Validate the recipient addresses. */
-        try {
-            $result = Horde_Mime_Address::parseAddressList($email, array('defserver' => $_SESSION['imp']['maildomain'], 'validate' => true));
-        } catch (Horde_Mime_Exception $e) {
-            return;
-        }
-
         $timelimit = $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_timelimit');
         if ($timelimit !== true) {
             if ($conf['sentmail']['driver'] == 'none') {
@@ -774,14 +760,33 @@ class IMP_Compose
             }
             if ($recipients > $timelimit) {
                 try {
-                    $message = Horde::callHook('perms_denied', array('imp:max_timelimit'));
+                    $error = Horde::callHook('perms_denied', array('imp:max_timelimit'));
                 } catch (Horde_Exception_HookNotSet $e) {
-                    $message = @htmlspecialchars(sprintf(_("You are not allowed to send messages to more than %d recipients within %d hours."), $timelimit, $conf['sentmail']['params']['limit_period']), ENT_COMPAT, Horde_Nls::getCharset());
+                    $error = @htmlspecialchars(sprintf(_("You are not allowed to send messages to more than %d recipients within %d hours."), $timelimit, $conf['sentmail']['params']['limit_period']), ENT_COMPAT, Horde_Nls::getCharset());
                 }
-                throw new IMP_Compose_Exception($message);
+                throw new IMP_Compose_Exception($error);
             }
         }
 
+        /* Pass to hook to allow alteration of message details. */
+        try {
+            Horde::callHook('pre_sent', array($message, $headers), 'imp');
+        } catch (Horde_Exception_HookNotSet $e) {}
+
+        /* Properly encode the addresses we're sending to. */
+        try {
+            $email = Horde_Mime::encodeAddress($email, null, $_SESSION['imp']['maildomain']);
+        } catch (Horde_Mime_Exception $e) {
+            throw new IMP_Compose_Exception($e);
+        }
+
+        /* Validate the recipient addresses. */
+        try {
+            $result = Horde_Mime_Address::parseAddressList($email, array('defserver' => $_SESSION['imp']['maildomain'], 'validate' => true));
+        } catch (Horde_Mime_Exception $e) {
+            return;
+        }
+
         $mail_driver = $this->getMailDriver();
 
         try {