Do parsing of flag form IDs in IMP_Imap_Flags::
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 25 Aug 2009 17:15:28 +0000 (11:15 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 25 Aug 2009 17:15:28 +0000 (11:15 -0600)
imp/lib/Imap/Flags.php
imp/lib/UI/Search.php
imp/mailbox.php
imp/message.php

index 4add4d6..298965b 100644 (file)
@@ -388,4 +388,23 @@ class IMP_Imap_Flags
         return '<div class="msgflags ' . $c . '" title="' . htmlspecialchars($l) . '"></div>';
     }
 
+    /**
+     * Process a flag ID formatted for use in form data.
+     *
+     * @param string $id  The ID from form data.
+     *
+     * @return array  Two element array:
+     * <pre>
+     * 'flag' - (string) The flag name.
+     * 'set' - (boolean) Whether the flag should be set or not.
+     * </pre>
+     */
+    public function parseFormId($id)
+    {
+        if (strpos($id, '0\\') === 0) {
+            return array('flag' => substr($id, 2), 'set' => false);
+        }
+        return array('flag' => $id, 'set' => true);
+    }
+
 }
index 22f6fea..2b097bf 100644 (file)
@@ -128,17 +128,14 @@ class IMP_UI_Search
         $search_array = array();
         $search_fields = $this->searchFields();
         $flag_fields = $this->flagFields();
+        $imp_flags = IMP_Imap_Flags::singleton();
 
         foreach ($search['field'] as $key => $val) {
             $ob = new Horde_Imap_Client_Search_Query();
 
             if (isset($flag_fields[$val])) {
-                if (strpos($val, '0\\') === 0) {
-                    $val = substr($val, 2);
-                    $ob->flag($val, false);
-                } else {
-                    $ob->flag($val, true);
-                }
+                $val = $imp_flags->parseFormId($val);
+                $ob->flag($val['flag'], $val['set']);
                 $search_array[] = $ob;
             } else {
                 switch ($search_fields[$val]['type']) {
index 9dfbeee..2c56bda 100644 (file)
@@ -76,6 +76,7 @@ if (!is_array(($indices = Horde_Util::getFormData('indices')))) {
 Horde_Nls::setTimeZone();
 
 $do_filter = false;
+$imp_flags = IMP_Imap_Flags::singleton();
 $open_compose_window = null;
 
 /* Run through the action handlers */
@@ -167,13 +168,9 @@ case 'copy_messages':
 case 'flag_messages':
     $flag = Horde_Util::getPost('flag');
     if ($flag && !empty($indices)) {
-        $set = true;
-        if (strpos($flag, '0\\') === 0) {
-            $flag = substr($flag, 2);
-            $set = false;
-        }
+        $flag = $imp_imap_flags->parseFormId($flag);
         $imp_message = IMP_Message::singleton();
-        $imp_message->flag(array($flag), $indices, $set);
+        $imp_message->flag(array($flag['flag']), $indices, $flag['set']);
     }
     break;
 
@@ -480,8 +477,6 @@ if (empty($pageOb['end'])) {
     exit;
 }
 
-$imp_flags = IMP_Imap_Flags::singleton();
-
 /* Display the navbar and actions if there is at least 1 message in mailbox. */
 if ($pageOb['msgcount']) {
     $use_trash = $prefs->getValue('use_trash');
index a998e27..294cb1f 100644 (file)
@@ -77,6 +77,8 @@ $index = $index_array['index'];
 $mailbox_name = $index_array['mailbox'];
 $indices_array = array($mailbox_name => array($index));
 
+$imp_flags = IMP_Imap_Flags::singleton();
+
 switch ($actionID) {
 case 'blacklist':
 case 'whitelist':
@@ -143,12 +145,9 @@ case 'notspam_report':
 case 'flag_message':
     $flag = Horde_Util::getFormData('flag');
     if ($flag && !empty($indices_array)) {
-        $peek = $set = true;
-        if (strpos($flag, '0\\') === 0) {
-            $flag = substr($flag, 2);
-            $set = false;
-        }
-        $imp_message->flag(array($flag), $indices_array, $set);
+        $peek = true;
+        $flag = $imp_flags->parseFormId($flag);
+        $imp_message->flag(array($flag['flag']), $indices_array, $flag['set']);
         if ($prefs->getValue('mailbox_return')) {
             _returnToMailbox($imp_mailbox->getMessageIndex());
             require IMP_BASE . '/mailbox.php';
@@ -379,8 +378,6 @@ $mailbox_url = Horde_Util::addParameter(IMP::generateIMPUrl('mailbox.php', $imp_
 /* Generate the view link. */
 $view_link = IMP::generateIMPUrl('view.php', $imp_mbox['mailbox'], $index, $mailbox_name);
 
-$imp_flags = IMP_Imap_Flags::singleton();
-
 /* Everything below here is related to preparing the output. */
 
 /* Set the status information of the message. */