mirror of
https://github.com/moparisthebest/k-9
synced 2025-01-10 05:08:18 -05:00
Add a new remote_name column to the folders table and port usage of Folder.getName to Folder.getRemoteName where appropriate. Restore folders from the local store when starting K-9 in the EasStore.
This commit is contained in:
parent
825c11f688
commit
84dd851399
@ -149,6 +149,9 @@ public class Account implements BaseAccount {
|
||||
private boolean mSyncRemoteDeletions;
|
||||
private String mCryptoApp;
|
||||
private boolean mCryptoAutoSignature;
|
||||
// The following 2 settings are currently only used by the EasStore.
|
||||
private String mSyncKey;
|
||||
private String mSecurityKey;
|
||||
|
||||
private CryptoProvider mCryptoProvider = null;
|
||||
|
||||
@ -409,10 +412,14 @@ public class Account implements BaseAccount {
|
||||
mCryptoApp = prefs.getString(mUuid + ".cryptoApp", Apg.NAME);
|
||||
mCryptoAutoSignature = prefs.getBoolean(mUuid + ".cryptoAutoSignature", false);
|
||||
mEnabled = prefs.getBoolean(mUuid + ".enabled", true);
|
||||
mSyncKey = prefs.getString(mUuid + ".syncKey", "");
|
||||
mSecurityKey = prefs.getString(mUuid + ".securityKey", "");
|
||||
}
|
||||
|
||||
protected synchronized void delete(Preferences preferences) {
|
||||
String[] uuids = preferences.getPreferences().getString("accountUuids", "").split(",");
|
||||
String uuidString = preferences.getPreferences().getString("accountUuids", "");
|
||||
if (uuidString.contains(mUuid)) {
|
||||
String[] uuids = uuidString.split(",");
|
||||
String[] newUuids = new String[uuids.length - 1];
|
||||
int i = 0;
|
||||
for (String uuid : uuids) {
|
||||
@ -481,6 +488,8 @@ public class Account implements BaseAccount {
|
||||
editor.remove(mUuid + ".cryptoApp");
|
||||
editor.remove(mUuid + ".cryptoAutoSignature");
|
||||
editor.remove(mUuid + ".enabled");
|
||||
editor.remove(mUuid + ".syncKey");
|
||||
editor.remove(mUuid + ".securityKey");
|
||||
editor.remove(mUuid + ".enableMoveButtons");
|
||||
editor.remove(mUuid + ".hideMoveButtonsEnum");
|
||||
for (String type : networkTypes) {
|
||||
@ -489,6 +498,7 @@ public class Account implements BaseAccount {
|
||||
deleteIdentities(preferences.getPreferences(), editor);
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
|
||||
public static int findNewAccountNumber(List<Integer> accountNumbers) {
|
||||
int newAccountNumber = -1;
|
||||
@ -644,6 +654,8 @@ public class Account implements BaseAccount {
|
||||
editor.putString(mUuid + ".cryptoApp", mCryptoApp);
|
||||
editor.putBoolean(mUuid + ".cryptoAutoSignature", mCryptoAutoSignature);
|
||||
editor.putBoolean(mUuid + ".enabled", mEnabled);
|
||||
editor.putString(mUuid + ".syncKey", mSyncKey);
|
||||
editor.putString(mUuid + ".securityKey", mSecurityKey);
|
||||
|
||||
editor.putBoolean(mUuid + ".vibrate", mNotificationSetting.shouldVibrate());
|
||||
editor.putInt(mUuid + ".vibratePattern", mNotificationSetting.getVibratePattern());
|
||||
@ -1466,6 +1478,22 @@ public class Account implements BaseAccount {
|
||||
mCryptoAutoSignature = cryptoAutoSignature;
|
||||
}
|
||||
|
||||
public String getSyncKey() {
|
||||
return mSyncKey;
|
||||
}
|
||||
|
||||
public void setSyncKey(String key) {
|
||||
mSyncKey = key;
|
||||
}
|
||||
|
||||
public String getSecurityKey() {
|
||||
return mSecurityKey;
|
||||
}
|
||||
|
||||
public void setSecurityKey(String key) {
|
||||
mSecurityKey = key;
|
||||
}
|
||||
|
||||
public String getInboxFolderName() {
|
||||
return mInboxFolderName;
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ public class ChooseFolder extends K9ListActivity {
|
||||
ArrayList<String> localFolders = new ArrayList<String>();
|
||||
|
||||
for (Folder folder : folders) {
|
||||
String name = folder.getName();
|
||||
String name = folder.getRemoteName();
|
||||
|
||||
// Inbox needs to be compared case-insensitively
|
||||
if (hideCurrentFolder && (name.equals(mFolder) ||
|
||||
@ -268,7 +268,7 @@ public class ChooseFolder extends K9ListActivity {
|
||||
Log.e(K9.LOG_TAG, "Couldn't get prefs to check for displayability of folder " + folder.getName(), me);
|
||||
}
|
||||
|
||||
localFolders.add(folder.getName());
|
||||
localFolders.add(folder.getRemoteName());
|
||||
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,8 @@ public class FolderInfoHolder implements Comparable<FolderInfoHolder> {
|
||||
|
||||
public void populate(Context context, Folder folder, Account account) {
|
||||
this.folder = folder;
|
||||
this.name = folder.getName();
|
||||
this.name = folder.getRemoteName();
|
||||
this.displayName = folder.getName();
|
||||
this.lastChecked = folder.getLastUpdate();
|
||||
|
||||
this.status = truncateStatus(folder.getStatus());
|
||||
@ -108,23 +109,23 @@ public class FolderInfoHolder implements Comparable<FolderInfoHolder> {
|
||||
}
|
||||
|
||||
if (this.name.equals(account.getDraftsFolderName())) {
|
||||
this.displayName = String.format(context.getString(R.string.special_mailbox_name_drafts_fmt), this.name);
|
||||
this.displayName = String.format(context.getString(R.string.special_mailbox_name_drafts_fmt), this.displayName);
|
||||
}
|
||||
|
||||
if (this.name.equals(account.getTrashFolderName())) {
|
||||
this.displayName = String.format(context.getString(R.string.special_mailbox_name_trash_fmt), this.name);
|
||||
this.displayName = String.format(context.getString(R.string.special_mailbox_name_trash_fmt), this.displayName);
|
||||
}
|
||||
|
||||
if (this.name.equals(account.getSentFolderName())) {
|
||||
this.displayName = String.format(context.getString(R.string.special_mailbox_name_sent_fmt), this.name);
|
||||
this.displayName = String.format(context.getString(R.string.special_mailbox_name_sent_fmt), this.displayName);
|
||||
}
|
||||
|
||||
if (this.name.equals(account.getArchiveFolderName())) {
|
||||
this.displayName = String.format(context.getString(R.string.special_mailbox_name_archive_fmt), this.name);
|
||||
this.displayName = String.format(context.getString(R.string.special_mailbox_name_archive_fmt), this.displayName);
|
||||
}
|
||||
|
||||
if (this.name.equals(account.getSpamFolderName())) {
|
||||
this.displayName = String.format(context.getString(R.string.special_mailbox_name_spam_fmt), this.name);
|
||||
this.displayName = String.format(context.getString(R.string.special_mailbox_name_spam_fmt), this.displayName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -703,9 +703,8 @@ public class FolderList extends K9ListActivity {
|
||||
return mFilteredFolders.get(position);
|
||||
}
|
||||
|
||||
|
||||
public long getItemId(int position) {
|
||||
return mFilteredFolders.get(position).folder.getName().hashCode() ;
|
||||
return mFilteredFolders.get(position).folder.getRemoteName().hashCode();
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
@ -801,7 +800,7 @@ public class FolderList extends K9ListActivity {
|
||||
|
||||
FolderInfoHolder holder = null;
|
||||
|
||||
int folderIndex = getFolderIndex(folder.getName());
|
||||
int folderIndex = getFolderIndex(folder.getRemoteName());
|
||||
if (folderIndex >= 0) {
|
||||
holder = (FolderInfoHolder) getItem(folderIndex);
|
||||
}
|
||||
|
@ -516,8 +516,8 @@ public class MessageList
|
||||
private void setWindowTitle() {
|
||||
String displayName;
|
||||
|
||||
if (mFolderName != null) {
|
||||
displayName = mFolderName;
|
||||
if (mCurrentFolder != null) {
|
||||
displayName = mCurrentFolder.folder.getName();
|
||||
|
||||
if (mAccount.getInboxFolderName().equalsIgnoreCase(displayName)) {
|
||||
displayName = getString(R.string.special_mailbox_name_inbox);
|
||||
@ -525,11 +525,14 @@ public class MessageList
|
||||
displayName = getString(R.string.special_mailbox_name_outbox);
|
||||
}
|
||||
|
||||
String dispString = mAdapter.mListener.formatHeader(MessageList.this, getString(R.string.message_list_title, mAccount.getDescription(), displayName), mUnreadMessageCount, getTimeFormat());
|
||||
String dispString = mAdapter.mListener.formatHeader(MessageList.this,
|
||||
getString(R.string.message_list_title, mAccount.getDescription(), displayName),
|
||||
mUnreadMessageCount, getTimeFormat());
|
||||
setTitle(dispString);
|
||||
} else if (mQueryString != null) {
|
||||
if (mTitle != null) {
|
||||
String dispString = mAdapter.mListener.formatHeader(MessageList.this, mTitle, mUnreadMessageCount, getTimeFormat());
|
||||
String dispString = mAdapter.mListener.formatHeader(MessageList.this, mTitle,
|
||||
mUnreadMessageCount, getTimeFormat());
|
||||
setTitle(dispString);
|
||||
} else {
|
||||
setTitle(getString(R.string.search_results) + ": " + mQueryString);
|
||||
@ -1342,13 +1345,13 @@ public class MessageList
|
||||
}
|
||||
|
||||
private void onToggleRead(MessageInfoHolder holder) {
|
||||
mController.setFlag(holder.message.getFolder().getAccount(), holder.message.getFolder().getName(), new String[] { holder.uid }, Flag.SEEN, !holder.read);
|
||||
mController.setFlag(holder.message.getFolder().getAccount(), holder.message.getFolder().getRemoteName(), new String[] { holder.uid }, Flag.SEEN, !holder.read);
|
||||
holder.read = !holder.read;
|
||||
mHandler.sortMessages();
|
||||
}
|
||||
|
||||
private void onToggleFlag(MessageInfoHolder holder) {
|
||||
mController.setFlag(holder.message.getFolder().getAccount(), holder.message.getFolder().getName(), new String[] { holder.uid }, Flag.FLAGGED, !holder.flagged);
|
||||
mController.setFlag(holder.message.getFolder().getAccount(), holder.message.getFolder().getRemoteName(), new String[] { holder.uid }, Flag.FLAGGED, !holder.flagged);
|
||||
holder.flagged = !holder.flagged;
|
||||
mHandler.sortMessages();
|
||||
}
|
||||
@ -2815,14 +2818,14 @@ public class MessageList
|
||||
final Message message = holder.message;
|
||||
if (first) {
|
||||
first = false;
|
||||
folderName = message.getFolder().getName();
|
||||
folderName = message.getFolder().getRemoteName();
|
||||
account = message.getFolder().getAccount();
|
||||
if ((operation == FolderOperation.MOVE && !mController.isMoveCapable(account)) || (operation == FolderOperation.COPY && !mController.isCopyCapable(account))) {
|
||||
// account is not copy/move capable
|
||||
return;
|
||||
}
|
||||
} else if (!account.equals(message.getFolder().getAccount())
|
||||
|| !folderName.equals(message.getFolder().getName())) {
|
||||
|| !folderName.equals(message.getFolder().getRemoteName())) {
|
||||
// make sure all messages come from the same account/folder?
|
||||
return;
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ public class MessageView extends K9Activity implements OnClickListener {
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (K9.manageBack()) {
|
||||
String folder = (mMessage != null) ? mMessage.getFolder().getName() : null;
|
||||
String folder = (mMessage != null) ? mMessage.getFolder().getRemoteName() : null;
|
||||
MessageList.actionHandleFolder(this, mAccount, folder);
|
||||
finish();
|
||||
} else {
|
||||
@ -717,7 +717,7 @@ public class MessageView extends K9Activity implements OnClickListener {
|
||||
private void onFlag() {
|
||||
if (mMessage != null) {
|
||||
mController.setFlag(mAccount,
|
||||
mMessage.getFolder().getName(), new String[] {mMessage.getUid()}, Flag.FLAGGED, !mMessage.isSet(Flag.FLAGGED));
|
||||
mMessage.getFolder().getRemoteName(), new String[] {mMessage.getUid()}, Flag.FLAGGED, !mMessage.isSet(Flag.FLAGGED));
|
||||
try {
|
||||
mMessage.setFlag(Flag.FLAGGED, !mMessage.isSet(Flag.FLAGGED));
|
||||
mMessageView.setHeaders(mMessage, mAccount);
|
||||
|
@ -908,7 +908,7 @@ public class AccountSettings extends K9PreferenceActivity {
|
||||
Iterator <? extends Folder > iter = folders.iterator();
|
||||
while (iter.hasNext()) {
|
||||
Folder folder = iter.next();
|
||||
if (mAccount.getOutboxFolderName().equals(folder.getName())) {
|
||||
if (mAccount.getOutboxFolderName().equals(folder.getRemoteName())) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
|
@ -74,8 +74,7 @@ public class FolderSettings extends K9PreferenceActivity {
|
||||
addPreferencesFromResource(R.xml.folder_settings_preferences);
|
||||
|
||||
Preference category = findPreference(PREFERENCE_TOP_CATERGORY);
|
||||
category.setTitle(folderName);
|
||||
|
||||
category.setTitle(mFolder.getName());
|
||||
|
||||
mInTopGroup = (CheckBoxPreference)findPreference(PREFERENCE_IN_TOP_GROUP);
|
||||
mInTopGroup.setChecked(mFolder.isInTopGroup());
|
||||
|
@ -64,6 +64,7 @@ import com.fsck.k9.mail.store.UnavailableStorageException;
|
||||
import com.fsck.k9.mail.store.LocalStore.LocalFolder;
|
||||
import com.fsck.k9.mail.store.LocalStore.LocalMessage;
|
||||
import com.fsck.k9.mail.store.LocalStore.PendingCommand;
|
||||
import com.fsck.k9.mail.store.EasStore.EasFolder;
|
||||
|
||||
|
||||
/**
|
||||
@ -463,14 +464,27 @@ public class MessagingController implements Runnable {
|
||||
localFolders = localStore.getPersonalNamespaces(false);
|
||||
HashSet<String> localFolderNames = new HashSet<String>();
|
||||
for (Folder localFolder : localFolders) {
|
||||
localFolderNames.add(localFolder.getName());
|
||||
localFolderNames.add(localFolder.getRemoteName());
|
||||
}
|
||||
for (Folder remoteFolder : remoteFolders) {
|
||||
if (localFolderNames.contains(remoteFolder.getName()) == false) {
|
||||
LocalFolder localFolder = localStore.getFolder(remoteFolder.getName());
|
||||
LocalFolder localFolder = null;
|
||||
if (localFolderNames.contains(remoteFolder.getRemoteName()) == false) {
|
||||
localFolder = localStore.getFolder(remoteFolder.getRemoteName(),
|
||||
remoteFolder.getName());
|
||||
foldersToCreate.add(localFolder);
|
||||
} else {
|
||||
for (Folder folder : localFolders) {
|
||||
if (folder.getRemoteName().equals(remoteFolder.getRemoteName())) {
|
||||
localFolder = (LocalFolder)folder;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
remoteFolderNames.add(remoteFolder.getRemoteName());
|
||||
|
||||
if (remoteFolder instanceof EasFolder) {
|
||||
((EasFolder)remoteFolder).setLocalFolder(localFolder, false);
|
||||
}
|
||||
remoteFolderNames.add(remoteFolder.getName());
|
||||
}
|
||||
localStore.createFolders(foldersToCreate, account.getDisplayCount());
|
||||
|
||||
@ -480,8 +494,8 @@ public class MessagingController implements Runnable {
|
||||
* Clear out any folders that are no longer on the remote store.
|
||||
*/
|
||||
for (Folder localFolder : localFolders) {
|
||||
String localFolderName = localFolder.getName();
|
||||
if (!account.isSpecialFolder(localFolderName) && !remoteFolderNames.contains(localFolderName)) {
|
||||
if (!account.isSpecialFolder(localFolder.getRemoteName()) &&
|
||||
!remoteFolderNames.contains(localFolder.getRemoteName())) {
|
||||
localFolder.delete(false);
|
||||
}
|
||||
}
|
||||
@ -511,8 +525,6 @@ public class MessagingController implements Runnable {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* List the messages in the local message store for the given folder asynchronously.
|
||||
*
|
||||
@ -742,9 +754,8 @@ public class MessagingController implements Runnable {
|
||||
public void messageStarted(String message, int number, int ofTotal) {}
|
||||
@Override
|
||||
public void messageFinished(Message message, int number, int ofTotal) {
|
||||
if (!isMessageSuppressed(message.getFolder().getAccount(), message.getFolder().getName(), message)) {
|
||||
if (!isMessageSuppressed(message.getFolder().getAccount(), message.getFolder().getRemoteName(), message)) {
|
||||
List<Message> messages = new ArrayList<Message>();
|
||||
|
||||
messages.add(message);
|
||||
stats.unreadMessageCount += (!message.isSet(Flag.SEEN)) ? 1 : 0;
|
||||
stats.flaggedMessageCount += (message.isSet(Flag.FLAGGED)) ? 1 : 0;
|
||||
@ -1201,7 +1212,7 @@ public class MessagingController implements Runnable {
|
||||
Log.d(K9.LOG_TAG, "Only syncing messages after " + earliestDate);
|
||||
}
|
||||
}
|
||||
final String folder = remoteFolder.getName();
|
||||
final String folder = remoteFolder.getRemoteName();
|
||||
|
||||
int unreadBeforeStart = 0;
|
||||
try {
|
||||
@ -1414,7 +1425,7 @@ public class MessagingController implements Runnable {
|
||||
final AtomicInteger progress,
|
||||
final int todo,
|
||||
FetchProfile fp) throws MessagingException {
|
||||
final String folder = remoteFolder.getName();
|
||||
final String folder = remoteFolder.getRemoteName();
|
||||
|
||||
final Date earliestDate = account.getEarliestPollDate();
|
||||
|
||||
@ -1561,7 +1572,7 @@ public class MessagingController implements Runnable {
|
||||
final AtomicInteger newMessages,
|
||||
final int todo,
|
||||
FetchProfile fp) throws MessagingException {
|
||||
final String folder = remoteFolder.getName();
|
||||
final String folder = remoteFolder.getRemoteName();
|
||||
|
||||
final Date earliestDate = account.getEarliestPollDate();
|
||||
|
||||
@ -1639,7 +1650,7 @@ public class MessagingController implements Runnable {
|
||||
final AtomicInteger newMessages,
|
||||
final int todo,
|
||||
FetchProfile fp) throws MessagingException {
|
||||
final String folder = remoteFolder.getName();
|
||||
final String folder = remoteFolder.getRemoteName();
|
||||
|
||||
final Date earliestDate = account.getEarliestPollDate();
|
||||
|
||||
@ -1763,7 +1774,7 @@ public class MessagingController implements Runnable {
|
||||
final int todo
|
||||
) throws MessagingException {
|
||||
|
||||
final String folder = remoteFolder.getName();
|
||||
final String folder = remoteFolder.getRemoteName();
|
||||
if (remoteFolder.supportsFetchingFlags()) {
|
||||
if (K9.DEBUG)
|
||||
Log.d(K9.LOG_TAG, "SYNC: About to sync flags for "
|
||||
@ -2536,7 +2547,7 @@ public class MessagingController implements Runnable {
|
||||
for (int i = 0; i < messages.size(); i++) {
|
||||
uids[i] = messages.get(i).getUid();
|
||||
}
|
||||
setFlag(account, folder.getName(), uids, flag, newState);
|
||||
setFlag(account, folder.getRemoteName(), uids, flag, newState);
|
||||
}
|
||||
|
||||
});
|
||||
@ -2782,8 +2793,8 @@ public class MessagingController implements Runnable {
|
||||
attachment.setBody(null);
|
||||
}
|
||||
Store remoteStore = account.getRemoteStore();
|
||||
localFolder = localStore.getFolder(message.getFolder().getName());
|
||||
remoteFolder = remoteStore.getFolder(message.getFolder().getName());
|
||||
localFolder = localStore.getFolder(message.getFolder().getRemoteName());
|
||||
remoteFolder = remoteStore.getFolder(message.getFolder().getRemoteName());
|
||||
remoteFolder.open(OpenMode.READ_WRITE);
|
||||
|
||||
//FIXME: This is an ugly hack that won't be needed once the Message objects have been united.
|
||||
@ -3082,7 +3093,7 @@ public class MessagingController implements Runnable {
|
||||
|
||||
PendingCommand command = new PendingCommand();
|
||||
command.command = PENDING_COMMAND_APPEND;
|
||||
command.arguments = new String[] { localSentFolder.getName(), message.getUid() };
|
||||
command.arguments = new String[] { localSentFolder.getRemoteName(), message.getUid() };
|
||||
queuePendingCommand(account, command);
|
||||
processPendingCommands(account);
|
||||
}
|
||||
@ -3341,13 +3352,13 @@ public class MessagingController implements Runnable {
|
||||
public void act(final Account account, final Folder folder,
|
||||
final List<Message> messages) {
|
||||
for (Message message : messages) {
|
||||
suppressMessage(account, folder.getName(), message);
|
||||
suppressMessage(account, folder.getRemoteName(), message);
|
||||
}
|
||||
|
||||
putBackground("deleteMessages", null, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
deleteMessagesSynchronous(account, folder.getName(), messages.toArray(EMPTY_MESSAGE_ARRAY), listener);
|
||||
deleteMessagesSynchronous(account, folder.getRemoteName(), messages.toArray(EMPTY_MESSAGE_ARRAY), listener);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -3515,7 +3526,7 @@ public class MessagingController implements Runnable {
|
||||
Log.d(K9.LOG_TAG, "About to load message " + account.getDescription() + ":" + message.getFolder().getName()
|
||||
+ ":" + message.getUid() + " for sendAlternate");
|
||||
|
||||
loadMessageForView(account, message.getFolder().getName(),
|
||||
loadMessageForView(account, message.getFolder().getRemoteName(),
|
||||
message.getUid(), new MessagingListener() {
|
||||
@Override
|
||||
public void loadMessageForViewBodyAvailable(Account account, String folder, String uid,
|
||||
@ -3760,7 +3771,7 @@ public class MessagingController implements Runnable {
|
||||
// In case multiple Commands get enqueued, don't run more than
|
||||
// once
|
||||
final LocalStore localStore = account.getLocalStore();
|
||||
tLocalFolder = localStore.getFolder(folder.getName());
|
||||
tLocalFolder = localStore.getFolder(folder.getRemoteName());
|
||||
tLocalFolder.open(Folder.OpenMode.READ_WRITE);
|
||||
|
||||
if (!ignoreLastCheckedTime && tLocalFolder.getLastChecked() >
|
||||
@ -3773,7 +3784,7 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
notifyFetchingMail(account, folder);
|
||||
try {
|
||||
synchronizeMailboxSynchronous(account, folder.getName(), listener, null);
|
||||
synchronizeMailboxSynchronous(account, folder.getRemoteName(), listener, null);
|
||||
} finally {
|
||||
notifyFetchingMailCancel(account);
|
||||
}
|
||||
@ -3897,7 +3908,7 @@ public class MessagingController implements Runnable {
|
||||
// But do notify if it's the INBOX (see issue 1817).
|
||||
Folder folder = message.getFolder();
|
||||
if (folder != null) {
|
||||
String folderName = folder.getName();
|
||||
String folderName = folder.getRemoteName();
|
||||
if (!account.getInboxFolderName().equals(folderName) &&
|
||||
(account.getTrashFolderName().equals(folderName)
|
||||
|| account.getDraftsFolderName().equals(folderName)
|
||||
@ -4090,7 +4101,7 @@ public class MessagingController implements Runnable {
|
||||
PendingCommand command = new PendingCommand();
|
||||
command.command = PENDING_COMMAND_APPEND;
|
||||
command.arguments = new String[] {
|
||||
localFolder.getName(),
|
||||
localFolder.getRemoteName(),
|
||||
localMessage.getUid()
|
||||
};
|
||||
queuePendingCommand(account, command);
|
||||
@ -4234,7 +4245,7 @@ public class MessagingController implements Runnable {
|
||||
if (K9.DEBUG)
|
||||
Log.i(K9.LOG_TAG, "Starting pusher for " + account.getDescription() + ":" + folder.getName());
|
||||
|
||||
names.add(folder.getName());
|
||||
names.add(folder.getRemoteName());
|
||||
}
|
||||
|
||||
if (!names.isEmpty()) {
|
||||
@ -4307,7 +4318,7 @@ public class MessagingController implements Runnable {
|
||||
LocalFolder localFolder = null;
|
||||
try {
|
||||
LocalStore localStore = account.getLocalStore();
|
||||
localFolder = localStore.getFolder(remoteFolder.getName());
|
||||
localFolder = localStore.getFolder(remoteFolder.getRemoteName());
|
||||
localFolder.open(OpenMode.READ_WRITE);
|
||||
|
||||
account.setRingNotified(false);
|
||||
@ -4327,7 +4338,7 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
|
||||
for (MessagingListener l : getListeners()) {
|
||||
l.folderStatusChanged(account, remoteFolder.getName(), unreadMessageCount);
|
||||
l.folderStatusChanged(account, remoteFolder.getRemoteName(), unreadMessageCount);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
@ -4342,7 +4353,7 @@ public class MessagingController implements Runnable {
|
||||
Log.e(K9.LOG_TAG, "Unable to set failed status on localFolder", se);
|
||||
}
|
||||
for (MessagingListener l : getListeners()) {
|
||||
l.synchronizeMailboxFailed(account, remoteFolder.getName(), errorMessage);
|
||||
l.synchronizeMailboxFailed(account, remoteFolder.getRemoteName(), errorMessage);
|
||||
}
|
||||
addErrorMessage(account, null, e);
|
||||
} finally {
|
||||
|
@ -44,7 +44,7 @@ public class MessagingControllerPushReceiver implements PushReceiver {
|
||||
if (K9.DEBUG)
|
||||
Log.v(K9.LOG_TAG, "syncFolder(" + folder.getName() + ")");
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
controller.synchronizeMailbox(account, folder.getName(), new MessagingListener() {
|
||||
controller.synchronizeMailbox(account, folder.getRemoteName(), new MessagingListener() {
|
||||
@Override
|
||||
public void synchronizeMailboxFinished(Account account, String folder,
|
||||
int totalMessagesInMailbox, int numNewMessages) {
|
||||
|
@ -86,7 +86,7 @@ public class MessageHelper {
|
||||
target.uid = message.getUid();
|
||||
|
||||
target.account = account.getDescription();
|
||||
target.uri = "email://messages/" + account.getAccountNumber() + "/" + m.getFolder().getName() + "/" + m.getUid();
|
||||
target.uri = "email://messages/" + account.getAccountNumber() + "/" + m.getFolder().getRemoteName() + "/" + m.getUid();
|
||||
|
||||
} catch (MessagingException me) {
|
||||
Log.w(K9.LOG_TAG, "Unable to load message info", me);
|
||||
|
@ -139,6 +139,8 @@ public abstract class Folder {
|
||||
|
||||
public abstract void delete(boolean recurse) throws MessagingException;
|
||||
|
||||
public abstract String getRemoteName();
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public abstract Flag[] getPermanentFlags();
|
||||
@ -193,6 +195,7 @@ public abstract class Folder {
|
||||
public FolderClass getSyncClass() {
|
||||
return getDisplayClass();
|
||||
}
|
||||
|
||||
public FolderClass getPushClass() {
|
||||
return getSyncClass();
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public abstract class Message implements Part, Body {
|
||||
return false;
|
||||
}
|
||||
Message other = (Message)o;
|
||||
return (mFolder.getName().equals(other.getFolder().getName())
|
||||
return (mFolder.getRemoteName().equals(other.getFolder().getRemoteName())
|
||||
&& mFolder.getAccount().getUuid().equals(other.getFolder().getAccount().getUuid())
|
||||
&& mUid.equals(other.getUid()));
|
||||
}
|
||||
@ -62,7 +62,7 @@ public abstract class Message implements Part, Body {
|
||||
final int MULTIPLIER = 31;
|
||||
|
||||
int result = 1;
|
||||
result = MULTIPLIER * result + mFolder.getName().hashCode();
|
||||
result = MULTIPLIER * result + mFolder.getRemoteName().hashCode();
|
||||
result = MULTIPLIER * result + mFolder.getAccount().getUuid().hashCode();
|
||||
result = MULTIPLIER * result + mUid.hashCode();
|
||||
return result;
|
||||
@ -197,7 +197,7 @@ public abstract class Message implements Part, Body {
|
||||
if (mReference == null) {
|
||||
mReference = new MessageReference();
|
||||
mReference.accountUuid = getFolder().getAccount().getUuid();
|
||||
mReference.folderName = getFolder().getName();
|
||||
mReference.folderName = getFolder().getRemoteName();
|
||||
mReference.uid = mUid;
|
||||
}
|
||||
return mReference;
|
||||
|
@ -61,6 +61,7 @@ import com.fsck.k9.mail.Pusher;
|
||||
import com.fsck.k9.mail.Store;
|
||||
import com.fsck.k9.mail.filter.EOLConvertingOutputStream;
|
||||
import com.fsck.k9.mail.internet.MimeMessage;
|
||||
import com.fsck.k9.mail.store.LocalStore.LocalFolder;
|
||||
import com.fsck.k9.mail.store.exchange.Eas;
|
||||
import com.fsck.k9.mail.store.exchange.adapter.EasEmailSyncParser;
|
||||
import com.fsck.k9.mail.store.exchange.adapter.FolderSyncParser;
|
||||
@ -82,6 +83,8 @@ public class EasStore extends Store {
|
||||
|
||||
private static final Message[] EMPTY_MESSAGE_ARRAY = new Message[0];
|
||||
|
||||
private static final String INITIAL_SYNC_KEY = "0";
|
||||
|
||||
static private final String PING_COMMAND = "Ping";
|
||||
// Command timeout is the the time allowed for reading data from an open connection before an
|
||||
// IOException is thrown. After a small added allowance, our watchdog alarm goes off (allowing
|
||||
@ -131,9 +134,6 @@ public class EasStore extends Store {
|
||||
|
||||
private HashMap<String, EasFolder> mFolderList = new HashMap<String, EasFolder>();
|
||||
|
||||
private String mStoreSyncKey = "0";
|
||||
private String mStoreSecuritySyncKey = "0";
|
||||
|
||||
/**
|
||||
* eas://user:password@server:port CONNECTION_SECURITY_NONE
|
||||
* eas+tls://user:password@server:port CONNECTION_SECURITY_TLS_OPTIONAL
|
||||
@ -194,11 +194,19 @@ public class EasStore extends Store {
|
||||
}
|
||||
|
||||
public String getStoreSyncKey() {
|
||||
return mStoreSyncKey;
|
||||
String key = mAccount.getSyncKey();
|
||||
|
||||
// Set the default sync key if it has not yet been set.
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
key = INITIAL_SYNC_KEY;
|
||||
mAccount.setSyncKey(key);
|
||||
}
|
||||
|
||||
public void setStoreSyncKey(String mStoreSyncKey) {
|
||||
this.mStoreSyncKey = mStoreSyncKey;
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setStoreSyncKey(String syncKey) {
|
||||
mAccount.setSyncKey(syncKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -253,7 +261,7 @@ public class EasStore extends Store {
|
||||
// Run second test here for provisioning failures...
|
||||
Serializer s = new Serializer();
|
||||
Log.e(K9.LOG_TAG, "Validate: try folder sync");
|
||||
s.start(Tags.FOLDER_FOLDER_SYNC).start(Tags.FOLDER_SYNC_KEY).text("0")
|
||||
s.start(Tags.FOLDER_FOLDER_SYNC).start(Tags.FOLDER_SYNC_KEY).text(INITIAL_SYNC_KEY)
|
||||
.end().end().done();
|
||||
resp = svc.sendHttpClientPost("FolderSync", s.toByteArray());
|
||||
reclaimConnection(resp);
|
||||
@ -541,9 +549,9 @@ public class EasStore extends Store {
|
||||
// If there's an account in existence, use its key; otherwise (we're creating the
|
||||
// account), send "0". The server will respond with code 449 if there are policies
|
||||
// to be enforced
|
||||
String key = "0";
|
||||
String key = INITIAL_SYNC_KEY;
|
||||
if (mAccount != null) {
|
||||
String accountKey = mStoreSecuritySyncKey;
|
||||
String accountKey = mAccount.getSecurityKey();
|
||||
if (!TextUtils.isEmpty(accountKey)) {
|
||||
key = accountKey;
|
||||
}
|
||||
@ -585,10 +593,18 @@ public class EasStore extends Store {
|
||||
|
||||
@Override
|
||||
public List <? extends Folder> getPersonalNamespaces(boolean forceListAll) throws MessagingException {
|
||||
synchronized (mFolderList) {
|
||||
if (forceListAll || mFolderList.isEmpty()) {
|
||||
if (forceListAll || getStoreSyncKey().equals(INITIAL_SYNC_KEY)) {
|
||||
if (forceListAll) {
|
||||
// Reset the sync key so the Exchange server will return the entire folder list
|
||||
// rather than just changes.
|
||||
setStoreSyncKey(INITIAL_SYNC_KEY);
|
||||
}
|
||||
return getInitialFolderList();
|
||||
} else {
|
||||
synchronized (mFolderList) {
|
||||
if (mFolderList.isEmpty()) {
|
||||
syncFoldersFromLocalStore();
|
||||
}
|
||||
return new ArrayList<EasFolder>(mFolderList.values());
|
||||
}
|
||||
}
|
||||
@ -623,7 +639,7 @@ public class EasStore extends Store {
|
||||
}
|
||||
}
|
||||
|
||||
public List <? extends Folder > getInitialFolderList() throws MessagingException {
|
||||
private List <? extends Folder > getInitialFolderList() throws MessagingException {
|
||||
LinkedList<Folder> folderList = new LinkedList<Folder>();
|
||||
|
||||
try {
|
||||
@ -641,8 +657,7 @@ public class EasStore extends Store {
|
||||
if (len != 0) {
|
||||
InputStream is = entity.getContent();
|
||||
// Returns true if we need to sync again
|
||||
if (new FolderSyncParser(is, this, folderList)
|
||||
.parse()) {
|
||||
if (new FolderSyncParser(is, this, folderList).parse()) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
@ -672,26 +687,29 @@ public class EasStore extends Store {
|
||||
throw new MessagingException("io", e);
|
||||
}
|
||||
|
||||
synchronized (mFolderList) {
|
||||
mFolderList.clear();
|
||||
for (Folder folder : folderList) {
|
||||
mFolderList.put(folder.getName(), (EasFolder) folder);
|
||||
mFolderList.put(folder.getRemoteName(), (EasFolder)folder);
|
||||
}
|
||||
}
|
||||
|
||||
for (Folder folder : folderList) {
|
||||
int type = ((EasFolder) folder).mType;
|
||||
switch (type) {
|
||||
case FolderSyncParser.INBOX_TYPE:
|
||||
String inboxFolderName = folder.getName();
|
||||
String inboxFolderName = folder.getRemoteName();
|
||||
this.mAccount.setAutoExpandFolderName(inboxFolderName);
|
||||
this.mAccount.setInboxFolderName(inboxFolderName);
|
||||
break;
|
||||
case FolderSyncParser.DRAFTS_TYPE:
|
||||
this.mAccount.setDraftsFolderName(folder.getName());
|
||||
this.mAccount.setDraftsFolderName(folder.getRemoteName());
|
||||
break;
|
||||
case FolderSyncParser.DELETED_TYPE:
|
||||
this.mAccount.setTrashFolderName(folder.getName());
|
||||
this.mAccount.setTrashFolderName(folder.getRemoteName());
|
||||
break;
|
||||
case FolderSyncParser.SENT_TYPE:
|
||||
this.mAccount.setSentFolderName(folder.getName());
|
||||
this.mAccount.setSentFolderName(folder.getRemoteName());
|
||||
break;
|
||||
case FolderSyncParser.OUTBOX_TYPE:
|
||||
// outbox folder is not synced
|
||||
@ -708,17 +726,45 @@ public class EasStore extends Store {
|
||||
ProvisionParser pp = canProvision();
|
||||
if (pp != null) {
|
||||
String policyKey = acknowledgeProvision(pp.getPolicyKey(), PROVISION_STATUS_OK);
|
||||
mStoreSecuritySyncKey = policyKey;
|
||||
mAccount.setSecurityKey(policyKey);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Folder getFolder(String name) {
|
||||
private void syncFoldersFromLocalStore() {
|
||||
try {
|
||||
LocalStore localStore = mAccount.getLocalStore();
|
||||
if (localStore != null) {
|
||||
List<? extends Folder> localFolders = localStore.getPersonalNamespaces(false);
|
||||
synchronized (mFolderList) {
|
||||
if (mFolderList.isEmpty()) {
|
||||
for (Folder folder : localFolders) {
|
||||
int type = FolderSyncParser.USER_FOLDER_TYPE;
|
||||
if (folder.getRemoteName().equals(mAccount.getInboxFolderName())) {
|
||||
type = FolderSyncParser.INBOX_TYPE;
|
||||
} else if (folder.getRemoteName().equals(mAccount.getDraftsFolderName())) {
|
||||
type = FolderSyncParser.DRAFTS_TYPE;
|
||||
} else if (folder.getRemoteName().equals(mAccount.getTrashFolderName())) {
|
||||
type = FolderSyncParser.DELETED_TYPE;
|
||||
} else if (folder.getRemoteName().equals(mAccount.getSentFolderName())) {
|
||||
type = FolderSyncParser.SENT_TYPE;
|
||||
}
|
||||
|
||||
EasFolder remoteFolder = new EasFolder(folder.getName(), folder.getRemoteName(), type);
|
||||
mFolderList.put(folder.getRemoteName(), remoteFolder);
|
||||
remoteFolder.setLocalFolder((LocalFolder)folder, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (MessagingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Folder getFolder(String serverId) {
|
||||
if (getStoreSyncKey().equals(INITIAL_SYNC_KEY)) {
|
||||
try {
|
||||
getInitialFolderList();
|
||||
}
|
||||
@ -726,7 +772,11 @@ public class EasStore extends Store {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return mFolderList.get(name);
|
||||
synchronized (mFolderList) {
|
||||
if (mFolderList.isEmpty()) {
|
||||
syncFoldersFromLocalStore();
|
||||
}
|
||||
return mFolderList.get(serverId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -798,11 +848,8 @@ public class EasStore extends Store {
|
||||
|
||||
SchemeRegistry reg = new SchemeRegistry();
|
||||
try {
|
||||
Scheme scheme = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
|
||||
reg.register(scheme);
|
||||
|
||||
scheme = new Scheme("https", new TrustedSocketFactory(mHost, mSecure), 443);
|
||||
reg.register(scheme);
|
||||
reg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
||||
reg.register(new Scheme("https", new TrustedSocketFactory(mHost, mSecure), 443));
|
||||
} catch (NoSuchAlgorithmException nsa) {
|
||||
Log.e(K9.LOG_TAG, "NoSuchAlgorithmException in getHttpClient: " + nsa);
|
||||
throw new MessagingException("NoSuchAlgorithmException in getHttpClient: " + nsa);
|
||||
@ -837,8 +884,8 @@ public class EasStore extends Store {
|
||||
private String mServerId;
|
||||
private int mType;
|
||||
private boolean mIsOpen = false;
|
||||
private int mMessageCount = 0;
|
||||
private String mSyncKey;
|
||||
private String mSyncKey = null;
|
||||
private LocalFolder mLocalFolder = null;
|
||||
|
||||
protected EasStore getStore() {
|
||||
return EasStore.this;
|
||||
@ -846,25 +893,34 @@ public class EasStore extends Store {
|
||||
|
||||
public EasFolder(String name, String serverId, int type) {
|
||||
super(EasStore.this.getAccount());
|
||||
this.mName = name;
|
||||
this.mServerId = serverId;
|
||||
this.mType = type;
|
||||
mName = name;
|
||||
mServerId = serverId;
|
||||
mType = type;
|
||||
}
|
||||
|
||||
public String getSyncKeyUnmodified() {
|
||||
return mSyncKey;
|
||||
public void setLocalFolder(LocalFolder folder, boolean setSyncKey) {
|
||||
mLocalFolder = folder;
|
||||
if (setSyncKey && mLocalFolder != null) {
|
||||
if (mSyncKey != null && !mSyncKey.equals(INITIAL_SYNC_KEY)) {
|
||||
Log.d(K9.LOG_TAG, "Overriding non-default SyncKey: " + mSyncKey);
|
||||
}
|
||||
mSyncKey = mLocalFolder.getPushState();
|
||||
}
|
||||
}
|
||||
|
||||
public String getSyncKey() {
|
||||
public String getSyncKey() throws MessagingException {
|
||||
if (mSyncKey == null) {
|
||||
Log.d(K9.LOG_TAG, "Reset SyncKey to 0");
|
||||
mSyncKey = "0";
|
||||
setSyncKey(INITIAL_SYNC_KEY);
|
||||
}
|
||||
return mSyncKey;
|
||||
}
|
||||
|
||||
public void setSyncKey(String mSyncKey) {
|
||||
this.mSyncKey = mSyncKey;
|
||||
public void setSyncKey(String key) throws MessagingException {
|
||||
mSyncKey = key;
|
||||
if (mLocalFolder != null) {
|
||||
mLocalFolder.setPushState(mSyncKey);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -874,17 +930,17 @@ public class EasStore extends Store {
|
||||
|
||||
@Override
|
||||
public void open(OpenMode mode) throws MessagingException {
|
||||
this.mIsOpen = true;
|
||||
mIsOpen = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyMessages(Message[] messages, Folder folder) throws MessagingException {
|
||||
moveOrCopyMessages(messages, folder.getName(), false);
|
||||
moveOrCopyMessages(messages, folder.getRemoteName(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveMessages(Message[] messages, Folder folder) throws MessagingException {
|
||||
moveOrCopyMessages(messages, folder.getName(), true);
|
||||
moveOrCopyMessages(messages, folder.getRemoteName(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -900,33 +956,7 @@ public class EasStore extends Store {
|
||||
|
||||
private void moveOrCopyMessages(Message[] messages, String folderName, boolean isMove)
|
||||
throws MessagingException {
|
||||
// String[] uids = new String[messages.length];
|
||||
//
|
||||
// for (int i = 0, count = messages.length; i < count; i++) {
|
||||
// uids[i] = messages[i].getUid();
|
||||
// }
|
||||
// String messageBody = "";
|
||||
// HashMap<String, String> headers = new HashMap<String, String>();
|
||||
// HashMap<String, String> uidToUrl = getMessageUrls(uids);
|
||||
// String[] urls = new String[uids.length];
|
||||
//
|
||||
// for (int i = 0, count = uids.length; i < count; i++) {
|
||||
// urls[i] = uidToUrl.get(uids[i]);
|
||||
// if (urls[i] == null && messages[i] instanceof EasMessage) {
|
||||
// EasMessage wdMessage = (EasMessage) messages[i];
|
||||
// urls[i] = wdMessage.getUrl();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// messageBody = getMoveOrCopyMessagesReadXml(urls, isMove);
|
||||
// EasFolder destFolder = (EasFolder) store.getFolder(folderName);
|
||||
// headers.put("Destination", destFolder.mFolderUrl);
|
||||
// headers.put("Brief", "t");
|
||||
// headers.put("If-Match", "*");
|
||||
// String action = (isMove ? "BMOVE" : "BCOPY");
|
||||
// Log.i(K9.LOG_TAG, "Moving " + messages.length + " messages to " + destFolder.mFolderUrl);
|
||||
//
|
||||
// processRequest(mFolderUrl, action, messageBody, headers, false);
|
||||
// EASTODO
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -946,7 +976,7 @@ public class EasStore extends Store {
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return this.mIsOpen;
|
||||
return mIsOpen;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -954,9 +984,14 @@ public class EasStore extends Store {
|
||||
return OpenMode.READ_WRITE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRemoteName() {
|
||||
return mServerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.mName;
|
||||
return mName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -966,8 +1001,7 @@ public class EasStore extends Store {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
this.mMessageCount = 0;
|
||||
this.mIsOpen = false;
|
||||
mIsOpen = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -977,7 +1011,8 @@ public class EasStore extends Store {
|
||||
|
||||
@Override
|
||||
public void delete(boolean recursive) throws MessagingException {
|
||||
throw new Error("WebDavFolder.delete() not implemeneted");
|
||||
// EASTODO
|
||||
throw new Error("EasFolder.delete() not implemeneted");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1000,9 +1035,7 @@ public class EasStore extends Store {
|
||||
}
|
||||
|
||||
private EasEmailSyncParser getMessagesInternal(Message[] messages, FetchProfile fp, MessageRetrievalListener listener,
|
||||
int start, int end) throws IOException,
|
||||
MessagingException {
|
||||
|
||||
int start, int end) throws IOException, MessagingException {
|
||||
Serializer s = new Serializer();
|
||||
EasEmailSyncParser syncParser = null;
|
||||
// EmailSyncAdapter target = new EmailSyncAdapter(this, mAccount);
|
||||
@ -1024,7 +1057,7 @@ public class EasStore extends Store {
|
||||
// appears to cause the server to delay its response in some cases, and this delay
|
||||
// can be long enough to result in an IOException and total failure to sync.
|
||||
// Therefore, we don't send any options with the initial sync.
|
||||
if (!syncKey.equals("0")) {
|
||||
if (!syncKey.equals(INITIAL_SYNC_KEY)) {
|
||||
boolean fetchBodySane = (fp != null) && fp.contains(FetchProfile.Item.BODY_SANE);
|
||||
boolean fetchBody = (fp != null) && fp.contains(FetchProfile.Item.BODY);
|
||||
|
||||
@ -1032,7 +1065,7 @@ public class EasStore extends Store {
|
||||
|
||||
if (messages == null) {
|
||||
s.tag(Tags.SYNC_GET_CHANGES);
|
||||
// s.data(Tags.SYNC_WINDOW_SIZE, Integer.toString(end - start + 1));
|
||||
// EASTODO: s.data(Tags.SYNC_WINDOW_SIZE, Integer.toString(end - start + 1));
|
||||
}
|
||||
// Handle options
|
||||
s.start(Tags.SYNC_OPTIONS);
|
||||
@ -1082,10 +1115,9 @@ public class EasStore extends Store {
|
||||
}
|
||||
s.end();
|
||||
}
|
||||
// // Send our changes up to the server
|
||||
// target.sendLocalChanges(s);
|
||||
|
||||
s.end().end().end().done();
|
||||
|
||||
HttpResponse resp = sendHttpClientPost("Sync", new ByteArrayEntity(s.toByteArray()), timeout);
|
||||
try {
|
||||
int code = resp.getStatusLine().getStatusCode();
|
||||
@ -1093,26 +1125,24 @@ public class EasStore extends Store {
|
||||
InputStream is = resp.getEntity().getContent();
|
||||
if (is != null) {
|
||||
syncParser = new EasEmailSyncParser(is, this, mAccount);
|
||||
|
||||
boolean moreAvailable = syncParser.parse();
|
||||
|
||||
if (moreAvailable && syncKey.equals("0")) {
|
||||
if (moreAvailable && !syncParser.hasMessages()) {
|
||||
// Make sure we free the connection to the pool before recursing. Otherwise
|
||||
// we'll dead lock.
|
||||
reclaimConnection(resp);
|
||||
return getMessagesInternal(messages, fp, listener, start, end);
|
||||
}
|
||||
} else {
|
||||
Log.d(K9.LOG_TAG, "Empty input stream in sync command response");
|
||||
}
|
||||
} else {
|
||||
// userLog("Sync response error: ", code);
|
||||
// if (isProvisionError(code)) {
|
||||
// mExitStatus = EXIT_SECURITY_FAILURE;
|
||||
// } else if (isAuthError(code)) {
|
||||
// mExitStatus = EXIT_LOGIN_FAILURE;
|
||||
// } else {
|
||||
// mExitStatus = EXIT_IO_ERROR;
|
||||
// }
|
||||
// return;
|
||||
throw new MessagingException("not ok status");
|
||||
if (isProvisionError(code)) {
|
||||
throw new MessagingException("Provision error received while downloading messages");
|
||||
} else if (isAuthError(code)) {
|
||||
throw new MessagingException("Authentication error received while downloading messages");
|
||||
} else {
|
||||
throw new MessagingException("Unknown error received while downloading messages");
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
reclaimConnection(resp);
|
||||
@ -1204,7 +1234,7 @@ public class EasStore extends Store {
|
||||
EasEmailSyncParser syncParser = getMessagesInternal(messages, fp, listener, -1, -1);
|
||||
messages = syncParser.getMessages().toArray(EMPTY_MESSAGE_ARRAY);
|
||||
} catch (IOException e) {
|
||||
throw new MessagingException("io exception while fetching messages", e);
|
||||
throw new MessagingException("IO exception while fetching messages", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1281,17 +1311,20 @@ public class EasStore extends Store {
|
||||
|
||||
@Override
|
||||
public void appendMessages(Message[] messages) throws MessagingException {
|
||||
// appendWebDavMessages(messages);
|
||||
// EASTODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof EasFolder) {
|
||||
return mServerId.equals(((EasFolder)o).mServerId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
return mServerId.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1308,6 +1341,11 @@ public class EasStore extends Store {
|
||||
"Unimplemented method setFlags(Flag[], boolean) breaks markAllMessagesAsRead and EmptyTrash");
|
||||
// Try to make this efficient by not retrieving all of the messages
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNewPushState(String oldPushState, Message message) {
|
||||
return mSyncKey;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1400,10 +1438,12 @@ public class EasStore extends Store {
|
||||
.data(Tags.PING_HEARTBEAT_INTERVAL, String.valueOf(responseTimeout))
|
||||
.start(Tags.PING_FOLDERS);
|
||||
|
||||
synchronized (mFolderList) {
|
||||
// Using getFolder here will ensure we have retrieved the folder list from the server.
|
||||
for (String folderName : folderNames) {
|
||||
EasFolder folder = (EasFolder)mStore.getFolder(folderName);
|
||||
if (folder != null) {
|
||||
s.start(Tags.PING_FOLDER)
|
||||
.data(Tags.PING_ID, mFolderList.get(folderName).mServerId)
|
||||
.data(Tags.PING_ID, folder.mServerId)
|
||||
.data(Tags.PING_CLASS, "Email")
|
||||
.end();
|
||||
}
|
||||
@ -1422,13 +1462,12 @@ public class EasStore extends Store {
|
||||
PingParser pingParser = new PingParser(is);
|
||||
if (!pingParser.parse()) {
|
||||
for (String folderServerId : pingParser.getFolderList()) {
|
||||
for (EasFolder folder : mFolderList.values()) {
|
||||
if (folderServerId.equals(folder.mServerId)) {
|
||||
Folder folder = mStore.getFolder(folderServerId);
|
||||
if (folder != null) {
|
||||
receiver.syncFolder(folder);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new MessagingException("Parsing of Ping response failed");
|
||||
}
|
||||
@ -1436,7 +1475,8 @@ public class EasStore extends Store {
|
||||
Log.d(K9.LOG_TAG, "Empty input stream in sync command response");
|
||||
}
|
||||
} else {
|
||||
throw new MessagingException("not ok status");
|
||||
throw new MessagingException("Received an unsuccessful HTTP status during a ping request: "
|
||||
+ String.valueOf(code));
|
||||
}
|
||||
} finally {
|
||||
reclaimConnection(resp);
|
||||
@ -1535,7 +1575,7 @@ public class EasStore extends Store {
|
||||
}
|
||||
}
|
||||
|
||||
byte[] prepare(EasFolder folder) throws IOException {
|
||||
byte[] prepare(EasFolder folder) throws IOException, MessagingException {
|
||||
Serializer s = new Serializer();
|
||||
|
||||
String className = "Email";
|
||||
|
@ -502,10 +502,10 @@ public class ImapStore extends Store {
|
||||
HashSet<String> subscribedFolderNames = new HashSet<String>();
|
||||
List <? extends Folder > subscribedFolders = listFolders(connection, true);
|
||||
for (Folder subscribedFolder : subscribedFolders) {
|
||||
subscribedFolderNames.add(subscribedFolder.getName());
|
||||
subscribedFolderNames.add(subscribedFolder.getRemoteName());
|
||||
}
|
||||
for (Folder folder : allFolders) {
|
||||
if (subscribedFolderNames.contains(folder.getName())) {
|
||||
if (subscribedFolderNames.contains(folder.getRemoteName())) {
|
||||
resultFolders.add(folder);
|
||||
}
|
||||
}
|
||||
@ -909,7 +909,6 @@ public class ImapStore extends Store {
|
||||
Log.e(K9.LOG_TAG, "Unable to open connection for " + getLogId(), me);
|
||||
throw me;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -937,6 +936,11 @@ public class ImapStore extends Store {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRemoteName() {
|
||||
return mName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return mName;
|
||||
@ -1084,7 +1088,7 @@ public class ImapStore extends Store {
|
||||
if (messages.length == 0)
|
||||
return;
|
||||
|
||||
if (trashFolderName == null || getName().equalsIgnoreCase(trashFolderName)) {
|
||||
if (trashFolderName == null || getRemoteName().equalsIgnoreCase(trashFolderName)) {
|
||||
setFlags(messages, new Flag[] { Flag.DELETED }, true);
|
||||
} else {
|
||||
ImapFolder remoteTrashFolder = (ImapFolder)getStore().getFolder(trashFolderName);
|
||||
@ -1999,14 +2003,14 @@ public class ImapStore extends Store {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof ImapFolder) {
|
||||
return ((ImapFolder)o).getName().equalsIgnoreCase(getName());
|
||||
return ((ImapFolder)o).getRemoteName().equalsIgnoreCase(getRemoteName());
|
||||
}
|
||||
return super.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getName().hashCode();
|
||||
return getRemoteName().hashCode();
|
||||
}
|
||||
|
||||
protected ImapStore getStore() {
|
||||
@ -2014,7 +2018,7 @@ public class ImapStore extends Store {
|
||||
}
|
||||
|
||||
protected String getLogId() {
|
||||
String id = getAccount().getDescription() + ":" + getName() + "/" + Thread.currentThread().getName();
|
||||
String id = getAccount().getDescription() + ":" + getRemoteName() + "/" + Thread.currentThread().getName();
|
||||
if (mConnection != null) {
|
||||
id += "/" + mConnection.getLogId();
|
||||
}
|
||||
@ -2603,7 +2607,7 @@ public class ImapStore extends Store {
|
||||
super(store, name);
|
||||
receiver = nReceiver;
|
||||
TracingPowerManager pm = TracingPowerManager.getPowerManager(receiver.getContext());
|
||||
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ImapFolderPusher " + store.getAccount().getDescription() + ":" + getName());
|
||||
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ImapFolderPusher " + store.getAccount().getDescription() + ":" + getRemoteName());
|
||||
wakeLock.setReferenceCounted(false);
|
||||
|
||||
}
|
||||
@ -2644,7 +2648,7 @@ public class ImapStore extends Store {
|
||||
try {
|
||||
int oldUidNext = -1;
|
||||
try {
|
||||
String pushStateS = receiver.getPushState(getName());
|
||||
String pushStateS = receiver.getPushState(getRemoteName());
|
||||
ImapPushState pushState = ImapPushState.parse(pushStateS);
|
||||
oldUidNext = pushState.uidNext;
|
||||
if (K9.DEBUG)
|
||||
@ -2729,7 +2733,7 @@ public class ImapStore extends Store {
|
||||
if (K9.DEBUG)
|
||||
Log.i(K9.LOG_TAG, "About to IDLE for " + getLogId());
|
||||
|
||||
receiver.setPushActive(getName(), true);
|
||||
receiver.setPushActive(getRemoteName(), true);
|
||||
idling.set(true);
|
||||
doneSent.set(false);
|
||||
|
||||
@ -2743,7 +2747,7 @@ public class ImapStore extends Store {
|
||||
wakeLock.acquire(K9.PUSH_WAKE_LOCK_TIMEOUT);
|
||||
storedUntaggedResponses.clear();
|
||||
idling.set(false);
|
||||
receiver.setPushActive(getName(), false);
|
||||
receiver.setPushActive(getRemoteName(), false);
|
||||
try {
|
||||
close();
|
||||
} catch (Exception me) {
|
||||
@ -2770,7 +2774,7 @@ public class ImapStore extends Store {
|
||||
}
|
||||
}
|
||||
}
|
||||
receiver.setPushActive(getName(), false);
|
||||
receiver.setPushActive(getRemoteName(), false);
|
||||
try {
|
||||
if (K9.DEBUG)
|
||||
Log.i(K9.LOG_TAG, "Pusher for " + getLogId() + " is exiting");
|
||||
@ -2836,7 +2840,7 @@ public class ImapStore extends Store {
|
||||
private void syncMessages(int end, boolean newArrivals) throws MessagingException {
|
||||
int oldUidNext = -1;
|
||||
try {
|
||||
String pushStateS = receiver.getPushState(getName());
|
||||
String pushStateS = receiver.getPushState(getRemoteName());
|
||||
ImapPushState pushState = ImapPushState.parse(pushStateS);
|
||||
oldUidNext = pushState.uidNext;
|
||||
if (K9.DEBUG)
|
||||
|
@ -102,11 +102,11 @@ public class LocalStore extends Store implements Serializable {
|
||||
"subject, sender_list, date, uid, flags, id, to_list, cc_list, "
|
||||
+ "bcc_list, reply_to_list, attachment_count, internal_date, message_id, folder_id, preview ";
|
||||
|
||||
static private String GET_FOLDER_COLS = "id, name, unread_count, visible_limit, last_updated, status, "
|
||||
+ "push_state, last_pushed, flagged_count, integrate, top_group, poll_class, push_class, "
|
||||
+ "display_class, remote_name";
|
||||
|
||||
static private String GET_FOLDER_COLS = "id, name, unread_count, visible_limit, last_updated, status, push_state, last_pushed, flagged_count, integrate, top_group, poll_class, push_class, display_class";
|
||||
|
||||
|
||||
protected static final int DB_VERSION = 43;
|
||||
protected static final int DB_VERSION = 44;
|
||||
|
||||
protected String uUid = null;
|
||||
|
||||
@ -151,7 +151,6 @@ public class LocalStore extends Store implements Serializable {
|
||||
Log.i(K9.LOG_TAG, String.format("Upgrading database from version %d to version %d",
|
||||
db.getVersion(), DB_VERSION));
|
||||
|
||||
|
||||
AttachmentProvider.clear(mApplication);
|
||||
|
||||
try {
|
||||
@ -163,8 +162,8 @@ public class LocalStore extends Store implements Serializable {
|
||||
db.execSQL("CREATE TABLE folders (id INTEGER PRIMARY KEY, name TEXT, "
|
||||
+ "last_updated INTEGER, unread_count INTEGER, visible_limit INTEGER, status TEXT, "
|
||||
+ "push_state TEXT, last_pushed INTEGER, flagged_count INTEGER default 0, "
|
||||
+ "integrate INTEGER, top_group INTEGER, poll_class TEXT, push_class TEXT, display_class TEXT"
|
||||
+ ")");
|
||||
+ "integrate INTEGER, top_group INTEGER, poll_class TEXT, push_class TEXT, display_class TEXT,"
|
||||
+ "remote_name TEXT)");
|
||||
|
||||
db.execSQL("CREATE INDEX IF NOT EXISTS folder_name ON folders (name)");
|
||||
db.execSQL("DROP TABLE IF EXISTS messages");
|
||||
@ -303,8 +302,6 @@ public class LocalStore extends Store implements Serializable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
catch (SQLiteException e) {
|
||||
Log.e(K9.LOG_TAG, "Exception while upgrading database to v41. folder classes may have vanished", e);
|
||||
|
||||
@ -366,17 +363,23 @@ public class LocalStore extends Store implements Serializable {
|
||||
Log.e(K9.LOG_TAG, "Error trying to fix the outbox folders", e);
|
||||
}
|
||||
}
|
||||
if (db.getVersion() < 44) {
|
||||
try {
|
||||
db.execSQL("ALTER TABLE folders ADD remote_name TEXT");
|
||||
// Mirror the name to the remote_name column for existing folders.
|
||||
db.execSQL("UPDATE folders SET remote_name = name");
|
||||
} catch (SQLiteException e) {
|
||||
Log.e(K9.LOG_TAG, "Unable to add remote_name column to folders");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch (SQLiteException e) {
|
||||
Log.e(K9.LOG_TAG, "Exception while upgrading database. Resetting the DB to v0");
|
||||
db.setVersion(0);
|
||||
throw new Error("Database upgrade failed! Resetting your DB version to 0 to force a full schema recreation.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
db.setVersion(DB_VERSION);
|
||||
|
||||
if (db.getVersion() != DB_VERSION) {
|
||||
@ -397,7 +400,6 @@ public class LocalStore extends Store implements Serializable {
|
||||
|
||||
private void update41Metadata(final SQLiteDatabase db, SharedPreferences prefs, int id, String name) {
|
||||
|
||||
|
||||
Folder.FolderClass displayClass = Folder.FolderClass.NO_CLASS;
|
||||
Folder.FolderClass syncClass = Folder.FolderClass.INHERITED;
|
||||
Folder.FolderClass pushClass = Folder.FolderClass.SECOND_CLASS;
|
||||
@ -624,6 +626,10 @@ public class LocalStore extends Store implements Serializable {
|
||||
return new LocalFolder(name);
|
||||
}
|
||||
|
||||
public LocalFolder getFolder(String remoteName, String name) {
|
||||
return new LocalFolder(remoteName, name);
|
||||
}
|
||||
|
||||
// TODO this takes about 260-300ms, seems slow.
|
||||
@Override
|
||||
public List <? extends Folder > getPersonalNamespaces(boolean forceListAll) throws MessagingException {
|
||||
@ -638,8 +644,10 @@ public class LocalStore extends Store implements Serializable {
|
||||
cursor = db.rawQuery("SELECT " + GET_FOLDER_COLS + " FROM folders ORDER BY name ASC", null);
|
||||
while (cursor.moveToNext()) {
|
||||
LocalFolder folder = new LocalFolder(cursor.getString(1));
|
||||
folder.open(cursor.getInt(0), cursor.getString(1), cursor.getInt(2), cursor.getInt(3), cursor.getLong(4), cursor.getString(5), cursor.getString(6), cursor.getLong(7), cursor.getInt(8), cursor.getInt(9), cursor.getInt(10), cursor.getString(11), cursor.getString(12), cursor.getString(13));
|
||||
|
||||
folder.open(cursor.getInt(0), cursor.getString(14), cursor.getString(1), cursor.getInt(2),
|
||||
cursor.getInt(3), cursor.getLong(4), cursor.getString(5), cursor.getString(6),
|
||||
cursor.getLong(7), cursor.getInt(8), cursor.getInt(9), cursor.getInt(10), cursor.getString(11),
|
||||
cursor.getString(12), cursor.getString(13));
|
||||
folders.add(folder);
|
||||
}
|
||||
return folders;
|
||||
@ -1050,41 +1058,42 @@ public class LocalStore extends Store implements Serializable {
|
||||
@Override
|
||||
public Void doDbWork(final SQLiteDatabase db) throws WrappedException {
|
||||
for (LocalFolder folder : foldersToCreate) {
|
||||
String name = folder.getName();
|
||||
String remoteName = folder.getRemoteName();
|
||||
final LocalFolder.PreferencesHolder prefHolder = folder.new PreferencesHolder();
|
||||
|
||||
// When created, special folders should always be displayed
|
||||
// inbox should be integrated
|
||||
// and the inbox and drafts folders should be syncced by default
|
||||
if (mAccount.isSpecialFolder(name)) {
|
||||
if (mAccount.isSpecialFolder(remoteName)) {
|
||||
prefHolder.inTopGroup = true;
|
||||
prefHolder.displayClass = LocalFolder.FolderClass.FIRST_CLASS;
|
||||
if (name.equalsIgnoreCase(mAccount.getInboxFolderName())) {
|
||||
if (remoteName.equalsIgnoreCase(mAccount.getInboxFolderName())) {
|
||||
prefHolder.integrate = true;
|
||||
prefHolder.pushClass = LocalFolder.FolderClass.FIRST_CLASS;
|
||||
} else {
|
||||
prefHolder.pushClass = LocalFolder.FolderClass.INHERITED;
|
||||
|
||||
}
|
||||
if (name.equalsIgnoreCase(mAccount.getInboxFolderName()) ||
|
||||
name.equalsIgnoreCase(mAccount.getDraftsFolderName())) {
|
||||
if (remoteName.equalsIgnoreCase(mAccount.getInboxFolderName()) ||
|
||||
remoteName.equalsIgnoreCase(mAccount.getDraftsFolderName())) {
|
||||
prefHolder.syncClass = LocalFolder.FolderClass.FIRST_CLASS;
|
||||
} else {
|
||||
prefHolder.syncClass = LocalFolder.FolderClass.NO_CLASS;
|
||||
}
|
||||
}
|
||||
folder.refresh(name, prefHolder); // Recover settings from Preferences
|
||||
folder.refresh(remoteName, prefHolder); // Recover settings from Preferences
|
||||
|
||||
db.execSQL("INSERT INTO folders (name, visible_limit, top_group, display_class, poll_class, push_class, integrate) VALUES (?, ?, ?, ?, ?, ?, ?)", new Object[] {
|
||||
name,
|
||||
db.execSQL("INSERT INTO folders (name, visible_limit, top_group, display_class, poll_class, push_class, integrate, remote_name)"
|
||||
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?)", new Object[] {
|
||||
folder.getName(),
|
||||
visibleLimit,
|
||||
prefHolder.inTopGroup ? 1 : 0,
|
||||
prefHolder.displayClass.name(),
|
||||
prefHolder.syncClass.name(),
|
||||
prefHolder.pushClass.name(),
|
||||
prefHolder.integrate ? 1 : 0,
|
||||
remoteName
|
||||
});
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -1092,10 +1101,10 @@ public class LocalStore extends Store implements Serializable {
|
||||
}
|
||||
|
||||
public class LocalFolder extends Folder implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
private static final long serialVersionUID = -1973296520918624767L;
|
||||
// mRemoteName uniquely identifies the folder in both the local and remote store.
|
||||
private String mRemoteName;
|
||||
private String mName = null;
|
||||
private long mFolderId = -1;
|
||||
private int mUnreadMessageCount = -1;
|
||||
@ -1112,23 +1121,35 @@ public class LocalStore extends Store implements Serializable {
|
||||
// know whether or not an unread message added to the local folder is actually "new" or not.
|
||||
private Integer mLastUid = null;
|
||||
|
||||
public LocalFolder(String name) {
|
||||
public LocalFolder(String remoteName) {
|
||||
super(LocalStore.this.mAccount);
|
||||
this.mName = name;
|
||||
|
||||
if (LocalStore.this.mAccount.getInboxFolderName().equals(getName())) {
|
||||
mRemoteName = remoteName;
|
||||
mName = remoteName;
|
||||
|
||||
if (LocalStore.this.mAccount.getInboxFolderName().equals(remoteName)) {
|
||||
mSyncClass = FolderClass.FIRST_CLASS;
|
||||
mPushClass = FolderClass.FIRST_CLASS;
|
||||
mInTopGroup = true;
|
||||
}
|
||||
}
|
||||
|
||||
public LocalFolder(String remoteName, String name) {
|
||||
super(LocalStore.this.mAccount);
|
||||
|
||||
mRemoteName = remoteName;
|
||||
mName = name;
|
||||
|
||||
if (LocalStore.this.mAccount.getInboxFolderName().equals(remoteName)) {
|
||||
mSyncClass = FolderClass.FIRST_CLASS;
|
||||
mPushClass = FolderClass.FIRST_CLASS;
|
||||
mInTopGroup = true;
|
||||
}
|
||||
}
|
||||
|
||||
public LocalFolder(long id) {
|
||||
super(LocalStore.this.mAccount);
|
||||
this.mFolderId = id;
|
||||
mFolderId = id;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
@ -1148,8 +1169,8 @@ public class LocalStore extends Store implements Serializable {
|
||||
try {
|
||||
String baseQuery = "SELECT " + GET_FOLDER_COLS + " FROM folders ";
|
||||
|
||||
if (mName != null) {
|
||||
cursor = db.rawQuery(baseQuery + "where folders.name = ?", new String[] { mName });
|
||||
if (mRemoteName != null) {
|
||||
cursor = db.rawQuery(baseQuery + "where folders.remote_name = ?", new String[] { mRemoteName });
|
||||
} else {
|
||||
cursor = db.rawQuery(baseQuery + "where folders.id = ?", new String[] { Long.toString(mFolderId) });
|
||||
}
|
||||
@ -1157,7 +1178,9 @@ public class LocalStore extends Store implements Serializable {
|
||||
if (cursor.moveToFirst()) {
|
||||
int folderId = cursor.getInt(0);
|
||||
if (folderId > 0) {
|
||||
open(folderId, cursor.getString(1), cursor.getInt(2), cursor.getInt(3), cursor.getLong(4), cursor.getString(5), cursor.getString(6), cursor.getLong(7), cursor.getInt(8), cursor.getInt(9), cursor.getInt(10), cursor.getString(11), cursor.getString(12), cursor.getString(13));
|
||||
open(folderId, cursor.getString(14), cursor.getString(1), cursor.getInt(2), cursor.getInt(3),
|
||||
cursor.getLong(4), cursor.getString(5), cursor.getString(6), cursor.getLong(7), cursor.getInt(8),
|
||||
cursor.getInt(9), cursor.getInt(10), cursor.getString(11), cursor.getString(12), cursor.getString(13));
|
||||
}
|
||||
} else {
|
||||
Log.w(K9.LOG_TAG, "Creating folder " + getName() + " with existing id " + getId());
|
||||
@ -1177,8 +1200,11 @@ public class LocalStore extends Store implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
private void open(int id, String name, int unreadCount, int visibleLimit, long lastChecked, String status, String pushState, long lastPushed, int flaggedCount, int integrate, int topGroup, String syncClass, String pushClass, String displayClass) throws MessagingException {
|
||||
private void open(int id, String remoteName, String name, int unreadCount, int visibleLimit, long lastChecked, String status,
|
||||
String pushState, long lastPushed, int flaggedCount, int integrate, int topGroup, String syncClass,
|
||||
String pushClass, String displayClass) throws MessagingException {
|
||||
mFolderId = id;
|
||||
mRemoteName = remoteName;
|
||||
mName = name;
|
||||
mUnreadMessageCount = unreadCount;
|
||||
mVisibleLimit = visibleLimit;
|
||||
@ -1195,7 +1221,6 @@ public class LocalStore extends Store implements Serializable {
|
||||
mDisplayClass = Folder.FolderClass.valueOf((displayClass == null) ? noClass : displayClass);
|
||||
mPushClass = Folder.FolderClass.valueOf((pushClass == null) ? noClass : pushClass);
|
||||
mSyncClass = Folder.FolderClass.valueOf((syncClass == null) ? noClass : syncClass);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1208,6 +1233,11 @@ public class LocalStore extends Store implements Serializable {
|
||||
return OpenMode.READ_WRITE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRemoteName() {
|
||||
return mRemoteName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return mName;
|
||||
@ -1220,10 +1250,8 @@ public class LocalStore extends Store implements Serializable {
|
||||
public Boolean doDbWork(final SQLiteDatabase db) throws WrappedException {
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = db.rawQuery("SELECT id FROM folders "
|
||||
+ "where folders.name = ?", new String[] { LocalFolder.this
|
||||
.getName()
|
||||
});
|
||||
cursor = db.rawQuery("SELECT id FROM folders where folders.remote_name = ?",
|
||||
new String[] { LocalFolder.this.getRemoteName() });
|
||||
if (cursor.moveToFirst()) {
|
||||
int folderId = cursor.getInt(0);
|
||||
return (folderId > 0);
|
||||
@ -1356,11 +1384,9 @@ public class LocalStore extends Store implements Serializable {
|
||||
listener.messageRemoved(messages[i]);
|
||||
}
|
||||
messages[i].destroy();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setVisibleLimit(final int visibleLimit) throws MessagingException {
|
||||
mVisibleLimit = visibleLimit;
|
||||
updateFolderColumn("visible_limit", mVisibleLimit);
|
||||
@ -1370,6 +1396,7 @@ public class LocalStore extends Store implements Serializable {
|
||||
public void setStatus(final String status) throws MessagingException {
|
||||
updateFolderColumn("status", status);
|
||||
}
|
||||
|
||||
public void setPushState(final String pushState) throws MessagingException {
|
||||
mPushState = pushState;
|
||||
updateFolderColumn("push_state", pushState);
|
||||
@ -1413,7 +1440,6 @@ public class LocalStore extends Store implements Serializable {
|
||||
|
||||
public FolderClass getRawSyncClass() {
|
||||
return mSyncClass;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1427,19 +1453,18 @@ public class LocalStore extends Store implements Serializable {
|
||||
|
||||
public FolderClass getRawPushClass() {
|
||||
return mPushClass;
|
||||
|
||||
}
|
||||
|
||||
public void setDisplayClass(FolderClass displayClass) throws MessagingException {
|
||||
mDisplayClass = displayClass;
|
||||
updateFolderColumn("display_class", mDisplayClass.name());
|
||||
|
||||
}
|
||||
|
||||
public void setSyncClass(FolderClass syncClass) throws MessagingException {
|
||||
mSyncClass = syncClass;
|
||||
updateFolderColumn("poll_class", mSyncClass.name());
|
||||
}
|
||||
|
||||
public void setPushClass(FolderClass pushClass) throws MessagingException {
|
||||
mPushClass = pushClass;
|
||||
updateFolderColumn("push_class", mPushClass.name());
|
||||
@ -1448,6 +1473,7 @@ public class LocalStore extends Store implements Serializable {
|
||||
public boolean isIntegrate() {
|
||||
return mIntegrate;
|
||||
}
|
||||
|
||||
public void setIntegrate(boolean integrate) throws MessagingException {
|
||||
mIntegrate = integrate;
|
||||
updateFolderColumn("integrate", mIntegrate ? 1 : 0);
|
||||
@ -1464,7 +1490,6 @@ public class LocalStore extends Store implements Serializable {
|
||||
private String getPrefId() throws MessagingException {
|
||||
open(OpenMode.READ_WRITE);
|
||||
return getPrefId(mName);
|
||||
|
||||
}
|
||||
|
||||
public void delete() throws MessagingException {
|
||||
@ -1491,19 +1516,19 @@ public class LocalStore extends Store implements Serializable {
|
||||
String id = getPrefId();
|
||||
|
||||
// there can be a lot of folders. For the defaults, let's not save prefs, saving space, except for INBOX
|
||||
if (mDisplayClass == FolderClass.NO_CLASS && !mAccount.getInboxFolderName().equals(getName())) {
|
||||
if (mDisplayClass == FolderClass.NO_CLASS && !mAccount.getInboxFolderName().equals(getRemoteName())) {
|
||||
editor.remove(id + ".displayMode");
|
||||
} else {
|
||||
editor.putString(id + ".displayMode", mDisplayClass.name());
|
||||
}
|
||||
|
||||
if (mSyncClass == FolderClass.INHERITED && !mAccount.getInboxFolderName().equals(getName())) {
|
||||
if (mSyncClass == FolderClass.INHERITED && !mAccount.getInboxFolderName().equals(getRemoteName())) {
|
||||
editor.remove(id + ".syncMode");
|
||||
} else {
|
||||
editor.putString(id + ".syncMode", mSyncClass.name());
|
||||
}
|
||||
|
||||
if (mPushClass == FolderClass.SECOND_CLASS && !mAccount.getInboxFolderName().equals(getName())) {
|
||||
if (mPushClass == FolderClass.SECOND_CLASS && !mAccount.getInboxFolderName().equals(getRemoteName())) {
|
||||
editor.remove(id + ".pushMode");
|
||||
} else {
|
||||
editor.putString(id + ".pushMode", mPushClass.name());
|
||||
@ -1511,7 +1536,6 @@ public class LocalStore extends Store implements Serializable {
|
||||
editor.putBoolean(id + ".inTopGroup", mInTopGroup);
|
||||
|
||||
editor.putBoolean(id + ".integrate", mIntegrate);
|
||||
|
||||
}
|
||||
|
||||
public void refresh(String name, PreferencesHolder prefHolder) {
|
||||
@ -1551,7 +1575,6 @@ public class LocalStore extends Store implements Serializable {
|
||||
}
|
||||
prefHolder.inTopGroup = preferences.getBoolean(id + ".inTopGroup", prefHolder.inTopGroup);
|
||||
prefHolder.integrate = preferences.getBoolean(id + ".integrate", prefHolder.integrate);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -2557,15 +2580,12 @@ public class LocalStore extends Store implements Serializable {
|
||||
clearMessagesWhere(where, params);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void clearAllMessages() throws MessagingException {
|
||||
final String where = "folder_id = ?";
|
||||
final String[] params = new String[] {
|
||||
Long.toString(mFolderId)
|
||||
};
|
||||
|
||||
|
||||
clearMessagesWhere(where, params);
|
||||
setPushState(null);
|
||||
setLastPush(0);
|
||||
@ -2593,7 +2613,6 @@ public class LocalStore extends Store implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void delete(final boolean recurse) throws MessagingException {
|
||||
try {
|
||||
@ -2623,14 +2642,14 @@ public class LocalStore extends Store implements Serializable {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof LocalFolder) {
|
||||
return ((LocalFolder)o).mName.equals(mName);
|
||||
return ((LocalFolder)o).mRemoteName.equals(mRemoteName);
|
||||
}
|
||||
return super.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return mName.hashCode();
|
||||
return mRemoteName.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -2638,7 +2657,6 @@ public class LocalStore extends Store implements Serializable {
|
||||
return PERMANENT_FLAGS;
|
||||
}
|
||||
|
||||
|
||||
private void deleteAttachments(final long messageId) throws MessagingException {
|
||||
open(OpenMode.READ_WRITE);
|
||||
database.execute(false, new DbCallback<Void>() {
|
||||
@ -2756,7 +2774,6 @@ public class LocalStore extends Store implements Serializable {
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isInTopGroup() {
|
||||
return mInTopGroup;
|
||||
@ -3026,7 +3043,6 @@ public class LocalStore extends Store implements Serializable {
|
||||
mMessageDirty = true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setReplyTo(Address[] replyTo) throws MessagingException {
|
||||
if (replyTo == null || replyTo.length == 0) {
|
||||
@ -3037,7 +3053,6 @@ public class LocalStore extends Store implements Serializable {
|
||||
mMessageDirty = true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* For performance reasons, we add headers instead of setting them (see super implementation)
|
||||
* which removes (expensive) them before adding them
|
||||
@ -3068,8 +3083,6 @@ public class LocalStore extends Store implements Serializable {
|
||||
mMessageDirty = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean toMe() {
|
||||
try {
|
||||
if (!mToMeCalculated) {
|
||||
@ -3087,13 +3100,8 @@ public class LocalStore extends Store implements Serializable {
|
||||
return mToMe;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public boolean ccMe() {
|
||||
try {
|
||||
|
||||
if (!mCcMeCalculated) {
|
||||
for (Address address : getRecipients(RecipientType.CC)) {
|
||||
if (mAccount.isAnIdentity(address)) {
|
||||
@ -3101,7 +3109,6 @@ public class LocalStore extends Store implements Serializable {
|
||||
mCcMeCalculated = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (MessagingException e) {
|
||||
// do something better than ignore this
|
||||
@ -3111,11 +3118,6 @@ public class LocalStore extends Store implements Serializable {
|
||||
return mCcMe;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void setFlagInternal(Flag flag, boolean set) throws MessagingException {
|
||||
super.setFlag(flag, set);
|
||||
}
|
||||
@ -3154,8 +3156,6 @@ public class LocalStore extends Store implements Serializable {
|
||||
} catch (WrappedException e) {
|
||||
throw(MessagingException) e.getCause();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -3163,9 +3163,7 @@ public class LocalStore extends Store implements Serializable {
|
||||
* and attachments as well. Delete will not actually remove the row since we need
|
||||
* to retain the uid for synchronization purposes.
|
||||
*/
|
||||
private void delete() throws MessagingException
|
||||
|
||||
{
|
||||
private void delete() throws MessagingException {
|
||||
/*
|
||||
* Delete all of the message's content to save space.
|
||||
*/
|
||||
@ -3198,8 +3196,6 @@ public class LocalStore extends Store implements Serializable {
|
||||
throw(MessagingException) e.getCause();
|
||||
}
|
||||
((LocalFolder)mFolder).deleteHeaders(mId);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -256,7 +256,7 @@ public class Pop3Store extends Store {
|
||||
Folder folder = mFolders.get(name);
|
||||
if (folder == null) {
|
||||
folder = new Pop3Folder(name);
|
||||
mFolders.put(folder.getName(), folder);
|
||||
mFolders.put(folder.getRemoteName(), folder);
|
||||
}
|
||||
return folder;
|
||||
}
|
||||
@ -460,6 +460,11 @@ public class Pop3Store extends Store {
|
||||
mSocket = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRemoteName() {
|
||||
return mName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return mName;
|
||||
|
@ -1336,12 +1336,12 @@ public class WebDavStore extends Store {
|
||||
|
||||
@Override
|
||||
public void copyMessages(Message[] messages, Folder folder) throws MessagingException {
|
||||
moveOrCopyMessages(messages, folder.getName(), false);
|
||||
moveOrCopyMessages(messages, folder.getRemoteName(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveMessages(Message[] messages, Folder folder) throws MessagingException {
|
||||
moveOrCopyMessages(messages, folder.getName(), true);
|
||||
moveOrCopyMessages(messages, folder.getRemoteName(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1434,6 +1434,11 @@ public class WebDavStore extends Store {
|
||||
return OpenMode.READ_WRITE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRemoteName() {
|
||||
return this.mName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.mName;
|
||||
|
@ -535,7 +535,6 @@ public class EasEmailSyncParser extends AbstractSyncParser {
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
public List<EasMessage> getMessages() throws MessagingException {
|
||||
List<EasMessage> messages = new ArrayList<EasMessage>();
|
||||
|
||||
@ -561,4 +560,7 @@ public class EasEmailSyncParser extends AbstractSyncParser {
|
||||
return messages;
|
||||
}
|
||||
|
||||
public boolean hasMessages() {
|
||||
return !newEmails.isEmpty() || !changedEmails.isEmpty() || !deletedEmails.isEmpty();
|
||||
}
|
||||
}
|
@ -175,7 +175,7 @@ public class MessageProvider extends ContentProvider {
|
||||
final Message message = source.message;
|
||||
return CONTENT_URI + "/delete_message/"
|
||||
+ message.getFolder().getAccount().getAccountNumber() + "/"
|
||||
+ message.getFolder().getName() + "/" + message.getUid();
|
||||
+ message.getFolder().getRemoteName() + "/" + message.getUid();
|
||||
}
|
||||
}
|
||||
public static class SenderExtractor implements FieldExtractor<MessageInfoHolder, CharSequence> {
|
||||
|
Loading…
Reference in New Issue
Block a user