TreeSet<ImapMessage> result = new TreeSet<ImapMessage>(new ImapMessage.SequenceComparator());
    Set<ImapMessage> getSubsequence(String subseqStr, boolean byUID) {        if (subseqStr == null || subseqStr.trim().equals("") || mSequence.size() == 0)            return Collections.emptySet();        else if (subseqStr.equals("$"))            return mSession.getSavedSearchResults();        ImapMessage i4msg = getLastMessage();        int lastID = (i4msg == null ? (byUID ? Integer.MAX_VALUE : mSequence.size()) : (byUID ? i4msg.imapUid : i4msg.sequence));        TreeSet<ImapMessage> result = new TreeSet<ImapMessage>(new ImapMessage.SequenceComparator());        for (String subset : subseqStr.split(",")) {            if (subset.indexOf(':') == -1) {                // single message -- get it and add it (may be null)                int id = (subset.equals("*") ? lastID : parseId(subset));                result.add(byUID ? getByImapId(id) : getBySequence(id));            } else {                // colon-delimited range -- get them and add them (may be null)                String[] range = subset.split(":", 2);                int lower = (range[0].equals("*") ? lastID : parseId(range[0]));                int upper = (range[1].equals("*") ? lastID : parseId(range[1]));                if (lower > upper)  { int tmp = upper; upper = lower; lower = tmp; }                if (!byUID) {                    upper = Math.min(lastID, upper);                    for (int seq = Math.max(0, lower); seq <= upper; seq++)                        result.add(getBySequence(seq));                } else {                    int start = uidSearch(lower), end = uidSearch(upper);                    if (start < 0)  start = -start - 1;                    if (end < 0)    end = -end - 2;                    for (int seq = start; seq <= end; seq++)                        if ((i4msg = getBySequence(seq + 1)) != null)                            result.add(i4msg);                }            }        }        return result;    }