1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-02-14 06:00:21 -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/jutf7-1.0.1-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="libs/htmlcleaner-2.2.jar"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@ -11,5 +11,5 @@
split.density=false
java.encoding=utf8
# Project target.
target=android-9
target=android-10
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
// 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 PROVISION_COMMAND = "Provision";
@ -545,11 +545,8 @@ public class EasStore extends Store {
try {
init();
}
catch (IOException e) {
e.printStackTrace();
}
catch (MessagingException e) {
e.printStackTrace();
catch (Exception e) {
Log.e(K9.LOG_TAG, "Exception encountered while initializing EasStore", e);
}
}
return mProtocolVersionDouble;
@ -585,7 +582,7 @@ public class EasStore extends Store {
}
}
catch (MessagingException e) {
e.printStackTrace();
Log.e(K9.LOG_TAG, "Exception encountered while provisioning in EasStore", e);
}
}
return response;
@ -779,13 +776,9 @@ public class EasStore extends Store {
}
} else if (isProvisionError(code)) {
// If the sync error is a provisioning failure (perhaps the policies changed),
// 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.
// let's try the provisioning procedure.
if (!tryProvision()) {
// Set the appropriate failure status
throw new RuntimeException();
throw new MessagingException("Unable to provision while tring to fetch the folder list");
} else {
// If we succeeded, try again...
return getInitialFolderList();
@ -829,11 +822,12 @@ public class EasStore extends Store {
mAccount.setSentFolderName(folder.getRemoteName());
break;
case FolderSyncParser.OUTBOX_TYPE:
// Outbox folder is not synced.
// Outbox folder is not sync'd.
break;
}
}
// We updated the account setting above, now write the settings to the DB.
mAccount.saveFolderNames(Preferences.getPreferences(K9.app.getApplicationContext()));
return folderList;
@ -878,7 +872,7 @@ public class EasStore extends Store {
}
}
} 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 {
getInitialFolderList();
} catch (MessagingException e) {
e.printStackTrace();
Log.e(K9.LOG_TAG, "Exception encountered while fetching the initial folder list", e);
}
}
synchronized (mFolderList) {
@ -1236,6 +1230,12 @@ public class EasStore extends Store {
EasEmailSyncParser parser = new EasEmailSyncParser(is, this, mAccount);
moreAvailable = parser.parse();
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 {
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();
if (is != null) {
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 {
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;
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.util.Arrays;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.util.Log;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.store.EasStore;
import com.fsck.k9.mail.store.EasStore.EasFolder;
/**
@ -37,18 +36,19 @@ import com.fsck.k9.mail.store.EasStore.EasFolder;
*
*/
public abstract class AbstractSyncParser extends Parser {
protected EasFolder mFolder;
protected Account mAccount;
protected ContentResolver mContentResolver;
private boolean mLooping;
protected String mNewSyncKey = null;
public AbstractSyncParser(InputStream in, EasFolder folder, Account account) throws IOException {
super(in);
mFolder = folder;
mAccount = account;
}
public String getNewSyncKey() {
return mNewSyncKey;
}
/**
* Read, parse, and act on incoming commands from the Exchange server
@ -74,10 +74,6 @@ public abstract class AbstractSyncParser extends Parser {
*/
public abstract void wipe();
public boolean isLooping() {
return mLooping;
}
/**
* 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
@ -87,21 +83,16 @@ public abstract class AbstractSyncParser extends Parser {
public boolean parse() throws IOException, MessagingException {
int status;
boolean moreAvailable = false;
boolean newSyncKey = false;
int interval = MailboxAdapter.mSyncInterval;
mLooping = false;
// If we're not at the top of the xml tree, throw an exception
// If we're not at the top of the XML tree, throw an exception.
if (nextTag(START_DOCUMENT) != Tags.SYNC_SYNC) {
throw new EasParserException();
}
boolean mailboxUpdated = false;
ContentValues cv = new ContentValues();
// Loop here through the remaining xml
// Loop here through the remaining XML
while (nextTag(START_DOCUMENT) != END_DOCUMENT) {
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) {
// Status = 1 is success; everything else is a failure
status = getValueInt();
@ -109,19 +100,17 @@ public abstract class AbstractSyncParser extends Parser {
Log.e(K9.LOG_TAG, "Sync failed: " + status);
// Status = 3 means invalid sync key
if (status == 3) {
// Must delete all of the data and start over with syncKey of "0"
mFolder.setSyncKey("0");
// Make this a push box through the first sync
// TODO Make frequency conditional on user settings!
MailboxAdapter.mSyncInterval = MailboxAdapter.CHECK_INTERVAL_PUSH;
// Must delete all of the data and start over with syncKey of "0".
mNewSyncKey = EasStore.INITIAL_SYNC_KEY;
Log.e(K9.LOG_TAG, "Bad sync key; RESET and delete data");
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;
} else if (status == 8) {
// 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.
// 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
}
@ -138,57 +127,17 @@ public abstract class AbstractSyncParser extends Parser {
String newKey = getValue();
userLog("Parsed key for ", mFolder.toString(), ": ", newKey);
if (!newKey.equals(mFolder.getSyncKey())) {
mFolder.setSyncKey(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;
mNewSyncKey = newKey;
}
} else {
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();
boolean abortSyncs = false;
// // 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
// Let the caller know that there's more to do.
userLog("Returning moreAvailable = " + moreAvailable);
return moreAvailable;
}
@ -200,5 +149,4 @@ public abstract class AbstractSyncParser extends Parser {
void userLog(String string, int num, String string2) {
Log.i(K9.LOG_TAG, string + num + string2);
}
}