Class CommandParser
- java.lang.Object
-
- com.icegreen.greenmail.imap.commands.CommandParser
-
public class CommandParser extends java.lang.Object
- Version:
- $Revision: 109034 $ QuickFix: Additional date parsing procedures was added in the dateTime method (2009-02-04)
- Author:
- Darrell DeBoer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description 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
-
Field Summary
Fields Modifier and Type Field Description protected org.slf4j.Logger
log
New logger.
-
Constructor Summary
Constructors Constructor Description CommandParser()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
astring(ImapRequestLineReader request)
Reads an argument of type "astring" from the request.java.lang.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 java.lang.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 java.lang.String
consumeQuoted(ImapRequestLineReader request)
Reads a quoted string value from the request.protected java.lang.String
consumeWord(ImapRequestLineReader request, CommandParser.CharacterValidator validator)
Reads the next "word from the request, comprising all characters up to the next SPACE.java.util.Date
date(ImapRequestLineReader request)
Reads a "date" argument from the request.java.util.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.javax.mail.Flags
flagList(ImapRequestLineReader request)
Reads a "flags" argument from the request.protected boolean
isListWildcard(char chr)
java.lang.String
mailbox(ImapRequestLineReader request)
Reads a "mailbox" argument from the request.java.lang.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(java.lang.String flagString, javax.mail.Flags flags)
java.lang.String
tag(ImapRequestLineReader request)
Reads a command "tag" from the request.
-
-
-
Method Detail
-
atom
public java.lang.String atom(ImapRequestLineReader request) throws ProtocolException
Reads an argument of type "atom" from the request.- Throws:
ProtocolException
-
tag
public java.lang.String tag(ImapRequestLineReader request) throws ProtocolException
Reads a command "tag" from the request.- Throws:
ProtocolException
-
astring
public java.lang.String astring(ImapRequestLineReader request) throws ProtocolException
Reads an argument of type "astring" from the request.- Throws:
ProtocolException
-
nstring
public java.lang.String nstring(ImapRequestLineReader request) throws ProtocolException
Reads an argument of type "nstring" from the request.- Throws:
ProtocolException
-
mailbox
public java.lang.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 java.util.Date dateTime(ImapRequestLineReader request) throws ProtocolException
Reads a "date-time" argument from the request. TODO handle timezones properly- Throws:
ProtocolException
-
date
public java.util.Date date(ImapRequestLineReader request) throws ProtocolException
Reads a "date" argument from the request. TODO handle timezones properly- Throws:
ProtocolException
-
consumeWord
protected java.lang.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 java.lang.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 java.lang.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 javax.mail.Flags flagList(ImapRequestLineReader request) throws ProtocolException
Reads a "flags" argument from the request.- Throws:
ProtocolException
-
setFlag
public void setFlag(java.lang.String flagString, javax.mail.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
-
-