Use IMP_Imap_Flags::getFlagList() to build the flag menu for searches.
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 25 Aug 2009 16:08:52 +0000 (10:08 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 25 Aug 2009 17:08:25 +0000 (11:08 -0600)
imp/lib/UI/Search.php
imp/search-basic.php
imp/search.php

index 89dc917..22f6fea 100644 (file)
@@ -21,10 +21,6 @@ class IMP_UI_Search
     const TEXT = 4;
     const SIZE = 5;
 
-    /* Defines used to identify the flag input. */
-    const FLAG_NOT = 0;
-    const FLAG_HAS = 1;
-
     /**
      * Return the base search fields.
      *
@@ -105,48 +101,17 @@ class IMP_UI_Search
      */
     public function flagFields()
     {
-        return array(
-            'seen' => array(
-                'flag' => '\\seen',
-                'label' => _("Seen messages"),
-                'type' => self::FLAG_HAS
-            ),
-            'unseen' => array(
-                'flag' => '\\seen',
-                'label' => _("Unseen messages"),
-                'type' => self::FLAG_NOT
-            ),
-            'answered' => array(
-                'flag' => '\\answered',
-                'label' => _("Answered messages"),
-                'type' => self::FLAG_HAS
-            ),
-            'unanswered' => array(
-                'flag' => '\\answered',
-                'label' => _("Unanswered messages"),
-                'type' => self::FLAG_NOT
-            ),
-            'flagged' => array(
-                'flag' => '\\flagged',
-                'label' => _("Flagged messages"),
-                'type' => self::FLAG_HAS
-            ),
-            'unflagged' => array(
-                'flag' => '\\flagged',
-                'label' => _("Unflagged messages"),
-                'type' => self::FLAG_NOT
-            ),
-            'deleted' => array(
-                'flag' => '\\deleted',
-                'label' => _("Deleted messages"),
-                'type' => self::FLAG_HAS
-            ),
-            'undeleted' => array(
-                'flag' => '\\deleted',
-                'label' => _("Undeleted messages"),
-                'type' => self::FLAG_NOT
-            ),
-        );
+        $imp_flags = IMP_Imap_Flags::singleton();
+        $flist = $imp_flags->getFlagList(null);
+
+        $flags = array();
+
+        for ($i = 0, $cnt = count($flist['set']); $i < $cnt; ++$i) {
+            $flags[$flist['set'][$i]['f']] = $flist['set'][$i]['l'];
+            $flags[$flist['unset'][$i]['f']] = sprintf(_("Not %s"), $flist['unset'][$i]['l']);
+        }
+
+        return $flags;
     }
 
     /**
@@ -168,7 +133,12 @@ class IMP_UI_Search
             $ob = new Horde_Imap_Client_Search_Query();
 
             if (isset($flag_fields[$val])) {
-                $ob->flag($flag_fields[$val]['flag'], (bool)$flag_fields[$val]['type']);
+                if (strpos($val, '0\\') === 0) {
+                    $val = substr($val, 2);
+                    $ob->flag($val, false);
+                } else {
+                    $ob->flag($val, true);
+                }
                 $search_array[] = $ob;
             } else {
                 switch ($search_fields[$val]['type']) {
index c0acd7e..452161e 100644 (file)
@@ -41,7 +41,7 @@ $search_mailbox = Horde_Util::getFormData('search_mailbox');
 
 foreach ($imp_ui_search->searchFields() as $key => $val) {
     if ($val['type'] != IMP_UI_Search::DATE) {
-        $s_fields[$key] = array(
+        $s_fields[] = array(
             'val' => $key,
             'label' => $val['label']
         );
@@ -49,9 +49,9 @@ foreach ($imp_ui_search->searchFields() as $key => $val) {
 }
 
 foreach ($imp_ui_search->flagFields() as $key => $val) {
-    $f_fields[$key] = array(
+    $f_fields[] = array(
         'val' => $key,
-        'label' => $val['label']
+        'label' => $val
     );
 }
 
index f744982..0710afe 100644 (file)
@@ -201,7 +201,7 @@ foreach ($imp_search_fields as $key => $val) {
 foreach ($imp_ui_search->flagFields() as $key => $val) {
     $f_fields[$key] = array(
         'val' => $key,
-        'label' => $val['label'],
+        'label' => $val,
         'sel' => null
     );
 }