From 01d5788ec5b5ef0b1450f42517348790d0585bcb Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 9 Dec 2009 16:33:00 -0700 Subject: [PATCH] Request #6734: Add hook to dynamically change mailbox label --- imp/config/hooks.php.dist | 16 ++++++++++++++++ imp/docs/CHANGES | 1 + imp/lib/IMP.php | 12 +++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/imp/config/hooks.php.dist b/imp/config/hooks.php.dist index 9281e2e42..fbf21e69e 100644 --- a/imp/config/hooks.php.dist +++ b/imp/config/hooks.php.dist @@ -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. diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index 8ce453596..ff77a6a0e 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -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. diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index b4a3f11e3..edbb19eda 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -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; + } } /** -- 2.11.0