From: Michael M Slusarz Date: Sun, 22 Mar 2009 02:45:01 +0000 (-0600) Subject: Move sequence parsing code to Horde_Imap_Client_Utils::. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=e1db42f7b12cbb0242cfe20f54324f1aadb10e95;p=horde.git Move sequence parsing code to Horde_Imap_Client_Utils::. --- diff --git a/imp/ajax.php b/imp/ajax.php index 470844eef..05e601b90 100644 --- a/imp/ajax.php +++ b/imp/ajax.php @@ -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 diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index e020b32a1..c2616455d 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -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. * diff --git a/imp/lib/Views/ListMessages.php b/imp/lib/Views/ListMessages.php index a5a6d3d16..8e78f556f 100644 --- a/imp/lib/Views/ListMessages.php +++ b/imp/lib/Views/ListMessages.php @@ -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); diff --git a/imp/mailbox.php b/imp/mailbox.php index 497c922d1..3c1a8babb 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -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; diff --git a/imp/thread.php b/imp/thread.php index 4abf24eb9..e76bff834 100644 --- a/imp/thread.php +++ b/imp/thread.php @@ -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; }