public IdRange[] parseIdRange(ImapSession session) throws DecodingException {
  if (session != null) {
    char c=nextWordChar();
    if (c == '$') {
      consume();
      return SearchResUtil.getSavedSequenceSet(session);
    }
  }
  CharacterValidator validator=new MessageSetCharValidator();
  String nextWord=consumeWord(validator,true);
  int commaPos=nextWord.indexOf(',');
  if (commaPos == -1) {
    return new IdRange[]{parseRange(nextWord)};
  }
  ArrayList<IdRange> rangeList=new ArrayList<IdRange>();
  int pos=0;
  while (commaPos != -1) {
    String range=nextWord.substring(pos,commaPos);
    IdRange set=parseRange(range);
    rangeList.add(set);
    pos=commaPos + 1;
    commaPos=nextWord.indexOf(',',pos);
  }
  String range=nextWord.substring(pos);
  rangeList.add(parseRange(range));
  List<IdRange> merged=IdRange.mergeRanges(rangeList);
  return (IdRange[])merged.toArray(new IdRange[merged.size()]);
}

public IdRange [ ] parseIdRange ( ImapSession session ) throws DecodingException { if ( session != null ) { char c = nextWordChar ( ) ; if ( c == '$' ) { consume ( ) ; return SearchResUtil . getSavedSequenceSet ( session ) ; } } CharacterValidator validator = new MessageSetCharValidator ( ) ; String nextWord = consumeWord ( validator , true ) ; int commaPos = nextWord . indexOf ( ',' ) ; if ( commaPos == - 1 ) { return new IdRange [ ] { parseRange ( nextWord ) } ; } ArrayList < IdRange > rangeList = new ArrayList < IdRange > ( ) ; int pos = 0 ; while ( commaPos != - 1 ) { String range = nextWord . substring ( pos , commaPos ) ; IdRange set = parseRange ( range ) ; rangeList . add ( set ) ; pos = commaPos + 1 ; commaPos = nextWord . indexOf ( ',' , pos ) ; } String range = nextWord . substring ( pos ) ; rangeList . add ( parseRange ( range ) ) ; List < IdRange > merged = IdRange . mergeRanges ( rangeList ) ; return ( IdRange [ ] ) merged . toArray ( new IdRange [ merged . size ( ) ] ) ; }
reads a " message set " argument , and parses into an idset . this also support the use of $ as sequence - set as stated in searchres rfc5182
