Methods Summary |
---|
public static com.sun.mail.iap.Response | byeResponse(java.lang.Exception ex)Return a Response object that looks like a BYE protocol response.
Include the details of the exception in the response string.
String err = "* BYE JavaMail Exception: " + ex.toString();
err = err.replace('\r", ' ").replace('\n", ' ");
Response r = new Response(err);
r.type |= SYNTHETIC;
return r;
|
public java.lang.String | getRest()Return the rest of the response as a string, usually used to
return the arbitrary message text after a NO response.
skipSpaces();
return ASCIIUtility.toString(buffer, index, size);
|
public java.lang.String | getTag()Return the tag, if this is a tagged statement.
return tag;
|
public int | getType()
return type;
|
public boolean | isBAD()
return ((type & TYPE_MASK) == BAD);
|
public boolean | isBYE()
return ((type & TYPE_MASK) == BYE);
|
public boolean | isContinuation()
return ((type & TAG_MASK) == CONTINUATION);
|
public boolean | isNO()
return ((type & TYPE_MASK) == NO);
|
public boolean | isOK()
return ((type & TYPE_MASK) == OK);
|
public boolean | isSynthetic()
return ((type & SYNTHETIC) == SYNTHETIC);
|
public boolean | isTagged()
return ((type & TAG_MASK) == TAGGED);
|
public boolean | isUnTagged()
return ((type & TAG_MASK) == UNTAGGED);
|
private void | parse()
index = 0; // position internal index at start
if (buffer[index] == '+") { // Continuation statement
type |= CONTINUATION;
index += 1; // Position beyond the '+'
return; // return
} else if (buffer[index] == '*") { // Untagged statement
type |= UNTAGGED;
index += 1; // Position beyond the '*'
} else { // Tagged statement
type |= TAGGED;
tag = readAtom(); // read the TAG, index positioned beyond tag
}
int mark = index; // mark
String s = readAtom(); // updates index
if (s == null)
s = ""; // avoid possible NPE
if (s.equalsIgnoreCase("OK"))
type |= OK;
else if (s.equalsIgnoreCase("NO"))
type |= NO;
else if (s.equalsIgnoreCase("BAD"))
type |= BAD;
else if (s.equalsIgnoreCase("BYE"))
type |= BYE;
else
index = mark; // reset
pindex = index;
return;
|
private java.lang.Object | parseString(boolean parseAtoms, boolean returnString)Generic parsing routine that can parse out a Quoted-String,
Literal or Atom and return the parsed token as a String
or a ByteArray. Errors or NIL data will return null.
byte b;
// Skip leading spaces
skipSpaces();
b = buffer[index];
if (b == '"") { // QuotedString
index++; // skip the quote
int start = index;
int copyto = index;
while ((b = buffer[index]) != '"") {
if (b == '\\") // skip escaped byte
index++;
if (index != copyto) { // only copy if we need to
// Beware: this is a destructive copy. I'm
// pretty sure this is OK, but ... ;>
buffer[copyto] = buffer[index];
}
copyto++;
index++;
}
index++; // skip past the terminating quote
if (returnString)
return ASCIIUtility.toString(buffer, start, copyto);
else
return new ByteArray(buffer, start, copyto-start);
} else if (b == '{") { // Literal
int start = ++index; // note the start position
while (buffer[index] != '}")
index++;
int count = 0;
try {
count = ASCIIUtility.parseInt(buffer, start, index);
} catch (NumberFormatException nex) {
// throw new ParsingException();
return null;
}
start = index + 3; // skip "}\r\n"
index = start + count; // position index to beyond the literal
if (returnString) // return as String
return ASCIIUtility.toString(buffer, start, start + count);
else
return new ByteArray(buffer, start, count);
} else if (parseAtoms) { // parse as an ATOM
int start = index; // track this, so that we can use to
// creating ByteArrayInputStream below.
String s = readAtom();
if (returnString)
return s;
else // *very* unlikely
return new ByteArray(buffer, start, index);
} else if (b == 'N" || b == 'n") { // the only valid value is 'NIL'
index += 3; // skip past NIL
return null;
}
return null; // Error
|
public byte | peekByte()
if (index < size)
return buffer[index];
else
return 0; // XXX - how else to signal error?
|
public java.lang.String | readAtom()Extract an ATOM, starting at the current position. Updates
the internal index to beyond the Atom.
return readAtom('\0");
|
public java.lang.String | readAtom(char delim)Extract an ATOM, but stop at the additional delimiter
(if not NUL). Used to parse a response code inside [].
skipSpaces();
if (index >= size) // already at end of response
return null;
/*
* An ATOM is any CHAR delimited by :
* SPACE | CTL | '(' | ')' | '{' | '%' | '*' | '"' | '\'
*/
byte b;
int start = index;
while (index < size && ((b = buffer[index]) > ' ") &&
b != '(" && b != ')" && b != '%" && b != '*" &&
b != '"" && b != '\\" && b != 0x7f &&
(delim == '\0" || b != delim))
index++;
return ASCIIUtility.toString(buffer, start, index);
|
public java.lang.String | readAtomString()Extract an ASTRING, starting at the current position
and return as a String. An ASTRING can be a QuotedString, a
Literal or an Atom
Any errors in parsing returns null
ASTRING := QuotedString | Literal | Atom
return (String)parseString(true, true);
|
public byte | readByte()Return the next byte from this Statement.
if (index < size)
return buffer[index++];
else
return 0; // XXX - how else to signal error?
|
public com.sun.mail.iap.ByteArray | readByteArray()Extract a NSTRING, starting at the current position. Return it as
a ByteArray. The sequence 'NIL' is returned as null
NSTRING := QuotedString | Literal | "NIL"
/*
* Special case, return the data after the continuation uninterpreted.
* It's usually a challenge for an AUTHENTICATE command.
*/
if (isContinuation()) {
skipSpaces();
return new ByteArray(buffer, index, size - index);
}
return (ByteArray)parseString(false, false);
|
public java.io.ByteArrayInputStream | readBytes()Extract a NSTRING, starting at the current position. Return it as
a ByteArrayInputStream. The sequence 'NIL' is returned as null
NSTRING := QuotedString | Literal | "NIL"
ByteArray ba = readByteArray();
if (ba != null)
return ba.toByteArrayInputStream();
else
return null;
|
public long | readLong()Extract a long number, starting at the current position. Updates the
internal index to beyond the number. Returns -1 if a long number
was not found.
// Skip leading spaces
skipSpaces();
int start = index;
while (index < size && Character.isDigit((char)buffer[index]))
index++;
if (index > start) {
try {
return ASCIIUtility.parseLong(buffer, start, index);
} catch (NumberFormatException nex) { }
}
return -1;
|
public int | readNumber()Extract an integer, starting at the current position. Updates the
internal index to beyond the number. Returns -1 if a number was
not found.
// Skip leading spaces
skipSpaces();
int start = index;
while (index < size && Character.isDigit((char)buffer[index]))
index++;
if (index > start) {
try {
return ASCIIUtility.parseInt(buffer, start, index);
} catch (NumberFormatException nex) { }
}
return -1;
|
public java.lang.String | readString(char delim)Read a string as an arbitrary sequence of characters,
stopping at the delimiter Used to read part of a
response code inside [].
skipSpaces();
if (index >= size) // already at end of response
return null;
int start = index;
while (index < size && buffer[index] != delim)
index++;
return ASCIIUtility.toString(buffer, start, index);
|
public java.lang.String | readString()Extract a NSTRING, starting at the current position. Return it as
a String. The sequence 'NIL' is returned as null
NSTRING := QuotedString | Literal | "NIL"
return (String)parseString(false, true);
|
public java.lang.String[] | readStringList()
skipSpaces();
if (buffer[index] != '(") // not what we expected
return null;
index++; // skip '('
Vector v = new Vector();
do {
v.addElement(readString());
} while (buffer[index++] != ')");
int size = v.size();
if (size > 0) {
String[] s = new String[size];
v.copyInto(s);
return s;
} else // empty list
return null;
|
public void | reset()Reset pointer to beginning of response.
index = pindex;
|
public void | skip(int count)
index += count;
|
public void | skipSpaces()
while (index < size && buffer[index] == ' ")
index++;
|
public void | skipToken()Skip to the next space, for use in error recovery while parsing.
while (index < size && buffer[index] != ' ")
index++;
|
public java.lang.String | toString()
return ASCIIUtility.toString(buffer, 0, size);
|