Move sequence parsing code to Horde_Imap_Client_Utils::.
authorMichael M Slusarz <slusarz@curecanti.org>
Sun, 22 Mar 2009 02:45:01 +0000 (20:45 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Sun, 22 Mar 2009 22:50:15 +0000 (16:50 -0600)
imp/ajax.php
imp/lib/IMP.php
imp/lib/Views/ListMessages.php
imp/mailbox.php
imp/thread.php

index 470844e..05e601b 100644 (file)
@@ -17,7 +17,7 @@ function _generateDeleteResult($mbox, $indices, $change, $nothread = false)
 
     $result = new stdClass;
     $result->folder = $mbox;
-    $result->uids = IMP::toRangeString($indices);
+    $result->uids = $GLOBALS['imap_utils']->toSequenceString($indices, array('mailbox' => true));
     $result->remove = ($GLOBALS['prefs']->getValue('hide_deleted') ||
                        $GLOBALS['prefs']->getValue('use_trash'));
     $result->cacheid = $imp_mailbox->getCacheID($mbox);
@@ -172,9 +172,11 @@ $dimp_logout = ($action == 'LogOut');
 $session_timeout = 'json';
 require_once $imp_dir . '/lib/base.php';
 
+$imap_utils = new Horde_Imap_Client_Utils();
+
 // Process common request variables.
 $mbox = Util::getPost('view');
-$indices = IMP::parseRangeString(Util::getPost('uid'));
+$indices = $imap_utils->fromSequenceString(Util::getPost('uid'));
 $cacheid = Util::getPost('cacheid');
 
 // Open an output buffer to ensure that we catch errors that might break JSON
index e020b32..c261645 100644 (file)
@@ -1923,96 +1923,6 @@ class IMP
     }
 
     /**
-     * Create a message list string.
-     * Format: {mbox_length}[mailbox]range_start:range_end,uid,uid2...
-     *
-     * @param array $in  An array with the full mailbox name as keys and an
-     *                   array of message indices as the values (see output
-     *                   from IMP::parseIndicesList()).
-     *
-     * @return string  The message list string. The string does not maintain
-     *                 sorted information.
-     */
-    static public function toRangeString($in)
-    {
-        $str = '';
-
-        foreach ($in as $mbox => $uids) {
-            if (empty($uids)) {
-                continue;
-            }
-
-            sort($uids, SORT_NUMERIC);
-            $first = $last = array_shift($uids);
-            $out = array();
-
-            foreach ($uids as $val) {
-                if ($last + 1 == $val) {
-                    $last = $val;
-                } else {
-                    $out[] = $first . ($last == $first ? '' : (':' . $last));
-                    $first = $last = $val;
-                }
-            }
-            $out[] = $first . ($last == $first ? '' : (':' . $last));
-            $str .= '{' . strlen($mbox) . '}' . $mbox . implode(',', $out);
-        }
-
-        return $str;
-    }
-
-    /**
-     * Parse a message list string generated by IMP::toRangeString().
-     * Format: ({mbox_length}[mailbox]range_start:range_end,uid,uid2)
-     *
-     * @param string $msgstr  The message list string.
-     *
-     * @return array  An array with the full mailbox name as keys and an
-     *                array of message indices as the values (see output
-     *                from IMP::parseIndicesList()).
-     */
-    static public function parseRangeString($msgstr)
-    {
-        $msglist = array();
-        $msgstr = trim($msgstr);
-
-        while ($msgstr) {
-            if ($msgstr[0] != '{') {
-                break;
-            }
-            $i = strpos($msgstr, '}');
-            $count = intval(substr($msgstr, 1, $i - 1));
-            $mbox = substr($msgstr, $i + 1, $count);
-            $i += $count + 1;
-            $end = strpos($msgstr, '{', $i);
-            if ($end === false) {
-                $uidstr = substr($msgstr, $i);
-                $msgstr = '';
-            } else {
-                $uidstr = substr($msgstr, $i, $end - $i);
-                $msgstr = substr($msgstr, $end);
-            }
-
-            $uids = array();
-            $uidarray = explode(',', $uidstr);
-            if (empty($uidarray)) {
-                $uidarray = array($uidstr);
-            }
-            foreach ($uidarray as $val) {
-                $range = explode(':', $val);
-                if (count($range) == 1) {
-                    $uids[] = intval($val);
-                } else {
-                    $uids = array_merge($uids, range(intval($range[0]), intval($range[1])));
-                }
-            }
-            $msglist[$mbox] = $uids;
-        }
-
-        return $msglist;
-    }
-
-    /**
      * Returns a Horde_Cache object (if configured) and handles any errors
      * associated with creating the object.
      *
index a5a6d3d..8e78f55 100644 (file)
@@ -184,7 +184,8 @@ class IMP_Views_ListMessages
             if (isset($md->search)) {
                 $cached = Horde_Serialize::unserialize($args['cached'], Horde_Serialize::JSON);
             } else {
-                $cached = IMP::parseRangeString($args['cached']);
+                $imap_utils = new Horde_Imap_Client_Utils();
+                $cached = $imap_utils->fromSequenceString($args['cached']);
                 $cached = reset($cached);
             }
             $cached = array_flip($cached);
index 497c922..3c1a8ba 100644 (file)
@@ -217,7 +217,8 @@ case 'empty_mailbox':
     break;
 
 case 'view_messages':
-    $redirect = Util::addParameter(IMP::generateIMPUrl('thread.php', $imp_mbox['mailbox'], null, null, false), array('mode' => 'msgview', 'msglist' => IMP::toRangeString(IMP::parseIndicesList($indices))), null, false);
+    $imap_utils = new Horde_Imap_Client_Utils();
+    $redirect = Util::addParameter(IMP::generateIMPUrl('thread.php', $imp_mbox['mailbox'], null, null, false), array('mode' => 'msgview', 'msglist' => $imap_utils->toSequenceString(IMP::parseIndicesList($indices), array('mailbox' => true))), null, false);
     header('Location: ' . $redirect);
     exit;
 
index 4abf24e..e76bff8 100644 (file)
@@ -27,7 +27,8 @@ if ($mode == 'thread') {
     }
 } else {
     /* MSGVIEW MODE: Make sure we have a valid list of messages. */
-    $msglist = IMP::parseRangeString(Util::getFormData('msglist', array()));
+    $imap_utils = new Horde_Imap_Client_Utils();
+    $msglist = $imap_utils->fromSequenceString(Util::getFormData('msglist'));
     if (empty($msglist)) {
         $error = true;
     }