/** * Reads an argument of type "atom" from the request. */ public String atom(ImapRequestLineReader request) throws ProtocolException { return consumeWord(request, new AtomCharValidator()); }
/** * Reads a command "tag" from the request. */ public String tag(ImapRequestLineReader request) throws ProtocolException { CharacterValidator validator = new TagCharValidator(); return consumeWord(request, validator); }
/** * Reads an argument of type "number" from the request. */ public long number(ImapRequestLineReader request) throws ProtocolException { String digits = consumeWord(request, new DigitCharValidator()); return Long.parseLong(digits); }
/** * Reads a "message set" argument, and parses into an IdSet. * Currently only supports a single range of values. */ public IdRange[] parseIdRange(ImapRequestLineReader request) throws ProtocolException { CharacterValidator validator = new MessageSetCharValidator(); String nextWord = consumeWord(request, validator); int commaPos = nextWord.indexOf(','); if (commaPos == -1) { return new IdRange[]{IdRange.parseRange(nextWord)}; } List<IdRange> rangeList = new ArrayList<>(); int pos = 0; while (commaPos != -1) { String range = nextWord.substring(pos, commaPos); IdRange set = IdRange.parseRange(range); rangeList.add(set); pos = commaPos + 1; commaPos = nextWord.indexOf(',', pos); } String range = nextWord.substring(pos); rangeList.add(IdRange.parseRange(range)); return rangeList.toArray(new IdRange[rangeList.size()]); }
/** * Reads a "flags" argument from the request. */ public Flags flagList(ImapRequestLineReader request) throws ProtocolException { Flags flags = new Flags(); request.nextWordChar(); consumeChar(request, '('); CharacterValidator validator = new NoopCharValidator(); String nextWord = consumeWord(request, validator); while (!nextWord.endsWith(")")) { setFlag(nextWord, flags); nextWord = consumeWord(request, validator); } // Got the closing ")", may be attached to a word. if (nextWord.length() > 1) { setFlag(nextWord.substring(0, nextWord.length() - 1), flags); } return flags; }