Improve POP sync.
- Set socket timeout as soon as you open it. This was how IMAP worked, so I just moved the call up one level. This should help one of the sync forever scenarios. - Simplify the SQL query for getting a Mailbox. - Try to load messages that failed to load last time. - Always close the connection to the remote folder. - Don't try to be too clever in fetching the body. This needs to be fixed later for attachements, but for now seems to work better and will let me get more testing. Change-Id: I91b6a6f2a2846b34b1a0c50eb4eb37fc947389ce
This commit is contained in:
parent
cb6bdff95c
commit
9a2686afa2
@ -106,7 +106,6 @@ class ImapConnection {
|
||||
}
|
||||
|
||||
mTransport.open();
|
||||
mTransport.setSoTimeout(MailTransport.SOCKET_READ_TIMEOUT);
|
||||
|
||||
createParser();
|
||||
|
||||
@ -498,7 +497,6 @@ class ImapConnection {
|
||||
executeSimpleCommand(ImapConstants.STARTTLS);
|
||||
|
||||
mTransport.reopenTls();
|
||||
mTransport.setSoTimeout(MailTransport.SOCKET_READ_TIMEOUT);
|
||||
createParser();
|
||||
// Per RFC requirement (3501-6.2.1) gather new capabilities
|
||||
return(queryCapabilities());
|
||||
|
@ -123,7 +123,7 @@ public class MailTransport {
|
||||
}
|
||||
mIn = new BufferedInputStream(mSocket.getInputStream(), 1024);
|
||||
mOut = new BufferedOutputStream(mSocket.getOutputStream(), 512);
|
||||
|
||||
mSocket.setSoTimeout(SOCKET_READ_TIMEOUT);
|
||||
} catch (SSLException e) {
|
||||
if (MailActivityEmail.DEBUG) {
|
||||
Log.d(Logging.LOG_TAG, e.toString());
|
||||
|
@ -205,8 +205,10 @@ public class Pop3Service extends Service {
|
||||
// We'll load them from most recent to oldest
|
||||
for (int i = cnt - 1; i >= 0; i--) {
|
||||
Pop3Message message = unsyncedMessages.get(i);
|
||||
remoteFolder.fetchBody(message, Pop3Store.FETCH_BODY_SANE_SUGGESTED_SIZE / 76,
|
||||
null);
|
||||
// TODO: this fetches the entire message at once. This should go back to trying
|
||||
// to avoid downloading attachments initially. Specifically, the second argument
|
||||
// below used to be Pop3Store.FETCH_BODY_SANE_SUGGESTED_SIZE / 76
|
||||
remoteFolder.fetchBody(message, -1, null);
|
||||
int flag = EmailContent.Message.FLAG_LOADED_COMPLETE;
|
||||
if (!message.isComplete()) {
|
||||
flag = EmailContent.Message.FLAG_LOADED_UNKNOWN;
|
||||
@ -266,10 +268,8 @@ public class Pop3Service extends Service {
|
||||
localUidCursor = resolver.query(
|
||||
EmailContent.Message.CONTENT_URI,
|
||||
LocalMessageInfo.PROJECTION,
|
||||
EmailContent.MessageColumns.ACCOUNT_KEY + "=?" +
|
||||
" AND " + MessageColumns.MAILBOX_KEY + "=?",
|
||||
MessageColumns.MAILBOX_KEY + "=?",
|
||||
new String[] {
|
||||
String.valueOf(account.mId),
|
||||
String.valueOf(mailbox.mId)
|
||||
},
|
||||
null);
|
||||
@ -356,9 +356,9 @@ public class Pop3Service extends Service {
|
||||
remoteUidMap.put(uid, message);
|
||||
LocalMessageInfo localMessage = localMessageMap.get(uid);
|
||||
// localMessage == null -> message has never been created (not even headers)
|
||||
// mFlagLoaded = UNLOADED -> message created, but none of body loaded
|
||||
// mFlagLoaded != FLAG_LOADED_COMPLETE -> message failed to sync completely
|
||||
if (localMessage == null ||
|
||||
(localMessage.mFlagLoaded == EmailContent.Message.FLAG_LOADED_UNLOADED)) {
|
||||
(localMessage.mFlagLoaded != EmailContent.Message.FLAG_LOADED_COMPLETE)) {
|
||||
unsyncedMessages.add(message);
|
||||
}
|
||||
}
|
||||
@ -366,6 +366,7 @@ public class Pop3Service extends Service {
|
||||
if (MailActivityEmail.DEBUG) {
|
||||
Log.d(TAG, "*** Message count is zero??");
|
||||
}
|
||||
remoteFolder.close(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user