com.icegreen.greenmail.imap.commands
Class CommandParser

java.lang.Object
  extended by com.icegreen.greenmail.imap.commands.CommandParser

public class CommandParser
extends Object

Version:
$Revision: 109034 $
Author:
Darrell DeBoer

Nested Class Summary
protected  class CommandParser.ATOM_CHARValidator
           
protected static interface CommandParser.CharacterValidator
          Provides the ability to ensure characters are part of a permitted set.
protected  class CommandParser.DigitCharValidator
           
protected  class CommandParser.NoopCharValidator
           
 
Constructor Summary
CommandParser()
           
 
Method Summary
 String astring(ImapRequestLineReader request)
          Reads an argument of type "astring" from the request.
 String atom(ImapRequestLineReader request)
          Reads an argument of type "atom" from the request.
 byte[] base64(ImapRequestLineReader request)
          Reads a base64 argument from the request.
protected  void consumeChar(ImapRequestLineReader request, char expected)
          Consumes the next character in the request, checking that it matches the expected one.
protected  String consumeLiteral(ImapRequestLineReader request)
          Reads an argument of type "literal" from the request, in the format: "{" charCount "}" CRLF *CHAR8 Note before calling, the request should be positioned so that nextChar is '{'.
protected  String consumeQuoted(ImapRequestLineReader request)
          Reads a quoted string value from the request.
protected  String consumeWord(ImapRequestLineReader request, CommandParser.CharacterValidator validator)
          Reads the next "word from the request, comprising all characters up to the next SPACE.
 Date date(ImapRequestLineReader request)
          Reads a "date" argument from the request.
 Date dateTime(ImapRequestLineReader request)
          Reads a "date-time" argument from the request.
 void endLine(ImapRequestLineReader request)
          Consumes the request up to and including the eno-of-line.
 Flags flagList(ImapRequestLineReader request)
          Reads a "flags" argument from the request.
protected  boolean isListWildcard(char chr)
           
 String mailbox(ImapRequestLineReader request)
          Reads a "mailbox" argument from the request.
 String nstring(ImapRequestLineReader request)
          Reads an argument of type "nstring" from the request.
 long number(ImapRequestLineReader request)
          Reads an argument of type "number" from the request.
 long nzNumber(ImapRequestLineReader request)
          Reads an argument of type "nznumber" (a non-zero number) (NOTE this isn't strictly as per the spec, since the spec disallows numbers such as "0123" as nzNumbers (although it's ok as a "number".
 IdRange[] parseIdRange(ImapRequestLineReader request)
          Reads a "message set" argument, and parses into an IdSet.
 void setFlag(String flagString, Flags flags)
           
 String tag(ImapRequestLineReader request)
          Reads a command "tag" from the request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandParser

public CommandParser()
Method Detail

atom

public String atom(ImapRequestLineReader request)
            throws ProtocolException
Reads an argument of type "atom" from the request.

Throws:
ProtocolException

tag

public String tag(ImapRequestLineReader request)
           throws ProtocolException
Reads a command "tag" from the request.

Throws:
ProtocolException

astring

public String astring(ImapRequestLineReader request)
               throws ProtocolException
Reads an argument of type "astring" from the request.

Throws:
ProtocolException

nstring

public String nstring(ImapRequestLineReader request)
               throws ProtocolException
Reads an argument of type "nstring" from the request.

Throws:
ProtocolException

mailbox

public String mailbox(ImapRequestLineReader request)
               throws ProtocolException
Reads a "mailbox" argument from the request. Not implemented *exactly* as per spec, since a quoted or literal "inbox" still yeilds "INBOX" (ie still case-insensitive if quoted or literal). I think this makes sense.

mailbox ::= "INBOX" / astring ;; INBOX is case-insensitive. All case variants of ;; INBOX (e.g. "iNbOx") MUST be interpreted as INBOX ;; not as an astring.

Throws:
ProtocolException

dateTime

public Date dateTime(ImapRequestLineReader request)
              throws ProtocolException
Reads a "date-time" argument from the request. TODO handle timezones properly

Throws:
ProtocolException

date

public Date date(ImapRequestLineReader request)
          throws ProtocolException
Reads a "date" argument from the request. TODO handle timezones properly

Throws:
ProtocolException

consumeWord

protected String consumeWord(ImapRequestLineReader request,
                             CommandParser.CharacterValidator validator)
                      throws ProtocolException
Reads the next "word from the request, comprising all characters up to the next SPACE. Characters are tested by the supplied CharacterValidator, and an exception is thrown if invalid characters are encountered.

Throws:
ProtocolException

consumeLiteral

protected String consumeLiteral(ImapRequestLineReader request)
                         throws ProtocolException
Reads an argument of type "literal" from the request, in the format: "{" charCount "}" CRLF *CHAR8 Note before calling, the request should be positioned so that nextChar is '{'. Leading whitespace is not skipped in this method.

Throws:
ProtocolException

consumeChar

protected void consumeChar(ImapRequestLineReader request,
                           char expected)
                    throws ProtocolException
Consumes the next character in the request, checking that it matches the expected one. This method should be used when the

Throws:
ProtocolException

consumeQuoted

protected String consumeQuoted(ImapRequestLineReader request)
                        throws ProtocolException
Reads a quoted string value from the request.

Throws:
ProtocolException

base64

public byte[] base64(ImapRequestLineReader request)
              throws ProtocolException
Reads a base64 argument from the request.

Throws:
ProtocolException

flagList

public Flags flagList(ImapRequestLineReader request)
               throws ProtocolException
Reads a "flags" argument from the request.

Throws:
ProtocolException

setFlag

public void setFlag(String flagString,
                    Flags flags)
             throws ProtocolException
Throws:
ProtocolException

number

public long number(ImapRequestLineReader request)
            throws ProtocolException
Reads an argument of type "number" from the request.

Throws:
ProtocolException

nzNumber

public long nzNumber(ImapRequestLineReader request)
              throws ProtocolException
Reads an argument of type "nznumber" (a non-zero number) (NOTE this isn't strictly as per the spec, since the spec disallows numbers such as "0123" as nzNumbers (although it's ok as a "number". I think the spec is a bit shonky.)

Throws:
ProtocolException

isListWildcard

protected boolean isListWildcard(char chr)

endLine

public void endLine(ImapRequestLineReader request)
             throws ProtocolException
Consumes the request up to and including the eno-of-line.

Parameters:
request - The request
Throws:
ProtocolException - If characters are encountered before the endLine.

parseIdRange

public IdRange[] parseIdRange(ImapRequestLineReader request)
                       throws ProtocolException
Reads a "message set" argument, and parses into an IdSet. Currently only supports a single range of values.

Throws:
ProtocolException