Class CommandParser
- java.lang.Object
-
- com.icegreen.greenmail.imap.commands.CommandParser
-
public class CommandParser extends Object
- Version:
- $Revision: 109034 $
- Author:
- Darrell DeBoer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classCommandParser.AtomCharValidatorprotected static interfaceCommandParser.CharacterValidatorProvides the ability to ensure characters are part of a permitted set.protected static classCommandParser.DigitCharValidatorprotected static classCommandParser.NoopCharValidator
-
Constructor Summary
Constructors Constructor Description CommandParser()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringastring(ImapRequestLineReader request)Reads an argument of type "astring" from the request.Stringatom(ImapRequestLineReader request)Reads an argument of type "atom" from the request.StringatomOnly(ImapRequestLineReader request)Reads an argument of type "atom" from the request.protected voidconsumeChar(ImapRequestLineReader request, char expected)Consumes the next character in the request, checking that it matches the expected one.protected StringconsumeLiteral(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 byte[]consumeLiteralAsBytes(ImapRequestLineReader request)longconsumeLong(ImapRequestLineReader request)protected StringconsumeQuoted(ImapRequestLineReader request)Reads a quoted string value from the request.protected StringconsumeWord(ImapRequestLineReader request)Reads the next "word" from the request, comprising all characters up to the next SPACE.protected StringconsumeWord(ImapRequestLineReader request, CommandParser.CharacterValidator validator)Reads the next "word" from the request, comprising all characters up to the next SPACE.protected StringconsumeWordOnly(ImapRequestLineReader request, CommandParser.CharacterValidator validator)Reads the next "word from the request, comprising all characters up to the next SPACE.DatedateTime(ImapRequestLineReader request)Reads a "date-time" argument from the request.voidendLine(ImapRequestLineReader request)Consumes the request up to and including the eno-of-line.jakarta.mail.FlagsflagList(ImapRequestLineReader request)Reads a "flags" argument from the request.protected booleanisAtomSpecial(char next)static booleanisCrOrLf(char chr)Checks if character is either CR or LF.protected booleanisListWildcard(char chr)Stringmailbox(ImapRequestLineReader request)Reads a "mailbox" argument from the request.Stringnstring(ImapRequestLineReader request)Reads an argument of type "nstring" from the request.longnumber(ImapRequestLineReader request)Reads an argument of type "number" from the request.longnzNumber(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.voidsetFlag(String flagString, jakarta.mail.Flags flags)Stringstring(ImapRequestLineReader request, Charset charset)Reads an argument of type "string" from the request.Stringtag(ImapRequestLineReader request)Reads a command "tag" from the request.
-
-
-
Method Detail
-
atom
public String atom(ImapRequestLineReader request) throws ProtocolException
Reads an argument of type "atom" from the request.- Throws:
ProtocolException
-
atomOnly
public String atomOnly(ImapRequestLineReader request) throws ProtocolException
Reads an argument of type "atom" from the request. Stops reading when non-atom chars are read.- 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
-
string
public String string(ImapRequestLineReader request, Charset charset) throws ProtocolException
Reads an argument of type "string" from the request.string = quoted / literal
- Throws:
ProtocolException
-
nstring
public String nstring(ImapRequestLineReader request) throws ProtocolException
Reads an argument of type "nstring" from the request. https://tools.ietf.org/html/rfc3501#page-88 : nstring = string / nil nil = "NIL"- 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.- Throws:
ProtocolException
-
consumeWord
protected String consumeWord(ImapRequestLineReader request) throws ProtocolException
Reads the next "word" from the request, comprising all characters up to the next SPACE.- 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
-
consumeWordOnly
protected String consumeWordOnly(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 if invalid characters are encountered these are not consumed.- Throws:
ProtocolException
-
consumeLong
public long consumeLong(ImapRequestLineReader request) throws ProtocolException
- 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
-
consumeLiteralAsBytes
protected byte[] consumeLiteralAsBytes(ImapRequestLineReader request) throws ProtocolException
- 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
-
flagList
public jakarta.mail.Flags flagList(ImapRequestLineReader request) throws ProtocolException
Reads a "flags" argument from the request.- Throws:
ProtocolException
-
setFlag
public void setFlag(String flagString, jakarta.mail.Flags flags)
-
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)
-
isCrOrLf
public static boolean isCrOrLf(char chr)
Checks if character is either CR or LF.- Parameters:
chr- the character- Returns:
- true, if either CR or LF.
-
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
-
isAtomSpecial
protected boolean isAtomSpecial(char next)
-
-