/** * Consumes a CRLF from the request. * TODO we're being liberal, the spec insists on \r\n for new lines. * * @param request the imap request * @throws ProtocolException */ private void consumeCRLF(ImapRequestLineReader request) throws ProtocolException { char next = request.nextChar(); if (next != '\n') { consumeChar(request, '\r'); } consumeChar(request, '\n'); }
protected byte[] consumeLiteralAsBytes(ImapRequestLineReader request) throws ProtocolException { // The 1st character must be '{' consumeChar(request, '{'); StringBuilder digits = new StringBuilder(); char next = request.nextChar(); while (next != '}' && next != '+') { digits.append(next); request.consume(); next = request.nextChar(); } // If the number is *not* suffixed with a '+', we *are* using a synchronized literal, // and we need to send command continuation request before reading data. boolean synchronizedLiteral = true; // '+' indicates a non-synchronized literal (no command continuation request) if (next == '+') { synchronizedLiteral = false; consumeChar(request, '+'); } // Consume the '}' and the newline consumeChar(request, '}'); consumeCRLF(request); if (synchronizedLiteral) { request.commandContinuationRequest(); } int size = Integer.parseInt(digits.toString()); byte[] buffer = new byte[size]; request.read(buffer); return buffer; }
/** * Reads a quoted string value from the request. */ protected String consumeQuoted(ImapRequestLineReader request) throws ProtocolException { // The 1st character must be '"' consumeChar(request, '"'); StringBuilder quoted = new StringBuilder(); char next = request.nextChar(); while (next != '"') { if (next == '\\') { request.consume(); next = request.nextChar(); if (!isQuotedSpecial(next)) { throw new ProtocolException("Invalid escaped character in quote: '" + next + '\''); } } quoted.append(next); request.consume(); next = request.nextChar(); } consumeChar(request, '"'); return quoted.toString(); }
/** * 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; }
@Override protected void doProcess(final ImapRequestLineReader request, final ImapResponse response, final ImapSession session) { if(!session.getHost().getStore().isQuotaSupported()) { response.commandFailed(this,"Quota is not supported. Activate quota capability first"); } try { String root = parser.mailbox(request); Quota quota = new Quota(root); parser.consumeChar(request, ' '); parser.consumeChar(request, '('); quota.setResourceLimit(parser.astring(request), parser.consumeLong(request)); char c =request.nextWordChar(); if(')' != c) { quota.setResourceLimit(parser.astring(request), parser.consumeLong(request)); } parser.consumeChar(request, ')'); session.getHost().getStore().setQuota( quota, session.getUser().getQualifiedMailboxName()); response.commandComplete(this); } catch (ProtocolException e) { response.commandFailed(this, "Can not parse command"+e.getMessage()); } } }