summaryrefslogtreecommitdiffstats
path: root/provider_src/com/android/email/mail/store/imap
diff options
context:
space:
mode:
Diffstat (limited to 'provider_src/com/android/email/mail/store/imap')
-rw-r--r--provider_src/com/android/email/mail/store/imap/ImapConstants.java4
-rw-r--r--provider_src/com/android/email/mail/store/imap/ImapList.java2
-rw-r--r--provider_src/com/android/email/mail/store/imap/ImapResponse.java7
-rw-r--r--provider_src/com/android/email/mail/store/imap/ImapResponseParser.java37
4 files changed, 47 insertions, 3 deletions
diff --git a/provider_src/com/android/email/mail/store/imap/ImapConstants.java b/provider_src/com/android/email/mail/store/imap/ImapConstants.java
index 9f4d59290..9c94fcf31 100644
--- a/provider_src/com/android/email/mail/store/imap/ImapConstants.java
+++ b/provider_src/com/android/email/mail/store/imap/ImapConstants.java
@@ -46,6 +46,7 @@ public final class ImapConstants {
public static final String COPYUID = "COPYUID";
public static final String CREATE = "CREATE";
public static final String DELETE = "DELETE";
+ public static final String DONE = "DONE";
public static final String EXAMINE = "EXAMINE";
public static final String EXISTS = "EXISTS";
public static final String EXPUNGE = "EXPUNGE";
@@ -58,6 +59,8 @@ public final class ImapConstants {
public static final String FLAGS = "FLAGS";
public static final String FLAGS_SILENT = "FLAGS.SILENT";
public static final String ID = "ID";
+ public static final String IDLE = "IDLE";
+ public static final String IDLING = "idling";
public static final String INBOX = "INBOX";
public static final String INTERNALDATE = "INTERNALDATE";
public static final String LIST = "LIST";
@@ -73,6 +76,7 @@ public final class ImapConstants {
public static final String PREAUTH = "PREAUTH";
public static final String READ_ONLY = "READ-ONLY";
public static final String READ_WRITE = "READ-WRITE";
+ public static final String RECENT = "RECENT";
public static final String RENAME = "RENAME";
public static final String RFC822_SIZE = "RFC822.SIZE";
public static final String SEARCH = "SEARCH";
diff --git a/provider_src/com/android/email/mail/store/imap/ImapList.java b/provider_src/com/android/email/mail/store/imap/ImapList.java
index e28355989..2ddf8227f 100644
--- a/provider_src/com/android/email/mail/store/imap/ImapList.java
+++ b/provider_src/com/android/email/mail/store/imap/ImapList.java
@@ -180,7 +180,7 @@ public class ImapList extends ImapElement {
@Override
public String toString() {
- return mList.toString();
+ return mList != null ? mList.toString() : "[null]";
}
/**
diff --git a/provider_src/com/android/email/mail/store/imap/ImapResponse.java b/provider_src/com/android/email/mail/store/imap/ImapResponse.java
index 9f975f7bf..292ff92b2 100644
--- a/provider_src/com/android/email/mail/store/imap/ImapResponse.java
+++ b/provider_src/com/android/email/mail/store/imap/ImapResponse.java
@@ -77,6 +77,13 @@ public class ImapResponse extends ImapList {
}
/**
+ * @return whether it's an IDLE response.
+ */
+ public boolean isIdling() {
+ return is(0, ImapConstants.IDLING);
+ }
+
+ /**
* @return whether it's an {@code responseType} data response. (i.e. not tagged).
* @param index where {@code responseType} should appear. e.g. 1 for "FETCH"
* @param responseType e.g. "FETCH"
diff --git a/provider_src/com/android/email/mail/store/imap/ImapResponseParser.java b/provider_src/com/android/email/mail/store/imap/ImapResponseParser.java
index 8dd1cf610..5efea3109 100644
--- a/provider_src/com/android/email/mail/store/imap/ImapResponseParser.java
+++ b/provider_src/com/android/email/mail/store/imap/ImapResponseParser.java
@@ -66,6 +66,9 @@ public class ImapResponseParser {
*/
private final ArrayList<ImapResponse> mResponsesToDestroy = new ArrayList<ImapResponse>();
+ private boolean mIdling;
+ private boolean mExpectIdlingResponse;
+
/**
* Exception thrown when we receive BYE. It derives from IOException, so it'll be treated
* in the same way EOF does.
@@ -168,10 +171,17 @@ public class ImapResponseParser {
} catch (RuntimeException e) {
// Parser crash -- log network activities.
onParseError(e);
+ mIdling = false;
throw e;
} catch (IOException e) {
// Network error, or received an unexpected char.
- onParseError(e);
+ // If we are idling don't parse the error, just let the upper layers
+ // handle the exception
+ if (!mIdling) {
+ onParseError(e);
+ } else {
+ mIdling = false;
+ }
throw e;
}
@@ -242,6 +252,14 @@ public class ImapResponseParser {
return ret;
}
+ public void resetIdlingStatus() {
+ mIdling = false;
+ }
+
+ public void expectIdlingResponse() {
+ mExpectIdlingResponse = true;
+ }
+
/**
* Parse and return the response line.
*/
@@ -263,11 +281,26 @@ public class ImapResponseParser {
responseToDestroy = new ImapResponse(null, true);
// If it's continuation request, we don't really care what's in it.
- responseToDestroy.add(new ImapSimpleString(readUntilEol()));
+ // NOTE: specs say the server is supposed to respond to the IDLE command
+ // with a continuation request response. To simplify internal handling,
+ // we'll always construct same response (ignoring the server text response).
+ // Our implementation always returns "+ idling".
+ if (mExpectIdlingResponse) {
+ // Discard the server message and put what we expected
+ readUntilEol();
+ responseToDestroy.add(new ImapSimpleString(ImapConstants.IDLING));
+ } else {
+ responseToDestroy.add(new ImapSimpleString(readUntilEol()));
+ }
// Response has successfully been built. Let's return it.
responseToReturn = responseToDestroy;
responseToDestroy = null;
+
+ mIdling = responseToReturn.isIdling();
+ if (mIdling) {
+ mExpectIdlingResponse = true;
+ }
} else {
// Status response or response data
final String tag;