Add preference to show flags created by other MUAs (Request #8882)
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 20 Apr 2010 08:49:53 +0000 (02:49 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 20 Apr 2010 21:15:04 +0000 (15:15 -0600)
imp/config/prefs.php.dist
imp/docs/CHANGES
imp/lib/Imap/Flags.php
imp/templates/prefs/flags.html

index 48d2928..db8a968 100644 (file)
@@ -973,7 +973,7 @@ $prefGroups['flags'] = array(
     'column' => _("Message Options"),
     'label' => _("Message Flags"),
     'desc' => _("Configure flag highlighting."),
-    'members' => array('flagmanagement')
+    'members' => array('flagmanagement', 'show_all_flags')
 );
 
 // UI for flag management.
@@ -1123,7 +1123,15 @@ $_prefs['msgflags_user'] = array(
 
 // The default color to use for flags that don't require row highlighting.
 $_prefs['msgflags_color'] = array(
-    'value' => '#ffffff'
+    'value' => '#ddd'
+);
+
+// Show all flags (including flags set by other mail programs)?
+$_prefs['show_all_flags'] = array(
+    'value' => 0,
+    'advanced' => true,
+    'type' => 'checkbox',
+    'desc' => _("Show all flags (including flags set by other mail programs)?")
 );
 
 
index d306aca..5915626 100644 (file)
@@ -2,6 +2,7 @@
 v5.0-git
 --------
 
+[mms] Add preference to show flags created by other MUAs (Request #8882).
 [mms] Added HTML signature support (Request #1406).
 [mms] Simplified date sorting display (Ticket #8936).
 [mms] Properly redirect messages pursuant to RFC 5322 [3.6.6].
index 77f9222..6edf5d1 100644 (file)
@@ -31,6 +31,13 @@ class IMP_Imap_Flags
     protected $_userflags = null;
 
     /**
+     * Temporary flags (i.e. flags created by other MUAs).
+     *
+     * @var array
+     */
+    protected $_tempflags = array();
+
+    /**
      * Save the flag list to the prefs backend.
      *
      * @param boolean $user  If true, update the user flag list. Otherwise,
@@ -93,25 +100,40 @@ class IMP_Imap_Flags
                  * allowed in EXAMINE mode. */
                 $GLOBALS['imp_imap']->ob()->openMailbox($options['mailbox'], Horde_Imap_Client::OPEN_READWRITE);
                 $status = $GLOBALS['imp_imap']->ob()->status($options['mailbox'], Horde_Imap_Client::STATUS_PERMFLAGS);
-                if (!in_array('\\*', $status['permflags'])) {
-                    $avail_flags = array_intersect($avail_flags, $status['permflags']);
+
+                if (($pos = array_search('\\*', $status['permflags'])) !== false) {
+                    if ($GLOBALS['prefs']->getValue('show_all_flags')) {
+                        unset($status['permflags'][$pos]);
+                        $avail_flags = array_keys(array_flip(array_merge($avail_flags, $status['permflags'])));
+                    }
+                } else {
+                    $avail_flags = $GLOBALS['prefs']->getValue('show_all_flags')
+                        ? $status['permflags']
+                        : array_filter(array_diff($status['permflags'], $avail_flags));
                 }
             } catch (Horde_Imap_Client_Exception $e) {}
         }
 
         foreach ($avail_flags as $key) {
-            $ret[$key] = $this->_flags[$key];
-            $ret[$key]['flag'] = $key;
-
-            if (!empty($options['fgcolor'])) {
-                $ret[$key] = $this->_getColor($key, $ret[$key]);
-            }
-
-            if (!empty($options['imap']) &&
-                !in_array($ret[$key]['t'], $types)) {
-                unset($ret[$key]);
-            } elseif (!empty($options['div']) && isset($ret[$key]['c'])) {
-                $ret[$key]['div'] = $this->_getDiv($ret[$key]['c'], $ret[$key]['l']);
+            if (!isset($this->_flags[$key])) {
+                /* Keywords might be UTF7-IMAP encoded. */
+                $ret[$key] = $this->_createEntry(Horde_String::convertCharset($key, 'UTF7-IMAP'));
+                $ret[$key]['flag'] = $key;
+                $this->_tempflags[$key] = $ret[$key];
+            } else {
+                $ret[$key] = $this->_flags[$key];
+                if (!empty($options['imap']) &&
+                    !in_array($ret[$key]['t'], $types)) {
+                    unset($ret[$key]);
+                } else {
+                    $ret[$key]['flag'] = $key;
+                    if (!empty($options['fgcolor'])) {
+                        $ret[$key] = $this->_getColor($key, $ret[$key]);
+                    }
+                    if (!empty($options['div']) && isset($ret[$key]['c'])) {
+                        $ret[$key]['div'] = $this->_getDiv($ret[$key]['c'], $ret[$key]['l']);
+                    }
+                }
             }
         }
 
@@ -162,15 +184,7 @@ class IMP_Imap_Flags
         for ($i = 0;; ++$i) {
             $curr = self::PREFIX . $i;
             if (!isset($this->_flags[$curr])) {
-                $entry = array(
-                    // 'a' => These flags are not shown in mimp
-                    // TODO: Generate random background
-                    'b' => '#ffffff',
-                    'c' => 'flagUser',
-                    'd' => true,
-                    'l' => $label,
-                    't' => 'imapp'
-                );
+                $entry = $this->_createEntry($label);
 
                 $this->_flags[$curr] = $entry;
                 $this->_userflags[$curr] = $entry;
@@ -182,6 +196,25 @@ class IMP_Imap_Flags
     }
 
     /**
+     * Creates a flag entry data object.
+     *
+     * @param string $label  The label to use for the flag.
+     *
+     * @return array  Flag data object.
+     */
+    protected function _createEntry($label)
+    {
+        return array(
+            // 'a' => These flags are not shown in mimp
+            'b' => $GLOBALS['prefs']->getValue('msgflags_color'),
+            'c' => 'flagUser',
+            'd' => true,
+            'l' => $label,
+            't' => 'imapp'
+        );
+    }
+
+    /**
      * Updates a flag.
      *
      * @param string $label  The flag label.
@@ -297,20 +330,16 @@ class IMP_Imap_Flags
             }
         }
 
-        if (($_SESSION['imp']['protocol'] == 'imap') &&
-            isset($options['flags'])) {
-            if (!empty($options['flags'])) {
-                $options['flags'] = array_map('strtolower', $options['flags']);
-            }
+        if ($_SESSION['imp']['protocol'] == 'imap') {
+            $flaglist = empty($options['flags'])
+                ? array()
+                : array_map('strtolower', $options['flags']);
 
-            foreach ($f as $k => $v) {
+            foreach (array_merge($f, $this->_tempflags) as $k => $v) {
                 if (in_array($v['t'], array('imap', 'imapp', 'imapu', 'imp'))) {
-                    if (empty($v['n'])) {
-                        $match = in_array($k, $options['flags']);
-                    } elseif (empty($options['flags'])) {
-                        $match = true;
-                    } else {
-                        $match = !in_array($k, $options['flags']);
+                    $match = in_array($k, $flaglist);
+                    if (!empty($v['n'])) {
+                        $match = !$match;
                     }
 
                     if ($match) {
@@ -420,9 +449,10 @@ class IMP_Imap_Flags
     protected function _getColor($key, $in)
     {
         $in['f'] = '#000';
+
         if (!isset($in['b'])) {
-            $in['b'] = $GLOBALS['prefs']->getValue('msgflags_color');
-        } elseif (Horde_Image::brightness($this->_flags[$key]['b']) < 128) {
+            $in['b'] = '#fff';
+        } elseif (Horde_Image::brightness($in['b']) < 128) {
             $in['f'] = '#f6f6f6';
         }
 
index b106375..409f0d7 100644 (file)
@@ -46,5 +46,7 @@
 </table>
 
 <if:userflags_notlocked>
-<input id="new_button" type="button" class="button" value="<gettext>New Flag</gettext>" />
+<div>
+ <input id="new_button" type="button" class="button" value="<gettext>New Flag</gettext>" />
+</div>
 </if:userflags_notlocked>