1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-02-15 06:30:17 -05:00

Miscellaneous cleanup in EAS support.

This commit is contained in:
Kris Wong 2012-01-05 20:48:09 -05:00
parent 9b3e4cbcf0
commit e7674272f9
4 changed files with 42 additions and 92 deletions

View File

@ -9,5 +9,5 @@
<classpathentry kind="lib" path="libs/jzlib-1.0.7.jar"/> <classpathentry kind="lib" path="libs/jzlib-1.0.7.jar"/>
<classpathentry kind="lib" path="libs/jutf7-1.0.1-SNAPSHOT.jar"/> <classpathentry kind="lib" path="libs/jutf7-1.0.1-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="libs/htmlcleaner-2.2.jar"/> <classpathentry kind="lib" path="libs/htmlcleaner-2.2.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>

View File

@ -11,5 +11,5 @@
split.density=false split.density=false
java.encoding=utf8 java.encoding=utf8
# Project target. # Project target.
target=android-9 target=android-10
extensible.libs.classpath=compile-only-libs extensible.libs.classpath=compile-only-libs

View File

@ -88,7 +88,7 @@ public class EasStore extends Store {
// This key is sent the first time we sync the folder hierarchy, and also the first time // This key is sent the first time we sync the folder hierarchy, and also the first time
// we sync the items any "collection" (emails in a folder). // we sync the items any "collection" (emails in a folder).
private static final String INITIAL_SYNC_KEY = "0"; public static final String INITIAL_SYNC_KEY = "0";
private static final String PING_COMMAND = "Ping"; private static final String PING_COMMAND = "Ping";
private static final String PROVISION_COMMAND = "Provision"; private static final String PROVISION_COMMAND = "Provision";
@ -545,11 +545,8 @@ public class EasStore extends Store {
try { try {
init(); init();
} }
catch (IOException e) { catch (Exception e) {
e.printStackTrace(); Log.e(K9.LOG_TAG, "Exception encountered while initializing EasStore", e);
}
catch (MessagingException e) {
e.printStackTrace();
} }
} }
return mProtocolVersionDouble; return mProtocolVersionDouble;
@ -585,7 +582,7 @@ public class EasStore extends Store {
} }
} }
catch (MessagingException e) { catch (MessagingException e) {
e.printStackTrace(); Log.e(K9.LOG_TAG, "Exception encountered while provisioning in EasStore", e);
} }
} }
return response; return response;
@ -779,13 +776,9 @@ public class EasStore extends Store {
} }
} else if (isProvisionError(code)) { } else if (isProvisionError(code)) {
// If the sync error is a provisioning failure (perhaps the policies changed), // If the sync error is a provisioning failure (perhaps the policies changed),
// let's try the provisioning procedure // let's try the provisioning procedure.
// Provisioning must only be attempted for the account mailbox - trying to
// provision any other mailbox may result in race conditions and the creation
// of multiple policy keys.
if (!tryProvision()) { if (!tryProvision()) {
// Set the appropriate failure status throw new MessagingException("Unable to provision while tring to fetch the folder list");
throw new RuntimeException();
} else { } else {
// If we succeeded, try again... // If we succeeded, try again...
return getInitialFolderList(); return getInitialFolderList();
@ -829,11 +822,12 @@ public class EasStore extends Store {
mAccount.setSentFolderName(folder.getRemoteName()); mAccount.setSentFolderName(folder.getRemoteName());
break; break;
case FolderSyncParser.OUTBOX_TYPE: case FolderSyncParser.OUTBOX_TYPE:
// Outbox folder is not synced. // Outbox folder is not sync'd.
break; break;
} }
} }
// We updated the account setting above, now write the settings to the DB.
mAccount.saveFolderNames(Preferences.getPreferences(K9.app.getApplicationContext())); mAccount.saveFolderNames(Preferences.getPreferences(K9.app.getApplicationContext()));
return folderList; return folderList;
@ -878,7 +872,7 @@ public class EasStore extends Store {
} }
} }
} catch (MessagingException e) { } catch (MessagingException e) {
e.printStackTrace(); Log.e(K9.LOG_TAG, "Exception encountered while restoring folders from the local store", e);
} }
} }
@ -888,7 +882,7 @@ public class EasStore extends Store {
try { try {
getInitialFolderList(); getInitialFolderList();
} catch (MessagingException e) { } catch (MessagingException e) {
e.printStackTrace(); Log.e(K9.LOG_TAG, "Exception encountered while fetching the initial folder list", e);
} }
} }
synchronized (mFolderList) { synchronized (mFolderList) {
@ -1236,6 +1230,12 @@ public class EasStore extends Store {
EasEmailSyncParser parser = new EasEmailSyncParser(is, this, mAccount); EasEmailSyncParser parser = new EasEmailSyncParser(is, this, mAccount);
moreAvailable = parser.parse(); moreAvailable = parser.parse();
easMessages.addAll(parser.getMessages()); easMessages.addAll(parser.getMessages());
// If we got a new sync key from the server, make sure to update our member.
String newKey = parser.getNewSyncKey();
if (newKey != null) {
setSyncKey(newKey);
}
} else { } else {
Log.d(K9.LOG_TAG, "Empty input stream in sync command response"); Log.d(K9.LOG_TAG, "Empty input stream in sync command response");
} }
@ -1669,7 +1669,13 @@ public class EasStore extends Store {
InputStream is = resp.getEntity().getContent(); InputStream is = resp.getEntity().getContent();
if (is != null) { if (is != null) {
EasEmailSyncParser syncParser = new EasEmailSyncParser(is, folder, folder.getAccount()); EasEmailSyncParser syncParser = new EasEmailSyncParser(is, folder, folder.getAccount());
parseResponse(syncParser, is); syncParser.parse();
// If we got a new sync key from the server, make sure to update our member.
String newKey = syncParser.getNewSyncKey();
if (newKey != null) {
folder.setSyncKey(newKey);
}
} else { } else {
Log.d(K9.LOG_TAG, "Empty input stream in sync command response"); Log.d(K9.LOG_TAG, "Empty input stream in sync command response");
} }
@ -1705,9 +1711,5 @@ public class EasStore extends Store {
} }
abstract void prepareCommand(Serializer s) throws IOException; abstract void prepareCommand(Serializer s) throws IOException;
void parseResponse(EasEmailSyncParser syncParser, InputStream is) throws IOException, MessagingException {
syncParser.parse();
}
} }
} }

View File

@ -21,13 +21,12 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Arrays; import java.util.Arrays;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.util.Log; import android.util.Log;
import com.fsck.k9.Account; import com.fsck.k9.Account;
import com.fsck.k9.K9; import com.fsck.k9.K9;
import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.store.EasStore;
import com.fsck.k9.mail.store.EasStore.EasFolder; import com.fsck.k9.mail.store.EasStore.EasFolder;
/** /**
@ -37,12 +36,9 @@ import com.fsck.k9.mail.store.EasStore.EasFolder;
* *
*/ */
public abstract class AbstractSyncParser extends Parser { public abstract class AbstractSyncParser extends Parser {
protected EasFolder mFolder; protected EasFolder mFolder;
protected Account mAccount; protected Account mAccount;
protected ContentResolver mContentResolver; protected String mNewSyncKey = null;
private boolean mLooping;
public AbstractSyncParser(InputStream in, EasFolder folder, Account account) throws IOException { public AbstractSyncParser(InputStream in, EasFolder folder, Account account) throws IOException {
super(in); super(in);
@ -50,6 +46,10 @@ public abstract class AbstractSyncParser extends Parser {
mAccount = account; mAccount = account;
} }
public String getNewSyncKey() {
return mNewSyncKey;
}
/** /**
* Read, parse, and act on incoming commands from the Exchange server * Read, parse, and act on incoming commands from the Exchange server
* @throws IOException if the connection is broken * @throws IOException if the connection is broken
@ -74,10 +74,6 @@ public abstract class AbstractSyncParser extends Parser {
*/ */
public abstract void wipe(); public abstract void wipe();
public boolean isLooping() {
return mLooping;
}
/** /**
* Loop through the top-level structure coming from the Exchange server * Loop through the top-level structure coming from the Exchange server
* Sync keys and the more available flag are handled here, whereas specific data parsing * Sync keys and the more available flag are handled here, whereas specific data parsing
@ -87,21 +83,16 @@ public abstract class AbstractSyncParser extends Parser {
public boolean parse() throws IOException, MessagingException { public boolean parse() throws IOException, MessagingException {
int status; int status;
boolean moreAvailable = false; boolean moreAvailable = false;
boolean newSyncKey = false;
int interval = MailboxAdapter.mSyncInterval; // If we're not at the top of the XML tree, throw an exception.
mLooping = false;
// If we're not at the top of the xml tree, throw an exception
if (nextTag(START_DOCUMENT) != Tags.SYNC_SYNC) { if (nextTag(START_DOCUMENT) != Tags.SYNC_SYNC) {
throw new EasParserException(); throw new EasParserException();
} }
boolean mailboxUpdated = false; // Loop here through the remaining XML
ContentValues cv = new ContentValues();
// Loop here through the remaining xml
while (nextTag(START_DOCUMENT) != END_DOCUMENT) { while (nextTag(START_DOCUMENT) != END_DOCUMENT) {
if (tag == Tags.SYNC_COLLECTION || tag == Tags.SYNC_COLLECTIONS) { if (tag == Tags.SYNC_COLLECTION || tag == Tags.SYNC_COLLECTIONS) {
// Ignore these tags, since we've only got one collection syncing in this loop // Ignore these tags, since we've only got one collection sync'ing in this loop
} else if (tag == Tags.SYNC_STATUS) { } else if (tag == Tags.SYNC_STATUS) {
// Status = 1 is success; everything else is a failure // Status = 1 is success; everything else is a failure
status = getValueInt(); status = getValueInt();
@ -109,19 +100,17 @@ public abstract class AbstractSyncParser extends Parser {
Log.e(K9.LOG_TAG, "Sync failed: " + status); Log.e(K9.LOG_TAG, "Sync failed: " + status);
// Status = 3 means invalid sync key // Status = 3 means invalid sync key
if (status == 3) { if (status == 3) {
// Must delete all of the data and start over with syncKey of "0" // Must delete all of the data and start over with syncKey of "0".
mFolder.setSyncKey("0"); mNewSyncKey = EasStore.INITIAL_SYNC_KEY;
// Make this a push box through the first sync
// TODO Make frequency conditional on user settings!
MailboxAdapter.mSyncInterval = MailboxAdapter.CHECK_INTERVAL_PUSH;
Log.e(K9.LOG_TAG, "Bad sync key; RESET and delete data"); Log.e(K9.LOG_TAG, "Bad sync key; RESET and delete data");
wipe(); wipe();
// Indicate there's more so that we'll start syncing again
// Indicate there's more so that we'll start sync'ing again.
moreAvailable = true; moreAvailable = true;
} else if (status == 8) { } else if (status == 8) {
// This is Bad; it means the server doesn't recognize the serverId it // This is Bad; it means the server doesn't recognize the serverId it
// sent us. What's needed is a refresh of the folder list. // sent us. What's needed is a refresh of the folder list.
// SyncManager.reloadFolderList(mContext, mAccount.mId, true); // EASTODO: SyncManager.reloadFolderList(mContext, mAccount.mId, true);
} }
// TODO Look at other error codes and consider what's to be done // TODO Look at other error codes and consider what's to be done
} }
@ -138,57 +127,17 @@ public abstract class AbstractSyncParser extends Parser {
String newKey = getValue(); String newKey = getValue();
userLog("Parsed key for ", mFolder.toString(), ": ", newKey); userLog("Parsed key for ", mFolder.toString(), ": ", newKey);
if (!newKey.equals(mFolder.getSyncKey())) { if (!newKey.equals(mFolder.getSyncKey())) {
mFolder.setSyncKey(newKey); mNewSyncKey = newKey;
mailboxUpdated = true;
newSyncKey = true;
}
// If we were pushing (i.e. auto-start), now we'll become ping-triggered
if (MailboxAdapter.mSyncInterval == MailboxAdapter.CHECK_INTERVAL_PUSH) {
MailboxAdapter.mSyncInterval = MailboxAdapter.CHECK_INTERVAL_PING;
} }
} else { } else {
skipTag(); skipTag();
} }
} }
// If we don't have a new sync key, ignore moreAvailable (or we'll loop)
if (moreAvailable && !newSyncKey) {
mLooping = true;
}
// Commit any changes // Commit any changes
commit(); commit();
boolean abortSyncs = false; // Let the caller know that there's more to do.
// // If the sync interval has changed, we need to save it
// if (mMailbox.mSyncInterval != interval) {
// cv.put(MailboxColumns.SYNC_INTERVAL, mMailbox.mSyncInterval);
// mailboxUpdated = true;
// // If there are changes, and we were bounced from push/ping, try again
// } else if (mService.mChangeCount > 0 &&
// mAccount.mSyncInterval == Account.CHECK_INTERVAL_PUSH &&
// mMailbox.mSyncInterval > 0) {
// userLog("Changes found to ping loop mailbox ", mMailbox.mDisplayName, ": will ping.");
// cv.put(MailboxColumns.SYNC_INTERVAL, Mailbox.CHECK_INTERVAL_PING);
// mailboxUpdated = true;
// abortSyncs = true;
// }
//
// if (mailboxUpdated) {
// synchronized (mService.getSynchronizer()) {
// if (!mService.isStopped()) {
// mMailbox.update(mContext, cv);
// }
// }
// }
//
// if (abortSyncs) {
// userLog("Aborting account syncs due to mailbox change to ping...");
// SyncManager.stopAccountSyncs(mAccount.mId);
// }
// Let the caller know that there's more to do
userLog("Returning moreAvailable = " + moreAvailable); userLog("Returning moreAvailable = " + moreAvailable);
return moreAvailable; return moreAvailable;
} }
@ -200,5 +149,4 @@ public abstract class AbstractSyncParser extends Parser {
void userLog(String string, int num, String string2) { void userLog(String string, int num, String string2) {
Log.i(K9.LOG_TAG, string + num + string2); Log.i(K9.LOG_TAG, string + num + string2);
} }
} }