$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);
$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
}
/**
- * 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.
*
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;