Horde_Imap_Client_Ids::_toSequenceString PHP Method

_toSequenceString() protected method

Index Format: range_start:range_end,uid,uid2,...
protected _toSequenceString ( boolean $sort = true ) : string
$sort boolean Numerically sort the IDs before creating the range?
return string The IMAP message sequence string.
    protected function _toSequenceString($sort = true)
    {
        if (empty($this->_ids)) {
            return '';
        }
        $in = $this->_ids;
        if ($sort && !$this->_sorted) {
            $this->_sort($in);
        }
        $first = $last = array_shift($in);
        $i = count($in) - 1;
        $out = array();
        reset($in);
        while (list($key, $val) = each($in)) {
            if ($last + 1 == $val) {
                $last = $val;
            }
            if ($i == $key || $last != $val) {
                if ($last == $first) {
                    $out[] = $first;
                    if ($i == $key) {
                        $out[] = $val;
                    }
                } else {
                    $out[] = $first . ':' . $last;
                    if ($i == $key && $last != $val) {
                        $out[] = $val;
                    }
                }
                $first = $last = $val;
            }
        }
        return empty($out) ? $first : implode(',', $out);
    }