Request #6734: Add hook to dynamically change mailbox label
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 9 Dec 2009 23:33:00 +0000 (16:33 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 9 Dec 2009 23:33:05 +0000 (16:33 -0700)
imp/config/hooks.php.dist
imp/docs/CHANGES
imp/lib/IMP.php

index 9281e2e..fbf21e6 100644 (file)
@@ -365,6 +365,22 @@ class IMP_Hooks
 
 
     /**
+     * Dynamically alter a mailbox display label.
+     *
+     * @param string $mbox   The mailbox name.
+     * @param string $label  The current label.
+     *
+     * @return string  The display label for $mbox.
+     */
+//    function mbox_label($mbox, $label)
+//    {
+//        // Example #1: Show 'foo' as 'bar'
+//        return ($mbox == 'foo')
+//            ? 'bar'
+//            : $label;
+//    }
+
+    /**
      * Mark a mailbox as read-only.
      *
      * @param string $mailbox  The mailbox name.
index 8ce4535..ff77a6a 100644 (file)
@@ -2,6 +2,7 @@
 v5.0-git
 --------
 
+[mms] Add hook to dynamically change mailbox label (Request #6734).
 [mms] Improved address expansion in MIMP.
 [mms] Load folders on-demand in sidebar (DIMP).
 [mms] Add priority setting to DIMP.
index b4a3f11..edbb19e 100644 (file)
@@ -64,9 +64,9 @@ class IMP
 
     /**
      * Returns the plain text label that is displayed for the current mailbox,
-     * replacing virtual search mailboxes with an appropriate description and
+     * replacing virtual search mailboxes with an appropriate description,
      * removing namespace and mailbox prefix information from what is shown to
-     * the user.
+     * the user, and passing the label through a user-defined hook.
      *
      * @param string $mbox  The mailbox to use for the label.
      *
@@ -74,9 +74,15 @@ class IMP
      */
     static public function getLabel($mbox)
     {
-        return IMP_Search::isSearchMbox($mbox)
+        $label = IMP_Search::isSearchMbox($mbox)
             ? $GLOBALS['imp_search']->getLabel($mbox)
             : self::displayFolder($mbox);
+
+        try {
+            return Horde::callHook('mbox_label', array($mbox, $label), 'imp');
+        } catch (Horde_Exception_HookNotSet $e) {
+            return $label;
+        }
     }
 
     /**