1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-25 09:08:49 -05:00

Fixed an issue which caused space characters to throw exceptions when being parsed. Some cosmetic changes, and context sensitivity for EXISTS, RECENT and EXPUNGE responses which have empty token lists.

This commit is contained in:
Apoorv Khatreja 2011-08-04 23:30:27 +05:30
parent 9335dacd46
commit 47bedec410

View File

@ -72,31 +72,23 @@ public class ImapResponseParser {
private void readTokens(ImapResponse response) throws IOException {
response.clear();
Object token;
String firstString = parseAtom();
String firstToken = (String) readToken(response);
response.add(firstString);
response.add(firstToken);
if (mIn.peek() == ' ') {
mIn.read(); //Skip space if parseAtom() didn't do it.
}
skipIfSpace();
if (isStatusResponse(firstString)) {
if (isStatusResponse(firstToken)) {
parseStatusResponse(response);
} else {
while ((token = readToken(response)) != null) {
if (!(token instanceof ImapList)) {
response.add(token);
if (isSizeOrExpungeResponse((String) token)) {
break;
}
}
}
/*
* TODO: Check for responses ("OK", "PREAUTH", "BYE", "NO", "BAD")
* that can contain resp-text tokens. If found, hand over to a special
* method that parses a resp-text token. There's no need to use
* readToken()/parseToken() on that data.
*
* See RFC 3501, Section 9 Formal Syntax (resp-text)
*/
}
response.mCompleted = true;
}
@ -106,9 +98,7 @@ public class ImapResponseParser {
int next = mIn.peek();
if (next == '[') {
parseSequence(parent);
if (mIn.peek() == ' ') { // Skip following space
mIn.read();
}
skipIfSpace();
}
String rest = readStringUntil('\r');
@ -121,6 +111,12 @@ public class ImapResponseParser {
}
void skipIfSpace() throws IOException {
if (mIn.peek() == ' ') {
expect(' ');
}
}
/**
* Reads the next token of the response. The token can be one of: String -
* for NIL, QUOTED, NUMBER, ATOM. Object - for LITERAL.
@ -532,6 +528,12 @@ public class ImapResponseParser {
symbol.equalsIgnoreCase("BYE");
}
public boolean isSizeOrExpungeResponse(String symbol) {
return symbol.equalsIgnoreCase("EXISTS") ||
symbol.equalsIgnoreCase("RECENT") ||
symbol.equalsIgnoreCase("EXPUNGE");
}
public static boolean equalsIgnoreCase(Object o1, Object o2) {
if (o1 != null && o2 != null && o1 instanceof String && o2 instanceof String) {
String s1 = (String)o1;