Abstract this code out
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 28 May 2009 11:56:22 +0000 (05:56 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 28 May 2009 11:56:22 +0000 (05:56 -0600)
imp/lib/Imap/Flags.php
imp/mailbox.php

index 3959995..21b710c 100644 (file)
@@ -349,6 +349,35 @@ class IMP_Imap_Flags
     }
 
     /**
+     * Get the list of set/unset actions for use in dropdown lists.
+     *
+     * @param string $mbox  The current mailbox.
+     *
+     * @return array  An array with 2 elements: 'set' and 'unset'.
+     */
+    public function getFlagList($mbox)
+    {
+        $ret = array('set' => array(), 'unset' => array());
+
+        foreach ($this->getList(array('imap' => true, 'mailbox' => $mbox)) as $val) {
+            $tmp = array(
+                'f' => $val['flag'],
+                'l' => $val['l']
+            );
+
+            /* Check for 'opposite' flag actions. */
+            $act1 = isset($val['n']) ? 'unset' : 'set';
+            $act2 = ($act1 == 'set') ? 'unset' : 'set';
+
+            $ret[$act1][] = $tmp;
+            $tmp['f'] = '0' . $val['flag'];
+            $ret[$act2][] = $tmp;
+        }
+
+        return $ret;
+    }
+
+    /**
      * Output a DIV element to display the icon.
      *
      * @param string $c  A classname.
index 3ddc771..8b3f84e 100644 (file)
@@ -505,27 +505,9 @@ if ($pageOb['msgcount']) {
     $n_template->set('use_pop', $_SESSION['imp']['protocol'] == 'pop');
 
     if (!$n_template->get('use_pop')) {
-        $flaglist_set = $flaglist_unset = array();
-        foreach ($imp_flags->getList(array('imap' => true, 'mailbox' => $search_mbox ? null : $imp_mbox['mailbox'])) as $val) {
-            $tmp = array(
-                'f' => $val['flag'],
-                'l' => $val['l']
-            );
-
-            /* These entries are 'opposite' flag actions. */
-            if (isset($val['n'])) {
-                $flaglist_unset[] = $tmp;
-                $tmp['f'] = '0' . $val['flag'];
-                $flaglist_set[] = $tmp;
-            } else {
-                $flaglist_set[] = $tmp;
-                $tmp['f'] = '0' . $val['flag'];
-                $flaglist_unset[] = $tmp;
-            }
-        }
-
-        $n_template->set('flaglist_set', $flaglist_set);
-        $n_template->set('flaglist_unset', $flaglist_unset);
+        $tmp = $imp_flags->getFlagList($search_mbox ? null : $imp_mbox['mailbox']);
+        $n_template->set('flaglist_set', $tmp['set']);
+        $n_template->set('flaglist_unset', $tmp['unset']);
 
         if ($n_template->get('use_folders')) {
             $n_template->set('move', Horde::widget('#', _("Move to folder"), 'widget moveAction', '', '', _("Move"), true));