Request #7353 - Add imp_hook_display_folder() hook.
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 5 Feb 2009 20:55:23 +0000 (13:55 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 6 Feb 2009 05:16:45 +0000 (22:16 -0700)
imp/config/conf.xml
imp/config/hooks.php.dist
imp/docs/CHANGES
imp/js/src/DimpBase.js
imp/lib/IMAP/Tree.php

index 6ab974e..f6d2c49 100644 (file)
    a custom function to provide additional information/custom formatting of
    messages in the mailbox message list? If so, make sure you define
    _imp_hook_msglist_format() in hooks.php.">false</configboolean>
+   <configboolean name="display_folder" required="false" desc="Should we use
+   a custom function to dynamically determine if we show a specified IMAP
+   mailbox in the folderlist ? If so, make sure you define
+   _imp_hook_display_folder() in hooks.php.">false</configboolean>
   </configsection>
  </configtab>
 
index fcfe918..0ce4e90 100644 (file)
 //     }
 // }
 
+// This is an example hook function to hide specified IMAP mailboxes in
+// folder listings. If the hook returns false, the mailbox will not be
+// displayed.
+
+// if (!function_exists('_imp_hook_display_folder')) {
+//     function _imp_hook_display_folder($mailbox) {
+//         return ($mailbox == 'DONOTDISPLAY');
+//     }
+// }
+
 // This is an example hook function for the IMP spam reporting email option.
 // This function is called when the message is about to be forwarded - it
 // will return the email address to forward to.  This is handy for spam
@@ -478,6 +488,13 @@ if (!empty($GLOBALS['conf']['kolab']['enabled'])) {
             return $icons;
         }
     }
+
+    if (!function_exists('_imp_hook_display_folder')) {
+        function _imp_hook_display_folder($mailbox) {
+            $type = Kolab::getMailboxType($mailbox);
+            return empty($type) || ($type == 'mail');
+        }
+    }
 }
 
 // Sample function for returning the quota. Uses the PECL ssh2
index fb57740..331c9f2 100644 (file)
@@ -50,10 +50,10 @@ v5.0-git
 v4.3.4-cvs
 ----------
 
-[jan] Fix rendering of subjects in RTL scripts when using LTR translations
-      (vilius@lnk.lt, Bug #3511).
 [mms] Add hook to allow hiding of IMAP folders (Request #7353, Gunnar
       Wrobel <p@rdus.de>).
+[jan] Fix rendering of subjects in RTL scripts when using LTR translations
+      (vilius@lnk.lt, Bug #3511).
 [jan] Fix logging of messages forwarded with attachments (Bug #7911).
 
 
index ff2707b..c667331 100644 (file)
@@ -1886,7 +1886,7 @@ var DimpBase = {
 
         div = new Element('DIV', { className: ob.cl || 'base', id: fid + '_div' });
         if (ob.i) {
-            div.setStyle({ background-image: 'url("' + ob.i + '")' });
+            div.setStyle({ backgroundImage: 'url("' + ob.i + '")' });
         }
         if (ob.ch) {
             div.writeAttribute({ className: 'exp' });
index c394b02..56966b7 100644 (file)
@@ -28,6 +28,7 @@ class IMP_IMAP_Tree
     const ELT_NEED_SORT = 64;
     const ELT_VFOLDER = 128;
     const ELT_NONIMAP = 256;
+    const ELT_INVISIBLE = 512;
 
     /* The isOpen() expanded mode constants. */
     const OPEN_NONE = 0;
@@ -382,7 +383,12 @@ class IMP_IMAP_Tree
         /* Get the mailbox label. */
         $elt['l'] = IMP::getLabel($tmp[$elt['c']]);
 
+
         if ($_SESSION['imp']['protocol'] != 'pop') {
+            if (!empty($GLOBALS['conf']['hooks']['display_folder'])) {
+                $this->_setInvisible($elt, !Horde::callHook('_imp_hook_display_folder', array($elt['v']), 'imp'));
+            }
+
             if ($elt['c'] != 0) {
                 $elt['p'] = implode(is_null($ns_info) ? $this->_delimiter : $ns_info['delimiter'], array_slice($tmp, 0, $elt['c']));
             }
@@ -1248,6 +1254,29 @@ class IMP_IMAP_Tree
     }
 
     /**
+     * Is the element invisible?
+     *
+     * @param array $elt  A tree element.
+     *
+     * @return integer  True if the element is marked as invisible.
+     */
+    public function isInvisible($elt)
+    {
+        return $elt['a'] & self::ELT_INVISIBLE;
+    }
+
+    /**
+     * Set the invisible attribute for an element.
+     *
+     * @param array &$elt    A tree element.
+     * @param boolean $bool  The setting.
+     */
+    protected function _setInvisible(&$elt, $bool)
+    {
+        $this->_setAttribute($elt, self::ELT_INVISIBLE, $bool);
+    }
+
+    /**
      * Flag the element as needing its children to be sorted.
      *
      * @param array &$elt    A tree element.
@@ -1401,9 +1430,10 @@ class IMP_IMAP_Tree
      */
     protected function _activeElt($elt)
     {
-        return ($this->_showunsub ||
-                ($this->isSubscribed($elt) && !$this->isContainer($elt)) ||
-                $this->hasChildren($elt));
+        return (!$this->isInvisible($elt) &&
+                ($this->_showunsub ||
+                 ($this->isSubscribed($elt) && !$this->isContainer($elt)) ||
+                 $this->hasChildren($elt)));
     }
 
     /**