diff --git a/src/com/fsck/k9/Account.java b/src/com/fsck/k9/Account.java index e0d97930f..cab6316a8 100644 --- a/src/com/fsck/k9/Account.java +++ b/src/com/fsck/k9/Account.java @@ -1,1016 +1,967 @@ -package com.fsck.k9; - -import android.app.Application; -import android.content.Context; -import android.content.SharedPreferences; -import android.net.Uri; -import com.fsck.k9.mail.Address; -import com.fsck.k9.mail.Folder; -import com.fsck.k9.mail.MessagingException; -import com.fsck.k9.mail.Store; -import com.fsck.k9.mail.store.LocalStore; -import com.fsck.k9.mail.store.LocalStore.LocalFolder; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - -/** - * Account stores all of the settings for a single account defined by the user. It is able to save - * and delete itself given a Preferences to work with. Each account is defined by a UUID. - */ -public class Account implements Serializable -{ - public static final int DELETE_POLICY_NEVER = 0; - public static final int DELETE_POLICY_7DAYS = 1; - public static final int DELETE_POLICY_ON_DELETE = 2; - public static final int DELETE_POLICY_MARK_AS_READ = 3; - - private static final long serialVersionUID = 2975156672298625121L; - - String mUuid; - String mStoreUri; - String mLocalStoreUri; - String mTransportUri; - String mDescription; - String mAlwaysBcc; - int mAutomaticCheckIntervalMinutes; - int mDisplayCount; - long mLastAutomaticCheckTime; - boolean mNotifyNewMail; - boolean mNotifySelfNewMail; - String mDraftsFolderName; - String mSentFolderName; - String mTrashFolderName; - String mOutboxFolderName; - String mAutoExpandFolderName; - FolderMode mFolderDisplayMode; - FolderMode mFolderSyncMode; - FolderMode mFolderPushMode; - FolderMode mFolderTargetMode; - int mAccountNumber; - boolean mVibrate; - boolean mRing; - String mRingtoneUri; - boolean mNotifySync; - HideButtons mHideMessageViewButtons; - boolean mIsSignatureBeforeQuotedText; - private String mExpungePolicy = EXPUNGE_IMMEDIATELY; - private int mMaxPushFolders; - private boolean mStoreAttachmentsOnSdCard; - - List identities; - - public enum FolderMode - { - NONE, ALL, FIRST_CLASS, FIRST_AND_SECOND_CLASS, NOT_SECOND_CLASS; - } - - public enum HideButtons - { - NEVER, ALWAYS, KEYBOARD_AVAILABLE; - } - - public static final String EXPUNGE_IMMEDIATELY = "EXPUNGE_IMMEDIATELY"; - public static final String EXPUNGE_MANUALLY = "EXPUNGE_MANUALLY"; - public static final String EXPUNGE_ON_POLL = "EXPUNGE_ON_POLL"; - - /** - *
-     * 0 Never
-     * 1 After 7 days
-     * 2 When I delete from inbox
-     * 
- */ - int mDeletePolicy; - - public Account(Context context) - { - // TODO Change local store path to something readable / recognizable - mUuid = UUID.randomUUID().toString(); - mLocalStoreUri = "local://localhost/" + context.getDatabasePath(mUuid + ".db"); - mAutomaticCheckIntervalMinutes = -1; - mDisplayCount = -1; - mAccountNumber = -1; - mNotifyNewMail = true; - mNotifySync = true; - mVibrate = false; - mRing = true; - mNotifySelfNewMail = true; - mFolderDisplayMode = FolderMode.NOT_SECOND_CLASS; - mFolderSyncMode = FolderMode.FIRST_CLASS; - mFolderPushMode = FolderMode.FIRST_CLASS; - mFolderTargetMode = FolderMode.NOT_SECOND_CLASS; - mHideMessageViewButtons = HideButtons.NEVER; - mRingtoneUri = "content://settings/system/notification_sound"; - mIsSignatureBeforeQuotedText = false; - mExpungePolicy = EXPUNGE_IMMEDIATELY; - mAutoExpandFolderName = "INBOX"; - mMaxPushFolders = 10; - - identities = new ArrayList(); - - Identity identity = new Identity(); - identity.setSignatureUse(true); - identity.setSignature(context.getString(R.string.default_signature)); - identity.setDescription(context.getString(R.string.default_identity_description)); - identities.add(identity); - } - - public class Identity implements Serializable - { - String mDescription; - String mName; - String mEmail; - String mSignature; - boolean mSignatureUse; - - public String getName() - { - return mName; - } - public void setName(String name) - { - mName = name; - } - public String getEmail() - { - return mEmail; - } - public void setEmail(String email) - { - mEmail = email; - } - public boolean getSignatureUse() - { - return mSignatureUse; - } - public void setSignatureUse(boolean signatureUse) - { - mSignatureUse = signatureUse; - } - public String getSignature() - { - return mSignature; - } - public void setSignature(String signature) - { - mSignature = signature; - } - public String getDescription() - { - return mDescription; - } - public void setDescription(String description) - { - mDescription = description; - } - public String toString() - { - return "Account.Identity(description=" + mDescription + ", name=" + mName + ", email=" + mEmail + ", signature=" + mSignature; - } - } - - Account(Preferences preferences, String uuid) - { - this.mUuid = uuid; - refresh(preferences); - } - - /** - * Refresh the account from the stored settings. - */ - public void refresh(Preferences preferences) - { - mStoreUri = Utility.base64Decode(preferences.getPreferences().getString(mUuid - + ".storeUri", null)); - mLocalStoreUri = preferences.getPreferences().getString(mUuid + ".localStoreUri", null); - mTransportUri = Utility.base64Decode(preferences.getPreferences().getString(mUuid - + ".transportUri", null)); - mDescription = preferences.getPreferences().getString(mUuid + ".description", null); - mAlwaysBcc = preferences.getPreferences().getString(mUuid + ".alwaysBcc", mAlwaysBcc); - mAutomaticCheckIntervalMinutes = preferences.getPreferences().getInt(mUuid - + ".automaticCheckIntervalMinutes", -1); - mDisplayCount = preferences.getPreferences().getInt(mUuid + ".displayCount", -1); - mLastAutomaticCheckTime = preferences.getPreferences().getLong(mUuid - + ".lastAutomaticCheckTime", 0); - mNotifyNewMail = preferences.getPreferences().getBoolean(mUuid + ".notifyNewMail", - false); - mNotifySelfNewMail = preferences.getPreferences().getBoolean(mUuid + ".notifySelfNewMail", - true); - mNotifySync = preferences.getPreferences().getBoolean(mUuid + ".notifyMailCheck", - false); - mDeletePolicy = preferences.getPreferences().getInt(mUuid + ".deletePolicy", 0); - mDraftsFolderName = preferences.getPreferences().getString(mUuid + ".draftsFolderName", - "Drafts"); - mSentFolderName = preferences.getPreferences().getString(mUuid + ".sentFolderName", - "Sent"); - mTrashFolderName = preferences.getPreferences().getString(mUuid + ".trashFolderName", - "Trash"); - mOutboxFolderName = preferences.getPreferences().getString(mUuid + ".outboxFolderName", - "Outbox"); - mExpungePolicy = preferences.getPreferences().getString(mUuid + ".expungePolicy", EXPUNGE_IMMEDIATELY); - - mMaxPushFolders = preferences.getPreferences().getInt(mUuid + ".maxPushFolders", 10); - - // Between r418 and r431 (version 0.103), folder names were set empty if the Incoming settings were - // opened for non-IMAP accounts. 0.103 was never a market release, so perhaps this code - // should be deleted sometime soon - if (mDraftsFolderName == null || mDraftsFolderName.equals("")) - { - mDraftsFolderName = "Drafts"; - } - if (mSentFolderName == null || mSentFolderName.equals("")) - { - mSentFolderName = "Sent"; - } - if (mTrashFolderName == null || mTrashFolderName.equals("")) - { - mTrashFolderName = "Trash"; - } - if (mOutboxFolderName == null || mOutboxFolderName.equals("")) - { - mOutboxFolderName = "Outbox"; - } - // End of 0.103 repair - - mAutoExpandFolderName = preferences.getPreferences().getString(mUuid + ".autoExpandFolderName", - "INBOX"); - - mAccountNumber = preferences.getPreferences().getInt(mUuid + ".accountNumber", 0); - mVibrate = preferences.getPreferences().getBoolean(mUuid + ".vibrate", false); - mRing = preferences.getPreferences().getBoolean(mUuid + ".ring", true); - - try - { - mHideMessageViewButtons = HideButtons.valueOf(preferences.getPreferences().getString(mUuid + ".hideButtonsEnum", - HideButtons.NEVER.name())); - } - catch (Exception e) - { - mHideMessageViewButtons = HideButtons.NEVER; - } - - mRingtoneUri = preferences.getPreferences().getString(mUuid + ".ringtone", - "content://settings/system/notification_sound"); - try - { - mFolderDisplayMode = FolderMode.valueOf(preferences.getPreferences().getString(mUuid + ".folderDisplayMode", - FolderMode.NOT_SECOND_CLASS.name())); - } - catch (Exception e) - { - mFolderDisplayMode = FolderMode.NOT_SECOND_CLASS; - } - - try - { - mFolderSyncMode = FolderMode.valueOf(preferences.getPreferences().getString(mUuid + ".folderSyncMode", - FolderMode.FIRST_CLASS.name())); - } - catch (Exception e) - { - mFolderSyncMode = FolderMode.FIRST_CLASS; - } - - try - { - mFolderPushMode = FolderMode.valueOf(preferences.getPreferences().getString(mUuid + ".folderPushMode", - FolderMode.FIRST_CLASS.name())); - } - catch (Exception e) - { - mFolderPushMode = FolderMode.FIRST_CLASS; - } - - try - { - mFolderTargetMode = FolderMode.valueOf(preferences.getPreferences().getString(mUuid + ".folderTargetMode", - FolderMode.NOT_SECOND_CLASS.name())); - } - catch (Exception e) - { - mFolderTargetMode = FolderMode.NOT_SECOND_CLASS; - } - - mIsSignatureBeforeQuotedText = preferences.getPreferences().getBoolean(mUuid + ".signatureBeforeQuotedText", false); - identities = loadIdentities(preferences.getPreferences()); - } - - private List loadIdentities(SharedPreferences prefs) - { - List newIdentities = new ArrayList(); - int ident = 0; - boolean gotOne = false; - do - { - gotOne = false; - String name = prefs.getString(mUuid + ".name." + ident, null); - String email = prefs.getString(mUuid + ".email." + ident, null); - boolean signatureUse = prefs.getBoolean(mUuid + ".signatureUse." + ident, true); - String signature = prefs.getString(mUuid + ".signature." + ident, null); - String description = prefs.getString(mUuid + ".description." + ident, null); - if (email != null) - { - Identity identity = new Identity(); - identity.setName(name); - identity.setEmail(email); - identity.setSignatureUse(signatureUse); - identity.setSignature(signature); - identity.setDescription(description); - newIdentities.add(identity); - gotOne = true; - } - ident++; - } - while (gotOne); - - if (newIdentities.size() == 0) - { - String name = prefs.getString(mUuid + ".name", null); - String email = prefs.getString(mUuid + ".email", null); - boolean signatureUse = prefs.getBoolean(mUuid + ".signatureUse", true); - String signature = prefs.getString(mUuid + ".signature", null); - Identity identity = new Identity(); - identity.setName(name); - identity.setEmail(email); - identity.setSignatureUse(signatureUse); - identity.setSignature(signature); - identity.setDescription(email); - newIdentities.add(identity); - } - - return newIdentities; - } - - private void deleteIdentities(SharedPreferences prefs, SharedPreferences.Editor editor) - { - int ident = 0; - boolean gotOne = false; - do - { - gotOne = false; - String email = prefs.getString(mUuid + ".email." + ident, null); - if (email != null) - { - editor.remove(mUuid + ".name." + ident); - editor.remove(mUuid + ".email." + ident); - editor.remove(mUuid + ".signatureUse." + ident); - editor.remove(mUuid + ".signature." + ident); - editor.remove(mUuid + ".description." + ident); - gotOne = true; - } - ident++; - } - while (gotOne); - } - - private void saveIdentities(SharedPreferences prefs, SharedPreferences.Editor editor) - { - deleteIdentities(prefs, editor); - int ident = 0; - - for (Identity identity : identities) - { - editor.putString(mUuid + ".name." + ident, identity.getName()); - editor.putString(mUuid + ".email." + ident, identity.getEmail()); - editor.putBoolean(mUuid + ".signatureUse." + ident, identity.getSignatureUse()); - editor.putString(mUuid + ".signature." + ident, identity.getSignature()); - editor.putString(mUuid + ".description." + ident, identity.getDescription()); - ident++; - } - } - - public List getIdentities() - { - return identities; - } - - public void setIdentities(List newIdentities) - { - identities = newIdentities; - } - - public String getUuid() - { - return mUuid; - } - - public String getStoreUri() - { - return mStoreUri; - } - - public void setStoreUri(String storeUri) - { - this.mStoreUri = storeUri; - } - - public String getTransportUri() - { - return mTransportUri; - } - - public void setTransportUri(String transportUri) - { - this.mTransportUri = transportUri; - } - - public String getDescription() - { - return mDescription; - } - - public void setDescription(String description) - { - this.mDescription = description; - } - - public String getName() - { - return identities.get(0).getName(); - } - - public void setName(String name) - { - identities.get(0).setName(name); - } - - public boolean getSignatureUse() - { - return identities.get(0).getSignatureUse(); - } - - public void setSignatureUse(boolean signatureUse) - { - identities.get(0).setSignatureUse(signatureUse); - } - - public String getSignature() - { - return identities.get(0).getSignature(); - } - - public void setSignature(String signature) - { - identities.get(0).setSignature(signature); - } - - public String getEmail() - { - return identities.get(0).getEmail(); - } - - public void setEmail(String email) - { - identities.get(0).setEmail(email); - } - - public String getAlwaysBcc() - { - return mAlwaysBcc; - } - - public void setAlwaysBcc(String alwaysBcc) - { - this.mAlwaysBcc = alwaysBcc; - } - - public Identity getIdentity(int i) - { - if (i < identities.size()) - { - return identities.get(i); - } - return null; - } - - public boolean isVibrate() - { - return mVibrate; - } - - public void setVibrate(boolean vibrate) - { - mVibrate = vibrate; - } - - public String getRingtone() - { - return mRingtoneUri; - } - - public void setRingtone(String ringtoneUri) - { - mRingtoneUri = ringtoneUri; - } - - public void delete(Preferences preferences) - { - String[] uuids = preferences.getPreferences().getString("accountUuids", "").split(","); - StringBuffer sb = new StringBuffer(); - for (int i = 0, length = uuids.length; i < length; i++) - { - if (!uuids[i].equals(mUuid)) - { - if (sb.length() > 0) - { - sb.append(','); - } - sb.append(uuids[i]); - } - } - String accountUuids = sb.toString(); - SharedPreferences.Editor editor = preferences.getPreferences().edit(); - editor.putString("accountUuids", accountUuids); - - editor.remove(mUuid + ".storeUri"); - editor.remove(mUuid + ".localStoreUri"); - editor.remove(mUuid + ".transportUri"); - editor.remove(mUuid + ".description"); - editor.remove(mUuid + ".name"); - editor.remove(mUuid + ".email"); - editor.remove(mUuid + ".alwaysBcc"); - editor.remove(mUuid + ".automaticCheckIntervalMinutes"); - editor.remove(mUuid + ".lastAutomaticCheckTime"); - editor.remove(mUuid + ".notifyNewMail"); - editor.remove(mUuid + ".notifySelfNewMail"); - editor.remove(mUuid + ".deletePolicy"); - editor.remove(mUuid + ".draftsFolderName"); - editor.remove(mUuid + ".sentFolderName"); - editor.remove(mUuid + ".trashFolderName"); - editor.remove(mUuid + ".outboxFolderName"); - editor.remove(mUuid + ".autoExpandFolderName"); - editor.remove(mUuid + ".accountNumber"); - editor.remove(mUuid + ".vibrate"); - editor.remove(mUuid + ".ring"); - editor.remove(mUuid + ".ringtone"); - editor.remove(mUuid + ".lastFullSync"); - editor.remove(mUuid + ".folderDisplayMode"); - editor.remove(mUuid + ".folderSyncMode"); - editor.remove(mUuid + ".folderPushMode"); - editor.remove(mUuid + ".folderTargetMode"); - editor.remove(mUuid + ".hideButtonsEnum"); - editor.remove(mUuid + ".signatureBeforeQuotedText"); - editor.remove(mUuid + ".expungePolicy"); - editor.remove(mUuid + ".maxPushFolders"); - deleteIdentities(preferences.getPreferences(), editor); - editor.commit(); - } - - public void save(Preferences preferences) - { - SharedPreferences.Editor editor = preferences.getPreferences().edit(); - - if (!preferences.getPreferences().getString("accountUuids", "").contains(mUuid)) - { - /* - * When the account is first created we assign it a unique account number. The - * account number will be unique to that account for the lifetime of the account. - * So, we get all the existing account numbers, sort them ascending, loop through - * the list and check if the number is greater than 1 + the previous number. If so - * we use the previous number + 1 as the account number. This refills gaps. - * mAccountNumber starts as -1 on a newly created account. It must be -1 for this - * algorithm to work. - * - * I bet there is a much smarter way to do this. Anyone like to suggest it? - */ - Account[] accounts = preferences.getAccounts(); - int[] accountNumbers = new int[accounts.length]; - for (int i = 0; i < accounts.length; i++) - { - accountNumbers[i] = accounts[i].getAccountNumber(); - } - Arrays.sort(accountNumbers); - for (int accountNumber : accountNumbers) - { - if (accountNumber > mAccountNumber + 1) - { - break; - } - mAccountNumber = accountNumber; - } - mAccountNumber++; - - String accountUuids = preferences.getPreferences().getString("accountUuids", ""); - accountUuids += (accountUuids.length() != 0 ? "," : "") + mUuid; - editor.putString("accountUuids", accountUuids); - } - - editor.putString(mUuid + ".storeUri", Utility.base64Encode(mStoreUri)); - editor.putString(mUuid + ".localStoreUri", mLocalStoreUri); - editor.putString(mUuid + ".transportUri", Utility.base64Encode(mTransportUri)); - editor.putString(mUuid + ".description", mDescription); - editor.putString(mUuid + ".alwaysBcc", mAlwaysBcc); - editor.putInt(mUuid + ".automaticCheckIntervalMinutes", mAutomaticCheckIntervalMinutes); - editor.putInt(mUuid + ".displayCount", mDisplayCount); - editor.putLong(mUuid + ".lastAutomaticCheckTime", mLastAutomaticCheckTime); - editor.putBoolean(mUuid + ".notifyNewMail", mNotifyNewMail); - editor.putBoolean(mUuid + ".notifySelfNewMail", mNotifySelfNewMail); - editor.putBoolean(mUuid + ".notifyMailCheck", mNotifySync); - editor.putInt(mUuid + ".deletePolicy", mDeletePolicy); - editor.putString(mUuid + ".draftsFolderName", mDraftsFolderName); - editor.putString(mUuid + ".sentFolderName", mSentFolderName); - editor.putString(mUuid + ".trashFolderName", mTrashFolderName); - editor.putString(mUuid + ".outboxFolderName", mOutboxFolderName); - editor.putString(mUuid + ".autoExpandFolderName", mAutoExpandFolderName); - editor.putInt(mUuid + ".accountNumber", mAccountNumber); - editor.putBoolean(mUuid + ".vibrate", mVibrate); - editor.putBoolean(mUuid + ".ring", mRing); - editor.putString(mUuid + ".hideButtonsEnum", mHideMessageViewButtons.name()); - editor.putString(mUuid + ".ringtone", mRingtoneUri); - editor.putString(mUuid + ".folderDisplayMode", mFolderDisplayMode.name()); - editor.putString(mUuid + ".folderSyncMode", mFolderSyncMode.name()); - editor.putString(mUuid + ".folderPushMode", mFolderPushMode.name()); - editor.putString(mUuid + ".folderTargetMode", mFolderTargetMode.name()); - editor.putBoolean(mUuid + ".signatureBeforeQuotedText", this.mIsSignatureBeforeQuotedText); - editor.putString(mUuid + ".expungePolicy", mExpungePolicy); - editor.putInt(mUuid + ".maxPushFolders", mMaxPushFolders); - saveIdentities(preferences.getPreferences(), editor); - - editor.commit(); - } - - public String toString() - { - return mDescription; - } - - public Uri getContentUri() - { - return Uri.parse("content://accounts/" + getUuid()); - } - - public String getLocalStoreUri() - { - return mLocalStoreUri; - } - - public void setLocalStoreUri(String localStoreUri) - { - this.mLocalStoreUri = localStoreUri; - } - - /** - * Returns -1 for never. - */ - public int getAutomaticCheckIntervalMinutes() - { - return mAutomaticCheckIntervalMinutes; - } - - public int getUnreadMessageCount(Context context, Application application) throws MessagingException - { - int unreadMessageCount = 0; - LocalStore localStore = (LocalStore) Store.getInstance( - getLocalStoreUri(), - application); - Account.FolderMode aMode = getFolderDisplayMode(); - Preferences prefs = Preferences.getPreferences(context); - for (LocalFolder folder : localStore.getPersonalNamespaces()) - { - folder.refresh(prefs); - Folder.FolderClass fMode = folder.getDisplayClass(); - - if (folder.getName().equals(getTrashFolderName()) == false && - folder.getName().equals(getDraftsFolderName()) == false && - folder.getName().equals(getOutboxFolderName()) == false && - folder.getName().equals(getSentFolderName()) == false && - folder.getName().equals(getErrorFolderName()) == false) - { - if (aMode == Account.FolderMode.NONE) - { - continue; - } - if (aMode == Account.FolderMode.FIRST_CLASS && - fMode != Folder.FolderClass.FIRST_CLASS) - { - continue; - } - if (aMode == Account.FolderMode.FIRST_AND_SECOND_CLASS && - fMode != Folder.FolderClass.FIRST_CLASS && - fMode != Folder.FolderClass.SECOND_CLASS) - { - continue; - } - if (aMode == Account.FolderMode.NOT_SECOND_CLASS && - fMode == Folder.FolderClass.SECOND_CLASS) - { - continue; - } - unreadMessageCount += folder.getUnreadMessageCount(); - } - } - - return unreadMessageCount; - - } - - public boolean isAnIdentity(Address[] addrs) - { - if (addrs == null) - { - return false; - } - for (Address addr : addrs) - { - if (findIdentity(addr) != null) - { - return true; - } - } - - return false; - } - - public boolean isAnIdentity(Address addr) - { - return findIdentity(addr) != null; - } - - public Identity findIdentity(Address addr) - { - for (Identity identity : identities) - { - String email = identity.getEmail(); - if (email != null && email.equalsIgnoreCase(addr.getAddress())) - { - return identity; - } - } - return null; - } - - public int getDisplayCount() - { - if (mDisplayCount == -1) - { - this.mDisplayCount = K9.DEFAULT_VISIBLE_LIMIT; - } - return mDisplayCount; - } - - /** - * @param automaticCheckIntervalMinutes or -1 for never. - */ - public boolean setAutomaticCheckIntervalMinutes(int automaticCheckIntervalMinutes) - { - int oldInterval = this.mAutomaticCheckIntervalMinutes; - int newInterval = automaticCheckIntervalMinutes; - this.mAutomaticCheckIntervalMinutes = automaticCheckIntervalMinutes; - - return (oldInterval != newInterval); - } - - /** - * @param displayCount - */ - public void setDisplayCount(int displayCount) - { - if (displayCount != -1) - { - this.mDisplayCount = displayCount; - } - else - { - this.mDisplayCount = K9.DEFAULT_VISIBLE_LIMIT; - } - } - - public long getLastAutomaticCheckTime() - { - return mLastAutomaticCheckTime; - } - - public void setLastAutomaticCheckTime(long lastAutomaticCheckTime) - { - this.mLastAutomaticCheckTime = lastAutomaticCheckTime; - } - - public boolean isNotifyNewMail() - { - return mNotifyNewMail; - } - - public void setNotifyNewMail(boolean notifyNewMail) - { - this.mNotifyNewMail = notifyNewMail; - } - - public int getDeletePolicy() - { - return mDeletePolicy; - } - - public void setDeletePolicy(int deletePolicy) - { - this.mDeletePolicy = deletePolicy; - } - - public String getDraftsFolderName() - { - return mDraftsFolderName; - } - - public void setDraftsFolderName(String draftsFolderName) - { - mDraftsFolderName = draftsFolderName; - } - - public String getSentFolderName() - { - return mSentFolderName; - } - - public String getErrorFolderName() - { - return K9.ERROR_FOLDER_NAME; - } - - public void setSentFolderName(String sentFolderName) - { - mSentFolderName = sentFolderName; - } - - public String getTrashFolderName() - { - return mTrashFolderName; - } - - public void setTrashFolderName(String trashFolderName) - { - mTrashFolderName = trashFolderName; - } - - public String getOutboxFolderName() - { - return mOutboxFolderName; - } - - public void setOutboxFolderName(String outboxFolderName) - { - mOutboxFolderName = outboxFolderName; - } - - public String getAutoExpandFolderName() - { - return mAutoExpandFolderName; - } - - public void setAutoExpandFolderName(String autoExpandFolderName) - { - mAutoExpandFolderName = autoExpandFolderName; - } - - public int getAccountNumber() - { - return mAccountNumber; - } - - @Override - public boolean equals(Object o) - { - if (o instanceof Account) - { - return ((Account)o).mUuid.equals(mUuid); - } - return super.equals(o); - } - - @Override - public int hashCode() - { - return mUuid.hashCode(); - } - - public FolderMode getFolderDisplayMode() - { - return mFolderDisplayMode; - } - - public boolean setFolderDisplayMode(FolderMode displayMode) - { - FolderMode oldDisplayMode = mFolderDisplayMode; - mFolderDisplayMode = displayMode; - return oldDisplayMode != displayMode; - } - - public FolderMode getFolderSyncMode() - { - return mFolderSyncMode; - } - - public boolean setFolderSyncMode(FolderMode syncMode) - { - FolderMode oldSyncMode = mFolderSyncMode; - mFolderSyncMode = syncMode; - - if (syncMode == FolderMode.NONE && oldSyncMode != FolderMode.NONE) - { - return true; - } - if (syncMode != FolderMode.NONE && oldSyncMode == FolderMode.NONE) - { - return true; - } - return false; - } - - public FolderMode getFolderPushMode() - { - return mFolderPushMode; - } - - public boolean setFolderPushMode(FolderMode pushMode) - { - FolderMode oldPushMode = mFolderPushMode; - - mFolderPushMode = pushMode; - return pushMode != oldPushMode; - } - - public boolean isShowOngoing() - { - return mNotifySync; - } - - public void setShowOngoing(boolean showOngoing) - { - this.mNotifySync = showOngoing; - } - - public HideButtons getHideMessageViewButtons() - { - return mHideMessageViewButtons; - } - - public void setHideMessageViewButtons(HideButtons hideMessageViewButtons) - { - mHideMessageViewButtons = hideMessageViewButtons; - } - - public FolderMode getFolderTargetMode() - { - return mFolderTargetMode; - } - - public void setFolderTargetMode(FolderMode folderTargetMode) - { - mFolderTargetMode = folderTargetMode; - } - - public boolean isSignatureBeforeQuotedText() - { - return mIsSignatureBeforeQuotedText; - } - - public void setSignatureBeforeQuotedText(boolean mIsSignatureBeforeQuotedText) - { - this.mIsSignatureBeforeQuotedText = mIsSignatureBeforeQuotedText; - } - - public boolean isNotifySelfNewMail() - { - return mNotifySelfNewMail; - } - - public void setNotifySelfNewMail(boolean notifySelfNewMail) - { - mNotifySelfNewMail = notifySelfNewMail; - } - - public String getExpungePolicy() - { - return mExpungePolicy; - } - - public void setExpungePolicy(String expungePolicy) - { - mExpungePolicy = expungePolicy; - } - - public int getMaxPushFolders() - { - return mMaxPushFolders; - } - - public boolean setMaxPushFolders(int maxPushFolders) - { - int oldMaxPushFolders = mMaxPushFolders; - mMaxPushFolders = maxPushFolders; - return oldMaxPushFolders != maxPushFolders; - } - - public boolean isRing() - { - return mRing; - } - - public void setRing(boolean ring) - { - mRing = ring; - } - -} + +package com.fsck.k9; + +import android.content.Context; +import android.content.SharedPreferences; +import android.net.Uri; +import com.fsck.k9.mail.Address; +import com.fsck.k9.mail.Folder; +import com.fsck.k9.mail.MessagingException; +import com.fsck.k9.mail.Store; +import com.fsck.k9.mail.store.LocalStore; +import com.fsck.k9.mail.store.LocalStore.LocalFolder; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +/** + * Account stores all of the settings for a single account defined by the user. It is able to save + * and delete itself given a Preferences to work with. Each account is defined by a UUID. + */ +public class Account +{ + public static final String EXPUNGE_IMMEDIATELY = "EXPUNGE_IMMEDIATELY"; + public static final String EXPUNGE_MANUALLY = "EXPUNGE_MANUALLY"; + public static final String EXPUNGE_ON_POLL = "EXPUNGE_ON_POLL"; + + public static final int DELETE_POLICY_NEVER = 0; + public static final int DELETE_POLICY_7DAYS = 1; + public static final int DELETE_POLICY_ON_DELETE = 2; + public static final int DELETE_POLICY_MARK_AS_READ = 3; + + /** + *
+     * 0 - Never (DELETE_POLICY_NEVER)
+     * 1 - After 7 days (DELETE_POLICY_7DAYS)
+     * 2 - When I delete from inbox (DELETE_POLICY_ON_DELETE)
+     * 3 - Mark as read (DELETE_POLICY_MARK_AS_READ)
+     * 
+ */ + private int mDeletePolicy; + + private String mUuid; + private String mStoreUri; + private String mLocalStoreUri; + private String mTransportUri; + private String mDescription; + private String mAlwaysBcc; + private int mAutomaticCheckIntervalMinutes; + private int mDisplayCount; + private long mLastAutomaticCheckTime; + private boolean mNotifyNewMail; + private boolean mNotifySelfNewMail; + private String mDraftsFolderName; + private String mSentFolderName; + private String mTrashFolderName; + private String mOutboxFolderName; + private String mAutoExpandFolderName; + private FolderMode mFolderDisplayMode; + private FolderMode mFolderSyncMode; + private FolderMode mFolderPushMode; + private FolderMode mFolderTargetMode; + private int mAccountNumber; + private boolean mVibrate; + private boolean mRing; + private String mRingtoneUri; + private boolean mNotifySync; + private HideButtons mHideMessageViewButtons; + private boolean mIsSignatureBeforeQuotedText; + private String mExpungePolicy = EXPUNGE_IMMEDIATELY; + private int mMaxPushFolders; + + private List identities; + + public enum FolderMode + { + NONE, ALL, FIRST_CLASS, FIRST_AND_SECOND_CLASS, NOT_SECOND_CLASS; + } + + public enum HideButtons + { + NEVER, ALWAYS, KEYBOARD_AVAILABLE; + } + + + protected Account(Context context) + { + // TODO Change local store path to something readable / recognizable + mUuid = UUID.randomUUID().toString(); + mLocalStoreUri = "local://localhost/" + context.getDatabasePath(mUuid + ".db"); + mAutomaticCheckIntervalMinutes = -1; + mDisplayCount = -1; + mAccountNumber = -1; + mNotifyNewMail = true; + mNotifySync = true; + mVibrate = false; + mRing = true; + mNotifySelfNewMail = true; + mFolderDisplayMode = FolderMode.NOT_SECOND_CLASS; + mFolderSyncMode = FolderMode.FIRST_CLASS; + mFolderPushMode = FolderMode.FIRST_CLASS; + mFolderTargetMode = FolderMode.NOT_SECOND_CLASS; + mHideMessageViewButtons = HideButtons.NEVER; + mRingtoneUri = "content://settings/system/notification_sound"; + mIsSignatureBeforeQuotedText = false; + mExpungePolicy = EXPUNGE_IMMEDIATELY; + mAutoExpandFolderName = "INBOX"; + mMaxPushFolders = 10; + + identities = new ArrayList(); + + Identity identity = new Identity(); + identity.setSignatureUse(true); + identity.setSignature(context.getString(R.string.default_signature)); + identity.setDescription(context.getString(R.string.default_identity_description)); + identities.add(identity); + } + + protected Account(Preferences preferences, String uuid) + { + this.mUuid = uuid; + loadAccount(preferences); + } + + /** + * Load stored settings for this account. + */ + private synchronized void loadAccount(Preferences preferences) + { + mStoreUri = Utility.base64Decode(preferences.getPreferences().getString(mUuid + + ".storeUri", null)); + mLocalStoreUri = preferences.getPreferences().getString(mUuid + ".localStoreUri", null); + mTransportUri = Utility.base64Decode(preferences.getPreferences().getString(mUuid + + ".transportUri", null)); + mDescription = preferences.getPreferences().getString(mUuid + ".description", null); + mAlwaysBcc = preferences.getPreferences().getString(mUuid + ".alwaysBcc", mAlwaysBcc); + mAutomaticCheckIntervalMinutes = preferences.getPreferences().getInt(mUuid + + ".automaticCheckIntervalMinutes", -1); + mDisplayCount = preferences.getPreferences().getInt(mUuid + ".displayCount", -1); + mLastAutomaticCheckTime = preferences.getPreferences().getLong(mUuid + + ".lastAutomaticCheckTime", 0); + mNotifyNewMail = preferences.getPreferences().getBoolean(mUuid + ".notifyNewMail", + false); + mNotifySelfNewMail = preferences.getPreferences().getBoolean(mUuid + ".notifySelfNewMail", + true); + mNotifySync = preferences.getPreferences().getBoolean(mUuid + ".notifyMailCheck", + false); + mDeletePolicy = preferences.getPreferences().getInt(mUuid + ".deletePolicy", 0); + mDraftsFolderName = preferences.getPreferences().getString(mUuid + ".draftsFolderName", + "Drafts"); + mSentFolderName = preferences.getPreferences().getString(mUuid + ".sentFolderName", + "Sent"); + mTrashFolderName = preferences.getPreferences().getString(mUuid + ".trashFolderName", + "Trash"); + mOutboxFolderName = preferences.getPreferences().getString(mUuid + ".outboxFolderName", + "Outbox"); + mExpungePolicy = preferences.getPreferences().getString(mUuid + ".expungePolicy", EXPUNGE_IMMEDIATELY); + + mMaxPushFolders = preferences.getPreferences().getInt(mUuid + ".maxPushFolders", 10); + + // Between r418 and r431 (version 0.103), folder names were set empty if the Incoming settings were + // opened for non-IMAP accounts. 0.103 was never a market release, so perhaps this code + // should be deleted sometime soon + if (mDraftsFolderName == null || mDraftsFolderName.equals("")) + { + mDraftsFolderName = "Drafts"; + } + if (mSentFolderName == null || mSentFolderName.equals("")) + { + mSentFolderName = "Sent"; + } + if (mTrashFolderName == null || mTrashFolderName.equals("")) + { + mTrashFolderName = "Trash"; + } + if (mOutboxFolderName == null || mOutboxFolderName.equals("")) + { + mOutboxFolderName = "Outbox"; + } + // End of 0.103 repair + + mAutoExpandFolderName = preferences.getPreferences().getString(mUuid + ".autoExpandFolderName", + "INBOX"); + + mAccountNumber = preferences.getPreferences().getInt(mUuid + ".accountNumber", 0); + mVibrate = preferences.getPreferences().getBoolean(mUuid + ".vibrate", false); + mRing = preferences.getPreferences().getBoolean(mUuid + ".ring", true); + + try + { + mHideMessageViewButtons = HideButtons.valueOf(preferences.getPreferences().getString(mUuid + ".hideButtonsEnum", + HideButtons.NEVER.name())); + } + catch (Exception e) + { + mHideMessageViewButtons = HideButtons.NEVER; + } + + mRingtoneUri = preferences.getPreferences().getString(mUuid + ".ringtone", + "content://settings/system/notification_sound"); + try + { + mFolderDisplayMode = FolderMode.valueOf(preferences.getPreferences().getString(mUuid + ".folderDisplayMode", + FolderMode.NOT_SECOND_CLASS.name())); + } + catch (Exception e) + { + mFolderDisplayMode = FolderMode.NOT_SECOND_CLASS; + } + + try + { + mFolderSyncMode = FolderMode.valueOf(preferences.getPreferences().getString(mUuid + ".folderSyncMode", + FolderMode.FIRST_CLASS.name())); + } + catch (Exception e) + { + mFolderSyncMode = FolderMode.FIRST_CLASS; + } + + try + { + mFolderPushMode = FolderMode.valueOf(preferences.getPreferences().getString(mUuid + ".folderPushMode", + FolderMode.FIRST_CLASS.name())); + } + catch (Exception e) + { + mFolderPushMode = FolderMode.FIRST_CLASS; + } + + try + { + mFolderTargetMode = FolderMode.valueOf(preferences.getPreferences().getString(mUuid + ".folderTargetMode", + FolderMode.NOT_SECOND_CLASS.name())); + } + catch (Exception e) + { + mFolderTargetMode = FolderMode.NOT_SECOND_CLASS; + } + + mIsSignatureBeforeQuotedText = preferences.getPreferences().getBoolean(mUuid + ".signatureBeforeQuotedText", false); + identities = loadIdentities(preferences.getPreferences()); + } + + + protected synchronized void delete(Preferences preferences) + { + String[] uuids = preferences.getPreferences().getString("accountUuids", "").split(","); + StringBuffer sb = new StringBuffer(); + for (int i = 0, length = uuids.length; i < length; i++) + { + if (!uuids[i].equals(mUuid)) + { + if (sb.length() > 0) + { + sb.append(','); + } + sb.append(uuids[i]); + } + } + String accountUuids = sb.toString(); + SharedPreferences.Editor editor = preferences.getPreferences().edit(); + editor.putString("accountUuids", accountUuids); + + editor.remove(mUuid + ".storeUri"); + editor.remove(mUuid + ".localStoreUri"); + editor.remove(mUuid + ".transportUri"); + editor.remove(mUuid + ".description"); + editor.remove(mUuid + ".name"); + editor.remove(mUuid + ".email"); + editor.remove(mUuid + ".alwaysBcc"); + editor.remove(mUuid + ".automaticCheckIntervalMinutes"); + editor.remove(mUuid + ".lastAutomaticCheckTime"); + editor.remove(mUuid + ".notifyNewMail"); + editor.remove(mUuid + ".notifySelfNewMail"); + editor.remove(mUuid + ".deletePolicy"); + editor.remove(mUuid + ".draftsFolderName"); + editor.remove(mUuid + ".sentFolderName"); + editor.remove(mUuid + ".trashFolderName"); + editor.remove(mUuid + ".outboxFolderName"); + editor.remove(mUuid + ".autoExpandFolderName"); + editor.remove(mUuid + ".accountNumber"); + editor.remove(mUuid + ".vibrate"); + editor.remove(mUuid + ".ring"); + editor.remove(mUuid + ".ringtone"); + editor.remove(mUuid + ".lastFullSync"); + editor.remove(mUuid + ".folderDisplayMode"); + editor.remove(mUuid + ".folderSyncMode"); + editor.remove(mUuid + ".folderPushMode"); + editor.remove(mUuid + ".folderTargetMode"); + editor.remove(mUuid + ".hideButtonsEnum"); + editor.remove(mUuid + ".signatureBeforeQuotedText"); + editor.remove(mUuid + ".expungePolicy"); + editor.remove(mUuid + ".maxPushFolders"); + deleteIdentities(preferences.getPreferences(), editor); + editor.commit(); + } + + public synchronized void save(Preferences preferences) + { + SharedPreferences.Editor editor = preferences.getPreferences().edit(); + + if (!preferences.getPreferences().getString("accountUuids", "").contains(mUuid)) + { + /* + * When the account is first created we assign it a unique account number. The + * account number will be unique to that account for the lifetime of the account. + * So, we get all the existing account numbers, sort them ascending, loop through + * the list and check if the number is greater than 1 + the previous number. If so + * we use the previous number + 1 as the account number. This refills gaps. + * mAccountNumber starts as -1 on a newly created account. It must be -1 for this + * algorithm to work. + * + * I bet there is a much smarter way to do this. Anyone like to suggest it? + */ + Account[] accounts = preferences.getAccounts(); + int[] accountNumbers = new int[accounts.length]; + for (int i = 0; i < accounts.length; i++) + { + accountNumbers[i] = accounts[i].getAccountNumber(); + } + Arrays.sort(accountNumbers); + for (int accountNumber : accountNumbers) + { + if (accountNumber > mAccountNumber + 1) + { + break; + } + mAccountNumber = accountNumber; + } + mAccountNumber++; + + String accountUuids = preferences.getPreferences().getString("accountUuids", ""); + accountUuids += (accountUuids.length() != 0 ? "," : "") + mUuid; + editor.putString("accountUuids", accountUuids); + } + + editor.putString(mUuid + ".storeUri", Utility.base64Encode(mStoreUri)); + editor.putString(mUuid + ".localStoreUri", mLocalStoreUri); + editor.putString(mUuid + ".transportUri", Utility.base64Encode(mTransportUri)); + editor.putString(mUuid + ".description", mDescription); + editor.putString(mUuid + ".alwaysBcc", mAlwaysBcc); + editor.putInt(mUuid + ".automaticCheckIntervalMinutes", mAutomaticCheckIntervalMinutes); + editor.putInt(mUuid + ".displayCount", mDisplayCount); + editor.putLong(mUuid + ".lastAutomaticCheckTime", mLastAutomaticCheckTime); + editor.putBoolean(mUuid + ".notifyNewMail", mNotifyNewMail); + editor.putBoolean(mUuid + ".notifySelfNewMail", mNotifySelfNewMail); + editor.putBoolean(mUuid + ".notifyMailCheck", mNotifySync); + editor.putInt(mUuid + ".deletePolicy", mDeletePolicy); + editor.putString(mUuid + ".draftsFolderName", mDraftsFolderName); + editor.putString(mUuid + ".sentFolderName", mSentFolderName); + editor.putString(mUuid + ".trashFolderName", mTrashFolderName); + editor.putString(mUuid + ".outboxFolderName", mOutboxFolderName); + editor.putString(mUuid + ".autoExpandFolderName", mAutoExpandFolderName); + editor.putInt(mUuid + ".accountNumber", mAccountNumber); + editor.putBoolean(mUuid + ".vibrate", mVibrate); + editor.putBoolean(mUuid + ".ring", mRing); + editor.putString(mUuid + ".hideButtonsEnum", mHideMessageViewButtons.name()); + editor.putString(mUuid + ".ringtone", mRingtoneUri); + editor.putString(mUuid + ".folderDisplayMode", mFolderDisplayMode.name()); + editor.putString(mUuid + ".folderSyncMode", mFolderSyncMode.name()); + editor.putString(mUuid + ".folderPushMode", mFolderPushMode.name()); + editor.putString(mUuid + ".folderTargetMode", mFolderTargetMode.name()); + editor.putBoolean(mUuid + ".signatureBeforeQuotedText", this.mIsSignatureBeforeQuotedText); + editor.putString(mUuid + ".expungePolicy", mExpungePolicy); + editor.putInt(mUuid + ".maxPushFolders", mMaxPushFolders); + saveIdentities(preferences.getPreferences(), editor); + + editor.commit(); + + } + + //TODO: Shouldn't this live in MessagingController? + public int getUnreadMessageCount(Context context) throws MessagingException + { + int unreadMessageCount = 0; + LocalStore localStore = getLocalStore(); + Account.FolderMode aMode = getFolderDisplayMode(); + Preferences prefs = Preferences.getPreferences(context); + for (LocalFolder folder : localStore.getPersonalNamespaces()) + { + folder.refresh(prefs); + Folder.FolderClass fMode = folder.getDisplayClass(); + + if (folder.getName().equals(getTrashFolderName()) == false && + folder.getName().equals(getDraftsFolderName()) == false && + folder.getName().equals(getOutboxFolderName()) == false && + folder.getName().equals(getSentFolderName()) == false && + folder.getName().equals(getErrorFolderName()) == false) + { + if (aMode == Account.FolderMode.NONE) + { + continue; + } + if (aMode == Account.FolderMode.FIRST_CLASS && + fMode != Folder.FolderClass.FIRST_CLASS) + { + continue; + } + if (aMode == Account.FolderMode.FIRST_AND_SECOND_CLASS && + fMode != Folder.FolderClass.FIRST_CLASS && + fMode != Folder.FolderClass.SECOND_CLASS) + { + continue; + } + if (aMode == Account.FolderMode.NOT_SECOND_CLASS && + fMode == Folder.FolderClass.SECOND_CLASS) + { + continue; + } + unreadMessageCount += folder.getUnreadMessageCount(); + } + } + + return unreadMessageCount; + } + + public String getUuid() + { + return mUuid; + } + + public Uri getContentUri() + { + return Uri.parse("content://accounts/" + getUuid()); + } + + public synchronized String getStoreUri() + { + return mStoreUri; + } + + public synchronized void setStoreUri(String storeUri) + { + this.mStoreUri = storeUri; + } + + public synchronized String getTransportUri() + { + return mTransportUri; + } + + public synchronized void setTransportUri(String transportUri) + { + this.mTransportUri = transportUri; + } + + public synchronized String getDescription() + { + return mDescription; + } + + public synchronized void setDescription(String description) + { + this.mDescription = description; + } + + public synchronized String getName() + { + return identities.get(0).getName(); + } + + public synchronized void setName(String name) + { + identities.get(0).setName(name); + } + + public synchronized boolean getSignatureUse() + { + return identities.get(0).getSignatureUse(); + } + + public synchronized void setSignatureUse(boolean signatureUse) + { + identities.get(0).setSignatureUse(signatureUse); + } + + public synchronized String getSignature() + { + return identities.get(0).getSignature(); + } + + public synchronized void setSignature(String signature) + { + identities.get(0).setSignature(signature); + } + + public synchronized String getEmail() + { + return identities.get(0).getEmail(); + } + + public synchronized void setEmail(String email) + { + identities.get(0).setEmail(email); + } + + public synchronized String getAlwaysBcc() + { + return mAlwaysBcc; + } + + public synchronized void setAlwaysBcc(String alwaysBcc) + { + this.mAlwaysBcc = alwaysBcc; + } + + public synchronized boolean isVibrate() + { + return mVibrate; + } + + public synchronized void setVibrate(boolean vibrate) + { + mVibrate = vibrate; + } + + public synchronized String getRingtone() + { + return mRingtoneUri; + } + + public synchronized void setRingtone(String ringtoneUri) + { + mRingtoneUri = ringtoneUri; + } + + public synchronized String getLocalStoreUri() + { + return mLocalStoreUri; + } + + public synchronized void setLocalStoreUri(String localStoreUri) + { + this.mLocalStoreUri = localStoreUri; + } + + /** + * Returns -1 for never. + */ + public synchronized int getAutomaticCheckIntervalMinutes() + { + return mAutomaticCheckIntervalMinutes; + } + + /** + * @param automaticCheckIntervalMinutes or -1 for never. + */ + public synchronized boolean setAutomaticCheckIntervalMinutes(int automaticCheckIntervalMinutes) + { + int oldInterval = this.mAutomaticCheckIntervalMinutes; + int newInterval = automaticCheckIntervalMinutes; + this.mAutomaticCheckIntervalMinutes = automaticCheckIntervalMinutes; + + return (oldInterval != newInterval); + } + + public synchronized int getDisplayCount() + { + if (mDisplayCount == -1) + { + this.mDisplayCount = K9.DEFAULT_VISIBLE_LIMIT; + } + return mDisplayCount; + } + + public synchronized void setDisplayCount(int displayCount) + { + if (displayCount != -1) + { + this.mDisplayCount = displayCount; + } + else + { + this.mDisplayCount = K9.DEFAULT_VISIBLE_LIMIT; + } + } + + public synchronized long getLastAutomaticCheckTime() + { + return mLastAutomaticCheckTime; + } + + public synchronized void setLastAutomaticCheckTime(long lastAutomaticCheckTime) + { + this.mLastAutomaticCheckTime = lastAutomaticCheckTime; + } + + public synchronized boolean isNotifyNewMail() + { + return mNotifyNewMail; + } + + public synchronized void setNotifyNewMail(boolean notifyNewMail) + { + this.mNotifyNewMail = notifyNewMail; + } + + public synchronized int getDeletePolicy() + { + return mDeletePolicy; + } + + public synchronized void setDeletePolicy(int deletePolicy) + { + this.mDeletePolicy = deletePolicy; + } + + public synchronized String getDraftsFolderName() + { + return mDraftsFolderName; + } + + public synchronized void setDraftsFolderName(String draftsFolderName) + { + mDraftsFolderName = draftsFolderName; + } + + public synchronized String getSentFolderName() + { + return mSentFolderName; + } + + public synchronized String getErrorFolderName() + { + return K9.ERROR_FOLDER_NAME; + } + + public synchronized void setSentFolderName(String sentFolderName) + { + mSentFolderName = sentFolderName; + } + + public synchronized String getTrashFolderName() + { + return mTrashFolderName; + } + + public synchronized void setTrashFolderName(String trashFolderName) + { + mTrashFolderName = trashFolderName; + } + + public synchronized String getOutboxFolderName() + { + return mOutboxFolderName; + } + + public synchronized void setOutboxFolderName(String outboxFolderName) + { + mOutboxFolderName = outboxFolderName; + } + + public synchronized String getAutoExpandFolderName() + { + return mAutoExpandFolderName; + } + + public synchronized void setAutoExpandFolderName(String autoExpandFolderName) + { + mAutoExpandFolderName = autoExpandFolderName; + } + + public synchronized int getAccountNumber() + { + return mAccountNumber; + } + + public synchronized FolderMode getFolderDisplayMode() + { + return mFolderDisplayMode; + } + + public synchronized boolean setFolderDisplayMode(FolderMode displayMode) + { + FolderMode oldDisplayMode = mFolderDisplayMode; + mFolderDisplayMode = displayMode; + return oldDisplayMode != displayMode; + } + + public synchronized FolderMode getFolderSyncMode() + { + return mFolderSyncMode; + } + + public synchronized boolean setFolderSyncMode(FolderMode syncMode) + { + FolderMode oldSyncMode = mFolderSyncMode; + mFolderSyncMode = syncMode; + + if (syncMode == FolderMode.NONE && oldSyncMode != FolderMode.NONE) + { + return true; + } + if (syncMode != FolderMode.NONE && oldSyncMode == FolderMode.NONE) + { + return true; + } + return false; + } + + public synchronized FolderMode getFolderPushMode() + { + return mFolderPushMode; + } + + public synchronized boolean setFolderPushMode(FolderMode pushMode) + { + FolderMode oldPushMode = mFolderPushMode; + + mFolderPushMode = pushMode; + return pushMode != oldPushMode; + } + + public synchronized boolean isShowOngoing() + { + return mNotifySync; + } + + public synchronized void setShowOngoing(boolean showOngoing) + { + this.mNotifySync = showOngoing; + } + + public synchronized HideButtons getHideMessageViewButtons() + { + return mHideMessageViewButtons; + } + + public synchronized void setHideMessageViewButtons(HideButtons hideMessageViewButtons) + { + mHideMessageViewButtons = hideMessageViewButtons; + } + + public synchronized FolderMode getFolderTargetMode() + { + return mFolderTargetMode; + } + + public synchronized void setFolderTargetMode(FolderMode folderTargetMode) + { + mFolderTargetMode = folderTargetMode; + } + + public synchronized boolean isSignatureBeforeQuotedText() + { + return mIsSignatureBeforeQuotedText; + } + + public synchronized void setSignatureBeforeQuotedText(boolean mIsSignatureBeforeQuotedText) + { + this.mIsSignatureBeforeQuotedText = mIsSignatureBeforeQuotedText; + } + + public synchronized boolean isNotifySelfNewMail() + { + return mNotifySelfNewMail; + } + + public synchronized void setNotifySelfNewMail(boolean notifySelfNewMail) + { + mNotifySelfNewMail = notifySelfNewMail; + } + + public synchronized String getExpungePolicy() + { + return mExpungePolicy; + } + + public synchronized void setExpungePolicy(String expungePolicy) + { + mExpungePolicy = expungePolicy; + } + + public synchronized int getMaxPushFolders() + { + return mMaxPushFolders; + } + + public synchronized boolean setMaxPushFolders(int maxPushFolders) + { + int oldMaxPushFolders = mMaxPushFolders; + mMaxPushFolders = maxPushFolders; + return oldMaxPushFolders != maxPushFolders; + } + + public synchronized boolean isRing() + { + return mRing; + } + + public synchronized void setRing(boolean ring) + { + mRing = ring; + } + + public LocalStore getLocalStore() throws MessagingException + { + return Store.getLocalInstance(this, K9.app); + } + + public Store getRemoteStore() throws MessagingException + { + return Store.getRemoteInstance(this); + } + + @Override + public synchronized String toString() + { + return mDescription; + } + + @Override + public boolean equals(Object o) + { + if (o instanceof Account) + { + return ((Account)o).mUuid.equals(mUuid); + } + return super.equals(o); + } + + @Override + public int hashCode() + { + return mUuid.hashCode(); + } + + + private synchronized List loadIdentities(SharedPreferences prefs) + { + List newIdentities = new ArrayList(); + int ident = 0; + boolean gotOne = false; + do + { + gotOne = false; + String name = prefs.getString(mUuid + ".name." + ident, null); + String email = prefs.getString(mUuid + ".email." + ident, null); + boolean signatureUse = prefs.getBoolean(mUuid + ".signatureUse." + ident, true); + String signature = prefs.getString(mUuid + ".signature." + ident, null); + String description = prefs.getString(mUuid + ".description." + ident, null); + if (email != null) + { + Identity identity = new Identity(); + identity.setName(name); + identity.setEmail(email); + identity.setSignatureUse(signatureUse); + identity.setSignature(signature); + identity.setDescription(description); + newIdentities.add(identity); + gotOne = true; + } + ident++; + } + while (gotOne); + + if (newIdentities.size() == 0) + { + String name = prefs.getString(mUuid + ".name", null); + String email = prefs.getString(mUuid + ".email", null); + boolean signatureUse = prefs.getBoolean(mUuid + ".signatureUse", true); + String signature = prefs.getString(mUuid + ".signature", null); + Identity identity = new Identity(); + identity.setName(name); + identity.setEmail(email); + identity.setSignatureUse(signatureUse); + identity.setSignature(signature); + identity.setDescription(email); + newIdentities.add(identity); + } + + return newIdentities; + } + + private synchronized void deleteIdentities(SharedPreferences prefs, SharedPreferences.Editor editor) + { + int ident = 0; + boolean gotOne = false; + do + { + gotOne = false; + String email = prefs.getString(mUuid + ".email." + ident, null); + if (email != null) + { + editor.remove(mUuid + ".name." + ident); + editor.remove(mUuid + ".email." + ident); + editor.remove(mUuid + ".signatureUse." + ident); + editor.remove(mUuid + ".signature." + ident); + editor.remove(mUuid + ".description." + ident); + gotOne = true; + } + ident++; + } + while (gotOne); + } + + private synchronized void saveIdentities(SharedPreferences prefs, SharedPreferences.Editor editor) + { + deleteIdentities(prefs, editor); + int ident = 0; + + for (Identity identity : identities) + { + editor.putString(mUuid + ".name." + ident, identity.getName()); + editor.putString(mUuid + ".email." + ident, identity.getEmail()); + editor.putBoolean(mUuid + ".signatureUse." + ident, identity.getSignatureUse()); + editor.putString(mUuid + ".signature." + ident, identity.getSignature()); + editor.putString(mUuid + ".description." + ident, identity.getDescription()); + ident++; + } + } + + public synchronized List getIdentities() + { + return identities; + } + + public synchronized void setIdentities(List newIdentities) + { + identities = new ArrayList(newIdentities); + } + + public synchronized Identity getIdentity(int i) + { + if (i < identities.size()) + { + return identities.get(i); + } + return null; + } + + public boolean isAnIdentity(Address[] addrs) + { + if (addrs == null) + { + return false; + } + for (Address addr : addrs) + { + if (findIdentity(addr) != null) + { + return true; + } + } + + return false; + } + + public boolean isAnIdentity(Address addr) + { + return findIdentity(addr) != null; + } + + public synchronized Identity findIdentity(Address addr) + { + for (Identity identity : identities) + { + String email = identity.getEmail(); + if (email != null && email.equalsIgnoreCase(addr.getAddress())) + { + return identity; + } + } + return null; + } +} diff --git a/src/com/fsck/k9/Identity.java b/src/com/fsck/k9/Identity.java new file mode 100644 index 000000000..92d228701 --- /dev/null +++ b/src/com/fsck/k9/Identity.java @@ -0,0 +1,68 @@ +package com.fsck.k9; + +import java.io.Serializable; + +public class Identity implements Serializable +{ + private String mDescription; + private String mName; + private String mEmail; + private String mSignature; + private boolean mSignatureUse; + + public synchronized String getName() + { + return mName; + } + + public synchronized void setName(String name) + { + mName = name; + } + + public synchronized String getEmail() + { + return mEmail; + } + + public synchronized void setEmail(String email) + { + mEmail = email; + } + + public synchronized boolean getSignatureUse() + { + return mSignatureUse; + } + + public synchronized void setSignatureUse(boolean signatureUse) + { + mSignatureUse = signatureUse; + } + + public synchronized String getSignature() + { + return mSignature; + } + + public synchronized void setSignature(String signature) + { + mSignature = signature; + } + + public synchronized String getDescription() + { + return mDescription; + } + + public synchronized void setDescription(String description) + { + mDescription = description; + } + + @Override + public synchronized String toString() + { + return "Account.Identity(description=" + mDescription + ", name=" + mName + ", email=" + mEmail + ", signature=" + mSignature; + } +} diff --git a/src/com/fsck/k9/MessagingController.java b/src/com/fsck/k9/MessagingController.java index add645963..dbee1ba2c 100644 --- a/src/com/fsck/k9/MessagingController.java +++ b/src/com/fsck/k9/MessagingController.java @@ -23,7 +23,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.PriorityBlockingQueue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; - import android.app.Application; import android.app.Notification; import android.app.NotificationManager; @@ -36,7 +35,6 @@ import android.os.Process; import android.os.PowerManager.WakeLock; import android.text.TextUtils; import android.util.Log; - import com.fsck.k9.activity.FolderList; import com.fsck.k9.activity.MessageList; import com.fsck.k9.mail.Address; @@ -62,6 +60,7 @@ import com.fsck.k9.mail.store.LocalStore.LocalFolder; import com.fsck.k9.mail.store.LocalStore.LocalMessage; import com.fsck.k9.mail.store.LocalStore.PendingCommand; + /** * Starts a long running (application) Thread that will run through commands * that require remote mailbox access. This class is used to serialize and @@ -422,7 +421,7 @@ public class MessagingController implements Runnable Folder[] localFolders = null; try { - Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); + Store localStore = account.getLocalStore(); localFolders = localStore.getPersonalNamespaces(); if (refreshRemote || localFolders == null || localFolders.length == 0) @@ -487,11 +486,11 @@ public class MessagingController implements Runnable Folder[] localFolders = null; try { - Store store = Store.getInstance(account.getStoreUri(), mApplication); + Store store = account.getRemoteStore(); Folder[] remoteFolders = store.getPersonalNamespaces(); - LocalStore localStore = (LocalStore)Store.getInstance(account.getLocalStoreUri(), mApplication); + LocalStore localStore = account.getLocalStore(); HashSet remoteFolderNames = new HashSet(); for (int i = 0, count = remoteFolders.length; i < count; i++) { @@ -664,7 +663,7 @@ public class MessagingController implements Runnable try { - Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); + Store localStore = account.getLocalStore(); localFolder = localStore.getFolder(folder); localFolder.open(OpenMode.READ_WRITE); @@ -756,8 +755,7 @@ public class MessagingController implements Runnable try { - LocalStore localStore = (LocalStore)Store.getInstance(account.getLocalStoreUri(), mApplication); - + LocalStore localStore = account.getLocalStore(); localStore.searchForMessages(retrievalListener, query); } catch (Exception e) @@ -778,8 +776,8 @@ public class MessagingController implements Runnable { try { - LocalStore localStore = (LocalStore) Store.getInstance(account.getLocalStoreUri(), mApplication); - LocalFolder localFolder = (LocalFolder) localStore.getFolder(folder); + LocalStore localStore = account.getLocalStore(); + LocalFolder localFolder = localStore.getFolder(folder); localFolder.setVisibleLimit(localFolder.getVisibleLimit() + account.getDisplayCount()); synchronizeMailbox(account, folder, listener); } @@ -797,8 +795,7 @@ public class MessagingController implements Runnable { try { - LocalStore localStore = - (LocalStore) Store.getInstance(account.getLocalStoreUri(), mApplication); + LocalStore localStore = account.getLocalStore(); localStore.resetVisibleLimits(account.getDisplayCount()); } catch (MessagingException e) @@ -885,8 +882,8 @@ public class MessagingController implements Runnable if (K9.DEBUG) Log.v(K9.LOG_TAG, "SYNC: About to get local folder " + folder); - final LocalStore localStore = (LocalStore) Store.getInstance(account.getLocalStoreUri(), mApplication); - tLocalFolder = (LocalFolder) localStore.getFolder(folder); + final LocalStore localStore = account.getLocalStore(); + tLocalFolder = localStore.getFolder(folder); final LocalFolder localFolder = tLocalFolder; localFolder.open(OpenMode.READ_WRITE); Message[] localMessages = localFolder.getMessages(null); @@ -899,7 +896,7 @@ public class MessagingController implements Runnable if (K9.DEBUG) Log.v(K9.LOG_TAG, "SYNC: About to get remote store for " + folder); - Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication); + Store remoteStore = account.getRemoteStore(); if (K9.DEBUG) Log.v(K9.LOG_TAG, "SYNC: About to get remote folder " + folder); @@ -1667,9 +1664,7 @@ public class MessagingController implements Runnable { try { - LocalStore localStore = (LocalStore) Store.getInstance( - account.getLocalStoreUri(), - mApplication); + LocalStore localStore = account.getLocalStore(); localStore.addPendingCommand(command); } catch (Exception e) @@ -1707,9 +1702,7 @@ public class MessagingController implements Runnable private void processPendingCommandsSynchronous(Account account) throws MessagingException { - LocalStore localStore = (LocalStore) Store.getInstance( - account.getLocalStoreUri(), - mApplication); + LocalStore localStore = account.getLocalStore(); ArrayList commands = localStore.getPendingCommands(); int progress = 0; @@ -1850,10 +1843,8 @@ public class MessagingController implements Runnable return; } - LocalStore localStore = (LocalStore) Store.getInstance( - account.getLocalStoreUri(), - mApplication); - localFolder = (LocalFolder) localStore.getFolder(folder); + LocalStore localStore = account.getLocalStore(); + localFolder = localStore.getFolder(folder); LocalMessage localMessage = (LocalMessage) localFolder.getMessage(uid); if (localMessage == null) @@ -1861,7 +1852,7 @@ public class MessagingController implements Runnable return; } - Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication); + Store remoteStore = account.getRemoteStore(); remoteFolder = remoteStore.getFolder(folder); if (!remoteFolder.exists()) { @@ -2033,7 +2024,7 @@ public class MessagingController implements Runnable } String destFolder = command.arguments[1]; String isCopyS = command.arguments[2]; - Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication); + Store remoteStore = account.getRemoteStore(); remoteSrcFolder = remoteStore.getFolder(srcFolder); List messages = new ArrayList(); @@ -2156,7 +2147,7 @@ public class MessagingController implements Runnable Flag flag = Flag.valueOf(command.arguments[2]); - Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication); + Store remoteStore = account.getRemoteStore(); Folder remoteFolder = remoteStore.getFolder(folder); try { @@ -2215,7 +2206,7 @@ public class MessagingController implements Runnable Folder remoteFolder = null; try { - Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication); + Store remoteStore = account.getRemoteStore(); remoteFolder = remoteStore.getFolder(folder); if (!remoteFolder.exists()) { @@ -2274,7 +2265,7 @@ public class MessagingController implements Runnable if (K9.DEBUG) Log.d(K9.LOG_TAG, "processPendingExpunge: folder = " + folder); - Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication); + Store remoteStore = account.getRemoteStore(); Folder remoteFolder = remoteStore.getFolder(folder); try { @@ -2322,7 +2313,7 @@ public class MessagingController implements Runnable return; } - Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication); + Store remoteStore = account.getRemoteStore(); Folder remoteSrcFolder = remoteStore.getFolder(srcFolder); Folder remoteDestFolder = remoteStore.getFolder(destFolder); @@ -2385,7 +2376,7 @@ public class MessagingController implements Runnable LocalFolder localFolder = null; try { - Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); + Store localStore = account.getLocalStore(); localFolder = (LocalFolder) localStore.getFolder(folder); localFolder.open(OpenMode.READ_WRITE); Message[] messages = localFolder.getMessages(null, false); @@ -2412,7 +2403,7 @@ public class MessagingController implements Runnable return; } - Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication); + Store remoteStore = account.getRemoteStore(); remoteFolder = remoteStore.getFolder(folder); if (!remoteFolder.exists()) @@ -2467,7 +2458,7 @@ public class MessagingController implements Runnable String rootCauseMessage = getRootCauseMessage(t); Log.e(K9.LOG_TAG, "Error " + "'" + rootCauseMessage + "'", t); - Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); + Store localStore = account.getLocalStore(); LocalFolder localFolder = (LocalFolder)localStore.getFolder(account.getErrorFolderName()); Message[] messages = new Message[1]; MimeMessage message = new MimeMessage(); @@ -2523,7 +2514,7 @@ public class MessagingController implements Runnable return; } - Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); + Store localStore = account.getLocalStore(); LocalFolder localFolder = (LocalFolder)localStore.getFolder(account.getErrorFolderName()); Message[] messages = new Message[1]; MimeMessage message = new MimeMessage(); @@ -2572,18 +2563,26 @@ public class MessagingController implements Runnable } public void setFlag( - final Account account, - final String folderName, final Message[] messages, final Flag flag, final boolean newState) { - String[] uids = new String[messages.length]; - for (int i = 0; i < messages.length; i++) + actOnMessages(messages, new MessageActor() { - uids[i] = messages[i].getUid(); - } - setFlag(account, folderName, uids, flag, newState); + @Override + public void act(final Account account, final Folder folder, + final List messages) + { + String[] uids = new String[messages.size()]; + for (int i = 0; i < messages.size(); i++) + { + uids[i] = messages.get(i).getUid(); + } + setFlag(account, folder.getName(), uids, flag, newState); + } + + }); + } public void setFlag( @@ -2598,7 +2597,7 @@ public class MessagingController implements Runnable Folder localFolder = null; try { - Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); + Store localStore = account.getLocalStore(); localFolder = localStore.getFolder(folderName); localFolder.open(OpenMode.READ_WRITE); ArrayList messages = new ArrayList(); @@ -2655,7 +2654,7 @@ public class MessagingController implements Runnable try { Log.w(K9.LOG_TAG, "Clearing pending commands!"); - LocalStore localStore = (LocalStore)Store.getInstance(account.getLocalStoreUri(), mApplication); + LocalStore localStore = account.getLocalStore(); localStore.removePendingCommands(); } catch (MessagingException me) @@ -2676,8 +2675,8 @@ public class MessagingController implements Runnable LocalFolder localFolder = null; try { - Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); - localFolder = (LocalFolder) localStore.getFolder(folder); + LocalStore localStore = account.getLocalStore(); + localFolder = localStore.getFolder(folder); localFolder.open(OpenMode.READ_WRITE); Message message = localFolder.getMessage(uid); @@ -2700,7 +2699,7 @@ public class MessagingController implements Runnable * fully if possible. */ - Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication); + Store remoteStore = account.getRemoteStore(); remoteFolder = remoteStore.getFolder(folder); remoteFolder.open(OpenMode.READ_WRITE); @@ -2722,7 +2721,7 @@ public class MessagingController implements Runnable // This is a view message request, so mark it read if (!message.isSet(Flag.SEEN)) { - setFlag(account, localFolder.getName(), new Message[] { message }, Flag.SEEN, true); + setFlag(new Message[] { message }, Flag.SEEN, true); } if (listener != null && !getListeners().contains(listener)) @@ -2789,8 +2788,8 @@ public class MessagingController implements Runnable try { - Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); - LocalFolder localFolder = (LocalFolder) localStore.getFolder(folder); + LocalStore localStore = account.getLocalStore(); + LocalFolder localFolder = localStore.getFolder(folder); localFolder.open(OpenMode.READ_WRITE); LocalMessage message = (LocalMessage)localFolder.getMessage(uid); @@ -2829,7 +2828,7 @@ public class MessagingController implements Runnable localFolder.close(); if (!message.isSet(Flag.SEEN)) { - setFlag(account, localFolder.getName(), new Message[] { message }, Flag.SEEN, true); + setFlag(new Message[] { message }, Flag.SEEN, true); } for (MessagingListener l : getListeners()) @@ -2936,8 +2935,8 @@ public class MessagingController implements Runnable LocalFolder localFolder = null; try { - LocalStore localStore = - (LocalStore) Store.getInstance(account.getLocalStoreUri(), mApplication); + LocalStore localStore = account.getLocalStore(); + /* * We clear out any attachments already cached in the entire store and then * we update the passed in message to reflect that there are no cached @@ -2952,9 +2951,8 @@ public class MessagingController implements Runnable { attachment.setBody(null); } - Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication); - localFolder = - (LocalFolder) localStore.getFolder(message.getFolder().getName()); + Store remoteStore = account.getRemoteStore(); + localFolder = localStore.getFolder(message.getFolder().getName()); remoteFolder = remoteStore.getFolder(message.getFolder().getName()); remoteFolder.open(OpenMode.READ_WRITE); @@ -3015,9 +3013,8 @@ public class MessagingController implements Runnable { try { - Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); - LocalFolder localFolder = - (LocalFolder) localStore.getFolder(account.getOutboxFolderName()); + LocalStore localStore = account.getLocalStore(); + LocalFolder localFolder = localStore.getFolder(account.getOutboxFolderName()); localFolder.open(OpenMode.READ_WRITE); localFolder.appendMessages(new Message[] { @@ -3062,9 +3059,7 @@ public class MessagingController implements Runnable Folder localFolder = null; try { - Store localStore = Store.getInstance( - account.getLocalStoreUri(), - mApplication); + Store localStore = account.getLocalStore(); localFolder = localStore.getFolder( account.getOutboxFolderName()); if (!localFolder.exists()) @@ -3104,9 +3099,7 @@ public class MessagingController implements Runnable Folder localFolder = null; try { - Store localStore = Store.getInstance( - account.getLocalStoreUri(), - mApplication); + Store localStore = account.getLocalStore(); localFolder = localStore.getFolder( account.getOutboxFolderName()); if (!localFolder.exists()) @@ -3138,7 +3131,7 @@ public class MessagingController implements Runnable if (K9.DEBUG) Log.i(K9.LOG_TAG, "Scanning folder '" + account.getOutboxFolderName() + "' (" + ((LocalFolder)localFolder).getId() + ") for messages to send"); - Transport transport = Transport.getInstance(account.getTransportUri()); + Transport transport = Transport.getInstance(account); for (Message message : localMessages) { if (message.isSet(Flag.DELETED)) @@ -3333,7 +3326,7 @@ public class MessagingController implements Runnable int unreadMessageCount = 0; try { - unreadMessageCount = account.getUnreadMessageCount(context, mApplication); + unreadMessageCount = account.getUnreadMessageCount(context); } catch (MessagingException me) { @@ -3359,7 +3352,7 @@ public class MessagingController implements Runnable int unreadMessageCount = 0; try { - Folder localFolder = (Folder) Store.getInstance(account.getLocalStoreUri(), mApplication).getFolder(folderName); + Folder localFolder = account.getLocalStore().getFolder(folderName); unreadMessageCount = localFolder.getUnreadMessageCount(); } catch (MessagingException me) @@ -3375,41 +3368,7 @@ public class MessagingController implements Runnable } - public int moveMessages(final Account account, final String srcFolder, final Message[] messages, final String destFolder, - final MessagingListener listener) - { - int messagesMoved = 0; - for (Message message : messages) - { - if (moveMessage(account, srcFolder, message, destFolder, listener)) - { - messagesMoved++; - } - } - return messagesMoved; - } - - public boolean moveMessage(final Account account, final String srcFolder, final Message message, final String destFolder, - final MessagingListener listener) - { - if (!message.getUid().startsWith(K9.LOCAL_UID_PREFIX)) - { - suppressMessage(account, srcFolder, message); - putBackground("moveMessage", null, new Runnable() - { - public void run() - { - moveOrCopyMessageSynchronous(account, srcFolder, message, destFolder, false, listener); - } - }); - return true; - } - else - { - return false; - } - } - + public boolean isMoveCapable(Message message) { if (!message.getUid().startsWith(K9.LOCAL_UID_PREFIX)) @@ -3430,8 +3389,8 @@ public class MessagingController implements Runnable { try { - Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); - Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication); + Store localStore = account.getLocalStore(); + Store remoteStore = account.getRemoteStore(); return localStore.isMoveCapable() && remoteStore.isMoveCapable(); } catch (MessagingException me) @@ -3445,8 +3404,8 @@ public class MessagingController implements Runnable { try { - Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); - Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication); + Store localStore = account.getLocalStore(); + Store remoteStore = account.getRemoteStore(); return localStore.isCopyCapable() && remoteStore.isCopyCapable(); } catch (MessagingException me) @@ -3455,47 +3414,52 @@ public class MessagingController implements Runnable return false; } } - - public int copyMessages(final Account account, final String srcFolder, final Message[] messages, final String destFolder, - final MessagingListener listener) + public void moveMessages(final Account account, final String srcFolder, final Message[] messages, final String destFolder, + final MessagingListener listener) { - int messagesCopied = 0; for (Message message : messages) { - if (copyMessage(account, srcFolder, message, destFolder, listener)) + suppressMessage(account, srcFolder, message); + } + putBackground("moveMessages", null, new Runnable() + { + public void run() { - messagesCopied++; + moveOrCopyMessageSynchronous(account, srcFolder, messages, destFolder, false, listener); } - } - return messagesCopied; - } - public boolean copyMessage(final Account account, final String srcFolder, final Message message, final String destFolder, - final MessagingListener listener) - { - if (!message.getUid().startsWith(K9.LOCAL_UID_PREFIX)) - { - putBackground("copyMessage", null, new Runnable() - { - public void run() - { - moveOrCopyMessageSynchronous(account, srcFolder, message, destFolder, true, listener); - } - }); - return true; - } - else - { - return false; - } + }); } - private void moveOrCopyMessageSynchronous(final Account account, final String srcFolder, final Message message, + public void moveMessage(final Account account, final String srcFolder, final Message message, final String destFolder, + final MessagingListener listener) + { + moveMessages(account, srcFolder, new Message[] { message }, destFolder, listener); + } + + public void copyMessages(final Account account, final String srcFolder, final Message[] messages, final String destFolder, + final MessagingListener listener) + { + putBackground("copyMessages", null, new Runnable() + { + public void run() + { + moveOrCopyMessageSynchronous(account, srcFolder, messages, destFolder, true, listener); + } + }); + } + public void copyMessage(final Account account, final String srcFolder, final Message message, final String destFolder, + final MessagingListener listener) + { + copyMessages(account, srcFolder, new Message[] { message }, destFolder, listener); + } + + private void moveOrCopyMessageSynchronous(final Account account, final String srcFolder, final Message[] inMessages, final String destFolder, final boolean isCopy, MessagingListener listener) { try { - Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); - Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication); + Store localStore = account.getLocalStore(); + Store remoteStore = account.getRemoteStore(); if (isCopy == false && (remoteStore.isMoveCapable() == false || localStore.isMoveCapable() == false)) { return; @@ -3507,33 +3471,54 @@ public class MessagingController implements Runnable Folder localSrcFolder = localStore.getFolder(srcFolder); Folder localDestFolder = localStore.getFolder(destFolder); - Message lMessage = localSrcFolder.getMessage(message.getUid()); - String origUid = message.getUid(); - if (lMessage != null) + + List uids = new LinkedList(); + for (Message message : inMessages) { + String uid = message.getUid(); + if (!uid.startsWith(K9.LOCAL_UID_PREFIX)) + { + uids.add(uid); + } + } + + Message[] messages = localSrcFolder.getMessages(uids.toArray(new String[0]), null); + if (messages.length > 0) + { + Map origUidMap = new HashMap(); + + for (Message message : messages) + { + origUidMap.put(message.getUid(), message); + } + if (K9.DEBUG) Log.i(K9.LOG_TAG, "moveOrCopyMessageSynchronous: source folder = " + srcFolder - + ", uid = " + origUid + ", destination folder = " + destFolder + ", isCopy = " + isCopy); + + ", " + messages.length + " messages, " + ", destination folder = " + destFolder + ", isCopy = " + isCopy); if (isCopy) { FetchProfile fp = new FetchProfile(); fp.add(FetchProfile.Item.ENVELOPE); fp.add(FetchProfile.Item.BODY); - localSrcFolder.fetch(new Message[] { message }, fp, null); - localSrcFolder.copyMessages(new Message[] { message }, localDestFolder); + localSrcFolder.fetch(messages, fp, null); + localSrcFolder.copyMessages(messages, localDestFolder); } else { - localSrcFolder.moveMessages(new Message[] { message }, localDestFolder); - for (MessagingListener l : getListeners()) + localSrcFolder.moveMessages(messages, localDestFolder); + for (String origUid : origUidMap.keySet()) { - l.messageUidChanged(account, srcFolder, origUid, message.getUid()); + for (MessagingListener l : getListeners()) + { + l.messageUidChanged(account, srcFolder, origUid, origUidMap.get(origUid).getUid()); + } + unsuppressMessage(account, srcFolder, origUid); } - unsuppressMessage(account, srcFolder, origUid); } + + queueMoveOrCopy(account, srcFolder, destFolder, isCopy, origUidMap.keySet().toArray(new String[0])); } - queueMoveOrCopy(account, srcFolder, destFolder, isCopy, new String[] { origUid }); processPendingCommands(account); } @@ -3555,22 +3540,56 @@ public class MessagingController implements Runnable } }); } - - public void deleteMessages(final Account account, final String folder, final Message[] messages, - final MessagingListener listener) + + public void deleteDraft(final Account account, String uid) { - for (Message message : messages) + LocalFolder localFolder = null; + try { - suppressMessage(account, folder, message); + LocalStore localStore = account.getLocalStore(); + localFolder = localStore.getFolder(account.getDraftsFolderName()); + localFolder.open(OpenMode.READ_WRITE); + Message message = localFolder.getMessage(uid); + deleteMessages(new Message[] { message }, null); } - - putBackground("deleteMessages", null, new Runnable() + catch (MessagingException me) { - public void run() + addErrorMessage(account, me); + } + finally + { + if (localFolder != null) { - deleteMessagesSynchronous(account, folder, messages, listener); + localFolder.close(); } + } + } + + public void deleteMessages(final Message[] messages, final MessagingListener listener) + { + actOnMessages(messages, new MessageActor() + { + + @Override + public void act(final Account account, final Folder folder, + final List messages) + { + for (Message message : messages) + { + suppressMessage(account, folder.getName(), message); + } + + putBackground("deleteMessages", null, new Runnable() + { + public void run() + { + deleteMessagesSynchronous(account, folder.getName(), messages.toArray(new Message[0]), listener); + } + }); + } + }); + } private void deleteMessagesSynchronous(final Account account, final String folder, final Message[] messages, @@ -3585,7 +3604,6 @@ public class MessagingController implements Runnable //as messages get a new UID after being moved for (Message message : messages) { - unsuppressMessage(account, folder, message); if (listener != null) { listener.messageDeleted(account, folder, message); @@ -3595,7 +3613,7 @@ public class MessagingController implements Runnable l.messageDeleted(account, folder, message); } } - Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); + Store localStore = account.getLocalStore(); localFolder = localStore.getFolder(folder); if (folder.equals(account.getTrashFolderName()) || K9.FOLDER_NONE.equals(account.getTrashFolderName())) { @@ -3671,6 +3689,10 @@ public class MessagingController implements Runnable if (K9.DEBUG) Log.d(K9.LOG_TAG, "Delete policy " + account.getDeletePolicy() + " prevents delete from server"); } + for (String uid : uids) + { + unsuppressMessage(account, folder, uid); + } } catch (MessagingException me) { @@ -3680,6 +3702,7 @@ public class MessagingController implements Runnable } finally { + if (localFolder != null) { localFolder.close(); @@ -3703,7 +3726,7 @@ public class MessagingController implements Runnable private void processPendingEmptyTrash(PendingCommand command, Account account) throws MessagingException { - Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication); + Store remoteStore = account.getRemoteStore(); Folder remoteFolder = remoteStore.getFolder(account.getTrashFolderName()); try @@ -3736,7 +3759,7 @@ public class MessagingController implements Runnable Folder localFolder = null; try { - Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); + Store localStore = account.getLocalStore(); localFolder = localStore.getFolder(account.getTrashFolderName()); localFolder.open(OpenMode.READ_WRITE); localFolder.setFlags(new Flag[] { Flag.DELETED }, true); @@ -3932,7 +3955,7 @@ public class MessagingController implements Runnable Account.FolderMode aDisplayMode = account.getFolderDisplayMode(); Account.FolderMode aSyncMode = account.getFolderSyncMode(); - Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); + Store localStore = account.getLocalStore(); for (final Folder folder : localStore.getPersonalNamespaces()) { @@ -3985,9 +4008,8 @@ public class MessagingController implements Runnable { // In case multiple Commands get enqueued, don't run more than // once - final LocalStore localStore = - (LocalStore) Store.getInstance(account.getLocalStoreUri(), mApplication); - tLocalFolder = (LocalFolder) localStore.getFolder(folder.getName()); + final LocalStore localStore = account.getLocalStore(); + tLocalFolder = localStore.getFolder(folder.getName()); tLocalFolder.open(Folder.OpenMode.READ_WRITE); if (ignoreLastCheckedTime == false && tLocalFolder.getLastChecked() > @@ -4095,7 +4117,7 @@ public class MessagingController implements Runnable { try { - LocalStore localStore = (LocalStore)Store.getInstance(account.getLocalStoreUri(), mApplication); + LocalStore localStore = account.getLocalStore(); long oldSize = localStore.getSize(); localStore.compact(); long newSize = localStore.getSize(); @@ -4124,7 +4146,7 @@ public class MessagingController implements Runnable { try { - LocalStore localStore = (LocalStore)Store.getInstance(account.getLocalStoreUri(), mApplication); + LocalStore localStore = account.getLocalStore(); long oldSize = localStore.getSize(); localStore.clear(); localStore.resetVisibleLimits(account.getDisplayCount()); @@ -4206,7 +4228,7 @@ public class MessagingController implements Runnable int unreadMessageCount = 0; try { - unreadMessageCount = account.getUnreadMessageCount(context, mApplication); + unreadMessageCount = account.getUnreadMessageCount(context); } catch (MessagingException e) { @@ -4253,19 +4275,19 @@ public class MessagingController implements Runnable } - public void saveDraft(final Account account, final Message message) + public Message saveDraft(final Account account, final Message message) { + Message localMessage = null; try { - Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); - LocalFolder localFolder = - (LocalFolder) localStore.getFolder(account.getDraftsFolderName()); + LocalStore localStore = account.getLocalStore(); + LocalFolder localFolder = localStore.getFolder(account.getDraftsFolderName()); localFolder.open(OpenMode.READ_WRITE); localFolder.appendMessages(new Message[] { message }); - Message localMessage = localFolder.getMessage(message.getUid()); + localMessage = localFolder.getMessage(message.getUid()); localMessage.setFlag(Flag.X_DOWNLOADED_FULL, true); PendingCommand command = new PendingCommand(); @@ -4277,12 +4299,14 @@ public class MessagingController implements Runnable }; queuePendingCommand(account, command); processPendingCommands(account); + } catch (MessagingException e) { Log.e(K9.LOG_TAG, "Unable to save message as draft.", e); addErrorMessage(account, e); } + return localMessage; } public boolean modeMismatch(Account.FolderMode aMode, Folder.FolderClass fMode) @@ -4403,7 +4427,7 @@ public class MessagingController implements Runnable List names = new ArrayList(); - Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication); + Store localStore = account.getLocalStore(); for (final Folder folder : localStore.getPersonalNamespaces()) { if (folder.getName().equals(account.getErrorFolderName()) @@ -4462,7 +4486,7 @@ public class MessagingController implements Runnable try { - Store store = Store.getInstance(account.getStoreUri(), mApplication); + Store store = account.getRemoteStore(); if (store.isPushCapable() == false) { if (K9.DEBUG) @@ -4537,8 +4561,8 @@ public class MessagingController implements Runnable LocalFolder localFolder = null; try { - LocalStore localStore = (LocalStore) Store.getInstance(account.getLocalStoreUri(), mApplication); - localFolder= (LocalFolder) localStore.getFolder(remoteFolder.getName()); + LocalStore localStore = account.getLocalStore(); + localFolder= localStore.getFolder(remoteFolder.getName()); localFolder.open(OpenMode.READ_WRITE); int newCount = downloadMessages(account, remoteFolder, localFolder, messages, flagSyncOnly); @@ -4849,23 +4873,47 @@ public class MessagingController implements Runnable } - private Map> binMessages(Message[] messages) + private void actOnMessages(Message[] messages, MessageActor actor) { - Map> bins = new HashMap>(); + Map>> accountMap = new HashMap>>(); + for (Message message : messages) { - String folderName = message.getFolder().getName(); - List bin = bins.get(folderName); - if (bin == null) + Folder folder = message.getFolder(); + Account account = folder.getAccount(); + + Map> folderMap = accountMap.get(account); + if (folderMap == null) { - bin = new LinkedList(); - bins.put(folderName, bin); + folderMap = new HashMap>(); + accountMap.put(account, folderMap); + } + List messageList = folderMap.get(folder); + if (messageList == null) + { + messageList = new LinkedList(); + folderMap.put(folder, messageList); + } + + messageList.add(message); + } + for (Map.Entry>> entry : accountMap.entrySet()) + { + Account account = entry.getKey(); + + //account.refresh(Preferences.getPreferences(K9.app)); + Map> folderMap = entry.getValue(); + for (Map.Entry> folderEntry : folderMap.entrySet()) + { + Folder folder = folderEntry.getKey(); + List messageList = folderEntry.getValue(); + actor.act(account, folder, messageList); } - bin.add(message); } - return bins; } - - - + + interface MessageActor + { + public void act(final Account account, final Folder folder, final List messages); + } } diff --git a/src/com/fsck/k9/MessagingControllerPushReceiver.java b/src/com/fsck/k9/MessagingControllerPushReceiver.java index a4f2959f3..694dc68bb 100644 --- a/src/com/fsck/k9/MessagingControllerPushReceiver.java +++ b/src/com/fsck/k9/MessagingControllerPushReceiver.java @@ -103,8 +103,8 @@ public class MessagingControllerPushReceiver implements PushReceiver LocalFolder localFolder = null; try { - LocalStore localStore = (LocalStore) Store.getInstance(account.getLocalStoreUri(), mApplication); - localFolder= (LocalFolder) localStore.getFolder(folderName); + LocalStore localStore = account.getLocalStore(); + localFolder = localStore.getFolder(folderName); localFolder.open(OpenMode.READ_WRITE); return localFolder.getPushState(); } diff --git a/src/com/fsck/k9/Preferences.java b/src/com/fsck/k9/Preferences.java index e4fd7005b..178a9e343 100644 --- a/src/com/fsck/k9/Preferences.java +++ b/src/com/fsck/k9/Preferences.java @@ -1,9 +1,10 @@ package com.fsck.k9; +import java.util.ArrayList; +import java.util.List; import android.content.Context; import android.content.SharedPreferences; -import android.net.Uri; import android.util.Config; import android.util.Log; import com.fsck.k9.preferences.Editor; @@ -13,7 +14,24 @@ public class Preferences { private static Preferences preferences; + /** + * TODO need to think about what happens if this gets GCed along with the + * Activity that initialized it. Do we lose ability to read Preferences in + * further Activities? Maybe this should be stored in the Application + * context. + */ + public static synchronized Preferences getPreferences(Context context) + { + if (preferences == null) + { + preferences = new Preferences(context); + } + return preferences; + } + + private Storage mStorage; + private List accounts; private Preferences(Context context) { @@ -27,77 +45,83 @@ public class Preferences } } - - /** - * TODO need to think about what happens if this gets GCed along with the - * Activity that initialized it. Do we lose ability to read Preferences in - * further Activities? Maybe this should be stored in the Application - * context. - * - * @return - */ - public static synchronized Preferences getPreferences(Context context) + private synchronized void loadAccounts() { - if (preferences == null) + String accountUuids = getPreferences().getString("accountUuids", null); + if ((accountUuids != null) && (accountUuids.length() != 0)) { - preferences = new Preferences(context); + String[] uuids = accountUuids.split(","); + accounts = new ArrayList(uuids.length); + for (int i = 0, length = uuids.length; i < length; i++) + { + accounts.add(new Account(this, uuids[i])); + } + } + else + { + accounts = new ArrayList(); } - return preferences; } /** * Returns an array of the accounts on the system. If no accounts are * registered the method returns an empty array. - * - * @return */ - public Account[] getAccounts() + public synchronized Account[] getAccounts() { - String accountUuids = getPreferences().getString("accountUuids", null); - if (accountUuids == null || accountUuids.length() == 0) + if (accounts == null) { - return new Account[] {}; + loadAccounts(); } - String[] uuids = accountUuids.split(","); - Account[] accounts = new Account[uuids.length]; - for (int i = 0, length = uuids.length; i < length; i++) - { - accounts[i] = new Account(this, uuids[i]); - } - return accounts; + + return accounts.toArray(new Account[0]); } - public Account getAccountByContentUri(Uri uri) + public synchronized Account getAccount(String uuid) { - return new Account(this, uri.getPath().substring(1)); + if (accounts == null) + { + loadAccounts(); + } + + for (Account account : accounts) + { + if (account.getUuid().equals(uuid)) + { + return account; + } + } + + return null; + } + + public synchronized Account newAccount() + { + Account account = new Account(K9.app); + accounts.add(account); + + return account; + } + + public synchronized void deleteAccount(Account account) + { + accounts.remove(account); + account.delete(this); } /** * Returns the Account marked as default. If no account is marked as default * the first account in the list is marked as default and then returned. If * there are no accounts on the system the method returns null. - * - * @return */ public Account getDefaultAccount() { String defaultAccountUuid = getPreferences().getString("defaultAccountUuid", null); - Account defaultAccount = null; - Account[] accounts = getAccounts(); - if (defaultAccountUuid != null) - { - for (Account account : accounts) - { - if (account.getUuid().equals(defaultAccountUuid)) - { - defaultAccount = account; - break; - } - } - } + Account defaultAccount = getAccount(defaultAccountUuid); if (defaultAccount == null) { + Account[] accounts = getAccounts(); if (accounts.length > 0) { defaultAccount = accounts[0]; diff --git a/src/com/fsck/k9/activity/Accounts.java b/src/com/fsck/k9/activity/Accounts.java index 8f1ff6de6..9e08b2617 100644 --- a/src/com/fsck/k9/activity/Accounts.java +++ b/src/com/fsck/k9/activity/Accounts.java @@ -21,9 +21,6 @@ import com.fsck.k9.*; import com.fsck.k9.activity.setup.AccountSettings; import com.fsck.k9.activity.setup.AccountSetupBasics; import com.fsck.k9.activity.setup.Prefs; -import com.fsck.k9.mail.Store; -import com.fsck.k9.mail.store.LocalStore; - import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -297,7 +294,8 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC if (icicle != null && icicle.containsKey(SELECTED_CONTEXT_ACCOUNT)) { - mSelectedContextAccount = (Account) icicle.getSerializable("selectedContextAccount"); + String accountUuid = icicle.getString("selectedContextAccount"); + mSelectedContextAccount = Preferences.getPreferences(this).getAccount(accountUuid); } if (icicle != null) @@ -317,7 +315,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC super.onSaveInstanceState(outState); if (mSelectedContextAccount != null) { - outState.putSerializable(SELECTED_CONTEXT_ACCOUNT, mSelectedContextAccount); + outState.putString(SELECTED_CONTEXT_ACCOUNT, mSelectedContextAccount.getUuid()); } outState.putSerializable(UNREAD_MESSAGE_COUNTS, unreadMessageCounts); } @@ -473,13 +471,13 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC dismissDialog(DIALOG_REMOVE_ACCOUNT); try { - ((LocalStore)Store.getInstance(mSelectedContextAccount.getLocalStoreUri(), getApplication())).delete(); + mSelectedContextAccount.getLocalStore().delete(); } catch (Exception e) { // Ignore } - mSelectedContextAccount.delete(Preferences.getPreferences(Accounts.this)); + Preferences.getPreferences(Accounts.this).deleteAccount(mSelectedContextAccount); K9.setServicesEnabled(Accounts.this); refresh(); } @@ -730,5 +728,3 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC } } } - - diff --git a/src/com/fsck/k9/activity/ChooseFolder.java b/src/com/fsck/k9/activity/ChooseFolder.java index 512f3055f..03c103afc 100644 --- a/src/com/fsck/k9/activity/ChooseFolder.java +++ b/src/com/fsck/k9/activity/ChooseFolder.java @@ -14,7 +14,6 @@ import android.widget.TextView; import com.fsck.k9.*; import com.fsck.k9.mail.Folder; import com.fsck.k9.mail.MessagingException; - import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -50,7 +49,8 @@ public class ChooseFolder extends K9ListActivity getListView().setItemsCanFocus(false); getListView().setChoiceMode(ListView.CHOICE_MODE_NONE); Intent intent = getIntent(); - mAccount = (Account) intent.getSerializableExtra(EXTRA_ACCOUNT); + String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mUID = intent.getStringExtra(EXTRA_MESSAGE_UID); mFolder = intent.getStringExtra(EXTRA_CUR_FOLDER); if (intent.getStringExtra(EXTRA_SHOW_CURRENT) != null) diff --git a/src/com/fsck/k9/activity/ChooseIdentity.java b/src/com/fsck/k9/activity/ChooseIdentity.java index 28ad0a89a..a1bf35795 100644 --- a/src/com/fsck/k9/activity/ChooseIdentity.java +++ b/src/com/fsck/k9/activity/ChooseIdentity.java @@ -11,9 +11,10 @@ import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; import com.fsck.k9.Account; +import com.fsck.k9.Identity; import com.fsck.k9.K9ListActivity; +import com.fsck.k9.Preferences; import com.fsck.k9.R; - import java.util.List; public class ChooseIdentity extends K9ListActivity @@ -26,7 +27,7 @@ public class ChooseIdentity extends K9ListActivity public static final String EXTRA_ACCOUNT = "com.fsck.k9.ChooseIdentity_account"; public static final String EXTRA_IDENTITY = "com.fsck.k9.ChooseIdentity_identity"; - protected List identities = null; + protected List identities = null; @Override public void onCreate(Bundle savedInstanceState) @@ -39,7 +40,8 @@ public class ChooseIdentity extends K9ListActivity getListView().setItemsCanFocus(false); getListView().setChoiceMode(ListView.CHOICE_MODE_NONE); Intent intent = getIntent(); - mAccount = (Account) intent.getSerializableExtra(EXTRA_ACCOUNT); + String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1); @@ -61,7 +63,7 @@ public class ChooseIdentity extends K9ListActivity adapter.clear(); identities = mAccount.getIdentities(); - for (Account.Identity identity : identities) + for (Identity identity : identities) { String email = identity.getEmail(); String description = identity.getDescription(); @@ -80,7 +82,7 @@ public class ChooseIdentity extends K9ListActivity { public void onItemClick(AdapterView adapterview, View view, int i, long l) { - Account.Identity identity = mAccount.getIdentity(i); + Identity identity = mAccount.getIdentity(i); String email = identity.getEmail(); if (email != null && email.trim().equals("") == false) { diff --git a/src/com/fsck/k9/activity/EditIdentity.java b/src/com/fsck/k9/activity/EditIdentity.java index 6e6545615..491657f8e 100644 --- a/src/com/fsck/k9/activity/EditIdentity.java +++ b/src/com/fsck/k9/activity/EditIdentity.java @@ -7,12 +7,11 @@ import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.EditText; import android.widget.LinearLayout; - import com.fsck.k9.Account; +import com.fsck.k9.Identity; import com.fsck.k9.K9Activity; import com.fsck.k9.Preferences; import com.fsck.k9.R; - import java.util.List; public class EditIdentity extends K9Activity @@ -23,7 +22,7 @@ public class EditIdentity extends K9Activity public static final String EXTRA_ACCOUNT = "com.fsck.k9.EditIdentity_account"; private Account mAccount; - private Account.Identity mIdentity; + private Identity mIdentity; private int mIdentityIndex; private EditText mDescriptionView; private CheckBox mSignatureUse; @@ -38,13 +37,14 @@ public class EditIdentity extends K9Activity { super.onCreate(savedInstanceState); - mIdentity = (Account.Identity)getIntent().getSerializableExtra(EXTRA_IDENTITY); + mIdentity = (Identity)getIntent().getSerializableExtra(EXTRA_IDENTITY); mIdentityIndex = getIntent().getIntExtra(EXTRA_IDENTITY_INDEX, -1); - mAccount = (Account) getIntent().getSerializableExtra(EXTRA_ACCOUNT); + String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); if (mIdentityIndex == -1) { - mIdentity = mAccount.new Identity(); + mIdentity = new Identity(); } setContentView(R.layout.edit_identity); @@ -55,7 +55,7 @@ public class EditIdentity extends K9Activity */ if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_IDENTITY)) { - mIdentity = (Account.Identity)savedInstanceState.getSerializable(EXTRA_IDENTITY); + mIdentity = (Identity)savedInstanceState.getSerializable(EXTRA_IDENTITY); } mDescriptionView = (EditText)findViewById(R.id.description); @@ -115,7 +115,7 @@ public class EditIdentity extends K9Activity mIdentity.setSignatureUse(mSignatureUse.isChecked()); mIdentity.setSignature(mSignatureView.getText().toString()); - List identities = mAccount.getIdentities(); + List identities = mAccount.getIdentities(); if (mIdentityIndex == -1) { identities.add(mIdentity); diff --git a/src/com/fsck/k9/activity/FolderList.java b/src/com/fsck/k9/activity/FolderList.java index 91ac86c6d..9e2fdad10 100644 --- a/src/com/fsck/k9/activity/FolderList.java +++ b/src/com/fsck/k9/activity/FolderList.java @@ -25,9 +25,7 @@ import com.fsck.k9.activity.setup.FolderSettings; import com.fsck.k9.mail.Folder; import com.fsck.k9.mail.Message; import com.fsck.k9.mail.MessagingException; -import com.fsck.k9.mail.Store; import com.fsck.k9.service.MailService; - import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -46,7 +44,7 @@ public class FolderList extends K9ListActivity private static final String EXTRA_INITIAL_FOLDER = "initialFolder"; - private static final String STATE_CURRENT_FOLDER = "com.fsck.k9.activity.folderlist_folder"; + //private static final String STATE_CURRENT_FOLDER = "com.fsck.k9.activity.folderlist_folder"; private static final String EXTRA_CLEAR_NOTIFICATION = "clearNotification"; @@ -205,7 +203,7 @@ public class FolderList extends K9ListActivity private static void actionHandleAccount(Context context, Account account, String initialFolder) { Intent intent = new Intent(context, FolderList.class); - intent.putExtra(EXTRA_ACCOUNT, account); + intent.putExtra(EXTRA_ACCOUNT, account.getUuid()); if (initialFolder != null) { @@ -228,7 +226,7 @@ public class FolderList extends K9ListActivity context, FolderList.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.putExtra(EXTRA_ACCOUNT, account); + intent.putExtra(EXTRA_ACCOUNT, account.getUuid()); intent.putExtra(EXTRA_CLEAR_NOTIFICATION, true); if (initialFolder != null) @@ -278,7 +276,8 @@ public class FolderList extends K9ListActivity String initialFolder; mUnreadMessageCount = 0; - mAccount = (Account)intent.getSerializableExtra(EXTRA_ACCOUNT); + String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); initialFolder = intent.getStringExtra(EXTRA_INITIAL_FOLDER); if ( @@ -338,7 +337,7 @@ public class FolderList extends K9ListActivity initializeActivityView(); MessagingController.getInstance(getApplication()).addListener(mAdapter.mListener); - mAccount.refresh(Preferences.getPreferences(this)); + //mAccount.refresh(Preferences.getPreferences(this)); MessagingController.getInstance(getApplication()).getAccountUnreadCount(this, mAccount, mAdapter.mListener); onRefresh(!REFRESH_REMOTE); @@ -922,7 +921,7 @@ public class FolderList extends K9ListActivity { if (account != null && folderName != null) { - localFolder = (Folder) Store.getInstance(account.getLocalStoreUri(), getApplication()).getFolder(folderName); + localFolder = account.getLocalStore().getFolder(folderName); int unreadMessageCount = localFolder.getUnreadMessageCount(); if (localFolder != null) { diff --git a/src/com/fsck/k9/activity/ManageIdentities.java b/src/com/fsck/k9/activity/ManageIdentities.java index ad45c3411..b12ce4791 100644 --- a/src/com/fsck/k9/activity/ManageIdentities.java +++ b/src/com/fsck/k9/activity/ManageIdentities.java @@ -7,7 +7,7 @@ import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.ListView; import android.widget.Toast; -import com.fsck.k9.Account; +import com.fsck.k9.Identity; import com.fsck.k9.Preferences; import com.fsck.k9.R; @@ -34,8 +34,7 @@ public class ManageIdentities extends ChooseIdentity private void editItem(int i) { Intent intent = new Intent(ManageIdentities.this, EditIdentity.class); - - intent.putExtra(EditIdentity.EXTRA_ACCOUNT, mAccount); + intent.putExtra(EditIdentity.EXTRA_ACCOUNT, mAccount.getUuid()); intent.putExtra(EditIdentity.EXTRA_IDENTITY, mAccount.getIdentity(i)); intent.putExtra(EditIdentity.EXTRA_IDENTITY_INDEX, i); startActivityForResult(intent, ACTIVITY_EDIT_IDENTITY); @@ -56,8 +55,7 @@ public class ManageIdentities extends ChooseIdentity { case R.id.new_identity: Intent intent = new Intent(ManageIdentities.this, EditIdentity.class); - - intent.putExtra(EditIdentity.EXTRA_ACCOUNT, mAccount); + intent.putExtra(EditIdentity.EXTRA_ACCOUNT, mAccount.getUuid()); startActivityForResult(intent, ACTIVITY_EDIT_IDENTITY); break; default: @@ -85,7 +83,7 @@ public class ManageIdentities extends ChooseIdentity case R.id.up: if (menuInfo.position > 0) { - Account.Identity identity = identities.remove(menuInfo.position); + Identity identity = identities.remove(menuInfo.position); identities.add(menuInfo.position - 1, identity); mIdentitiesChanged = true; refreshView(); @@ -95,14 +93,14 @@ public class ManageIdentities extends ChooseIdentity case R.id.down: if (menuInfo.position < identities.size() - 1) { - Account.Identity identity = identities.remove(menuInfo.position); + Identity identity = identities.remove(menuInfo.position); identities.add(menuInfo.position + 1, identity); mIdentitiesChanged = true; refreshView(); } break; case R.id.top: - Account.Identity identity = identities.remove(menuInfo.position); + Identity identity = identities.remove(menuInfo.position); identities.add(0, identity); mIdentitiesChanged = true; refreshView(); @@ -129,7 +127,7 @@ public class ManageIdentities extends ChooseIdentity public void onResume() { super.onResume(); - mAccount.refresh(Preferences.getPreferences(getApplication().getApplicationContext())); + //mAccount.refresh(Preferences.getPreferences(getApplication().getApplicationContext())); refreshView(); } diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java index 7309b8530..1b1130890 100644 --- a/src/com/fsck/k9/activity/MessageCompose.java +++ b/src/com/fsck/k9/activity/MessageCompose.java @@ -28,7 +28,6 @@ import com.fsck.k9.mail.Message.RecipientType; import com.fsck.k9.mail.internet.*; import com.fsck.k9.mail.store.LocalStore; import com.fsck.k9.mail.store.LocalStore.LocalAttachmentBody; - import java.io.File; import java.io.Serializable; import java.io.UnsupportedEncodingException; @@ -78,7 +77,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc private static final int ACTIVITY_CHOOSE_IDENTITY = 2; private Account mAccount; - private Account.Identity mIdentity; + private Identity mIdentity; private boolean mIdentityChanged = false; private boolean mSignatureChanged = false; private String mFolder; @@ -178,7 +177,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc public static void actionCompose(Context context, Account account) { Intent i = new Intent(context, MessageCompose.class); - i.putExtra(EXTRA_ACCOUNT, account); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); context.startActivity(i); } @@ -197,7 +196,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc boolean replyAll) { Intent i = new Intent(context, MessageCompose.class); - i.putExtra(EXTRA_ACCOUNT, account); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); i.putExtra(EXTRA_FOLDER, message.getFolder().getName()); i.putExtra(EXTRA_MESSAGE, message.getUid()); if (replyAll) @@ -220,7 +219,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc public static void actionForward(Context context, Account account, Message message) { Intent i = new Intent(context, MessageCompose.class); - i.putExtra(EXTRA_ACCOUNT, account); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); i.putExtra(EXTRA_FOLDER, message.getFolder().getName()); i.putExtra(EXTRA_MESSAGE, message.getUid()); i.setAction(ACTION_FORWARD); @@ -240,7 +239,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc public static void actionEditDraft(Context context, Account account, Message message) { Intent i = new Intent(context, MessageCompose.class); - i.putExtra(EXTRA_ACCOUNT, account); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); i.putExtra(EXTRA_FOLDER, message.getFolder().getName()); i.putExtra(EXTRA_MESSAGE, message.getUid()); i.setAction(ACTION_EDIT_DRAFT); @@ -257,7 +256,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc setContentView(R.layout.message_compose); Intent intent = getIntent(); - mAccount = (Account) intent.getSerializableExtra(EXTRA_ACCOUNT); + String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); if (mAccount == null) { @@ -632,7 +632,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc mQuotedTextBar.setVisibility(savedInstanceState.getBoolean(STATE_KEY_QUOTED_TEXT_SHOWN) ? View.VISIBLE : View.GONE); mQuotedText.setVisibility(savedInstanceState.getBoolean(STATE_KEY_QUOTED_TEXT_SHOWN) ? View.VISIBLE : View.GONE); mDraftUid = savedInstanceState.getString(STATE_KEY_DRAFT_UID); - mIdentity = (Account.Identity)savedInstanceState.getSerializable(STATE_IDENTITY); + mIdentity = (Identity)savedInstanceState.getSerializable(STATE_IDENTITY); mIdentityChanged = savedInstanceState.getBoolean(STATE_IDENTITY_CHANGED); updateFrom(); updateSignature(); @@ -820,7 +820,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc if (mIdentityChanged || mSignatureChanged) { String signature = mSignatureView.getText().toString(); - k9identity += ":" + Utility.base64Encode(signature) ; + k9identity += ":" + Utility.base64Encode(signature); if (mIdentityChanged) { @@ -835,8 +835,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc Log.d(K9.LOG_TAG, "Saving identity: " + k9identity); message.addHeader(K9.K9MAIL_IDENTITY, k9identity); - MessagingController.getInstance(getApplication()).saveDraft(mAccount, message); - mDraftUid = message.getUid(); + Message draftMessage = MessagingController.getInstance(getApplication()).saveDraft(mAccount, message); + mDraftUid = draftMessage.getUid(); // Don't display the toast if the user is just changing the orientation if ((getChangingConfigurations() & ActivityInfo.CONFIG_ORIENTATION) == 0) @@ -846,28 +846,12 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc } else { - /* - * Send the message - * TODO Is it possible for us to be editing a draft with a null source message? Don't - * think so. Could probably remove below check. - */ - if (ACTION_EDIT_DRAFT.equals(getIntent().getAction()) && mSourceMessageUid != null) - { - /* - * We're sending a previously saved draft, so delete the old draft first. - */ - MessagingController.getInstance(getApplication()).deleteMessages(mAccount, mFolder, new Message[] { mSourceMessage }, null); - } + MessagingController.getInstance(getApplication()).sendMessage(mAccount, message, null); if (mDraftUid != null) { - /* - * Message was auto-saved (screen rotation) so delete that draft before sending - */ - Message draftMessage = new MimeMessage(); - draftMessage.setUid(mDraftUid); - MessagingController.getInstance(getApplication()).deleteMessages(mAccount, mAccount.getDraftsFolderName(), new Message[] { draftMessage }, null); + MessagingController.getInstance(getApplication()).deleteDraft(mAccount, mDraftUid); + mDraftUid = null; } - MessagingController.getInstance(getApplication()).sendMessage(mAccount, message, null); } } @@ -896,17 +880,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc private void onDiscard() { - if (mSourceMessageUid != null) - { - if (ACTION_EDIT_DRAFT.equals(getIntent().getAction()) && mSourceMessageUid != null) - { - MessagingController.getInstance(getApplication()).deleteMessages(mAccount, mFolder, new Message[] { mSourceMessage }, null); - } - } if (mDraftUid != null) { - Message draftMessage = new MimeMessage(); - MessagingController.getInstance(getApplication()).deleteMessages(mAccount, mAccount.getDraftsFolderName(), new Message[] { draftMessage }, null); + MessagingController.getInstance(getApplication()).deleteDraft(mAccount, mDraftUid); + mDraftUid = null; } mHandler.sendEmptyMessage(MSG_DISCARDED_DRAFT); mDraftNeedsSaving = false; @@ -1045,10 +1022,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc private void onIdentityChosen(Intent intent) { Bundle bundle = intent.getExtras();; - switchToIdentity((Account.Identity)bundle.getSerializable(ChooseIdentity.EXTRA_IDENTITY)); + switchToIdentity((Identity)bundle.getSerializable(ChooseIdentity.EXTRA_IDENTITY)); } - private void switchToIdentity(Account.Identity identity) + private void switchToIdentity(Identity identity) { mIdentity = identity; mIdentityChanged = true; @@ -1133,7 +1110,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc if (mAccount.getIdentities().size() > 1) { Intent intent = new Intent(this, ChooseIdentity.class); - intent.putExtra(ChooseIdentity.EXTRA_ACCOUNT, mAccount); + intent.putExtra(ChooseIdentity.EXTRA_ACCOUNT, mAccount.getUuid()); startActivityForResult(intent, ACTIVITY_CHOOSE_IDENTITY); } else @@ -1273,10 +1250,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc if (ACTION_REPLY_ALL.equals(action) || ACTION_REPLY.equals(action)) { - Account.Identity useIdentity = null; + Identity useIdentity = null; for (Address address : message.getRecipients(RecipientType.TO)) { - Account.Identity identity = mAccount.findIdentity(address); + Identity identity = mAccount.findIdentity(address); if (identity != null) { useIdentity = identity; @@ -1289,7 +1266,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc { for (Address address : message.getRecipients(RecipientType.CC)) { - Account.Identity identity = mAccount.findIdentity(address); + Identity identity = mAccount.findIdentity(address); if (identity != null) { useIdentity = identity; @@ -1300,7 +1277,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc } if (useIdentity != null) { - Account.Identity defaultIdentity = mAccount.getIdentity(0); + Identity defaultIdentity = mAccount.getIdentity(0); if (useIdentity != defaultIdentity) { switchToIdentity(useIdentity); @@ -1312,7 +1289,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc { for (Address address : message.getRecipients(RecipientType.TO)) { - Account.Identity identity = mAccount.findIdentity(address); + Identity identity = mAccount.findIdentity(address); if (!mAccount.isAnIdentity(address)) { addAddress(mToView, address); @@ -1398,6 +1375,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc { try { + mDraftUid = message.getUid(); mSubjectView.setText(message.getSubject()); addAddresses(mToView, message.getRecipients(RecipientType.TO)); if (message.getRecipients(RecipientType.CC).length > 0) @@ -1431,6 +1409,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc String name = null; String email = null; String signature = null; + boolean signatureUse = message.getFolder().getAccount().getSignatureUse(); if (tokens.hasMoreTokens()) { bodyLengthS = Utility.base64Decode(tokens.nextToken()); @@ -1445,6 +1424,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc } if (tokens.hasMoreTokens()) { + signatureUse = true; signature = Utility.base64Decode(tokens.nextToken()); } if (tokens.hasMoreTokens()) @@ -1456,7 +1436,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc email = Utility.base64Decode(tokens.nextToken()); } - Account.Identity newIdentity= mAccount.new Identity(); + Identity newIdentity = new Identity(); + newIdentity.setSignatureUse(signatureUse); if (signature != null) { newIdentity.setSignature(signature); @@ -1584,12 +1565,16 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc @Override public void messageUidChanged(Account account, String folder, String oldUid, String newUid) { - if (account.equals(mAccount) && (folder.equals(mFolder) || (mFolder == null && folder.equals(mAccount.getDraftsFolderName())))) + if (account.equals(mAccount) && folder.equals(mAccount.getDraftsFolderName())) { if (oldUid.equals(mDraftUid)) { mDraftUid = newUid; } + } + + if (account.equals(mAccount) && (folder.equals(mFolder))) + { if (oldUid.equals(mSourceMessageUid)) { mSourceMessageUid = newUid; diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index bc014136c..678ea70fc 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -22,7 +22,6 @@ import android.view.*; import android.view.ContextMenu.ContextMenuInfo; import android.view.View.OnClickListener; import android.view.GestureDetector.SimpleOnGestureListener; - import android.widget.*; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.CompoundButton.OnCheckedChangeListener; @@ -35,7 +34,6 @@ import com.fsck.k9.mail.Message.RecipientType; import com.fsck.k9.mail.store.LocalStore; import com.fsck.k9.mail.store.LocalStore.LocalFolder; import com.fsck.k9.mail.store.LocalStore.LocalMessage; - import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -61,19 +59,14 @@ public class MessageList private static final int ACTIVITY_CHOOSE_FOLDER_MOVE = 1; private static final int ACTIVITY_CHOOSE_FOLDER_COPY = 2; + + private static final int ACTIVITY_CHOOSE_FOLDER_MOVE_BATCH = 3; + private static final int ACTIVITY_CHOOSE_FOLDER_COPY_BATCH = 4; private static final String EXTRA_ACCOUNT = "account"; private static final String EXTRA_FOLDER = "folder"; private static final String EXTRA_QUERY = "query"; - - private static final String STATE_KEY_LIST = "com.fsck.k9.activity.messagelist_state"; - private static final String STATE_CURRENT_FOLDER = "com.fsck.k9.activity.messagelist_folder"; - private static final String STATE_QUERY = "com.fsck.k9.activity.query"; - private static final String STATE_CURRENT_ITEM = "com.fsck.k9.activity.messagelist_selection"; - private static final String STATE_KEY_SELECTED_COUNT = "com.fsck.k9.activity.messagelist_selected_count"; - - private ListView mListView; private boolean mTouchView = true; @@ -291,7 +284,7 @@ public class MessageList public static Intent actionHandleFolderIntent(Context context, Account account, String folder) { Intent intent = new Intent(context, MessageList.class); - intent.putExtra(EXTRA_ACCOUNT, account); + intent.putExtra(EXTRA_ACCOUNT, account.getUuid()); if (folder != null) { @@ -338,7 +331,8 @@ public class MessageList public void onNewIntent(Intent intent) { setIntent(intent); // onNewIntent doesn't autoset our "internal" intent - mAccount = (Account)intent.getSerializableExtra(EXTRA_ACCOUNT); + String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mFolderName = intent.getStringExtra(EXTRA_FOLDER); mQueryString = intent.getStringExtra(EXTRA_QUERY); @@ -749,7 +743,7 @@ public class MessageList private void onDelete(MessageInfoHolder holder, int position) { mAdapter.removeMessage(holder); - mController.deleteMessages(holder.account, holder.message.getFolder().getName(), new Message[] { holder.message }, null); + mController.deleteMessages(new Message[] { holder.message }, null); } @@ -768,8 +762,7 @@ public class MessageList } Intent intent = new Intent(this, ChooseFolder.class); - - intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, holder.account); + intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, holder.account.getUuid()); intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, holder.folder.name); intent.putExtra(ChooseFolder.EXTRA_MESSAGE_UID, holder.message.getUid()); startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_MOVE); @@ -790,8 +783,7 @@ public class MessageList } Intent intent = new Intent(this, ChooseFolder.class); - - intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, holder.account); + intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, holder.account.getUuid()); intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, holder.folder.name); intent.putExtra(ChooseFolder.EXTRA_MESSAGE_UID, holder.message.getUid()); startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_COPY); @@ -807,6 +799,7 @@ public class MessageList { case ACTIVITY_CHOOSE_FOLDER_MOVE: case ACTIVITY_CHOOSE_FOLDER_COPY: + { if (data == null) return; @@ -814,7 +807,6 @@ public class MessageList String uid = data.getStringExtra(ChooseFolder.EXTRA_MESSAGE_UID); - MessageInfoHolder m = mAdapter.getMessage(uid); if (destFolderName != null && m != null) { @@ -822,15 +814,27 @@ public class MessageList { case ACTIVITY_CHOOSE_FOLDER_MOVE: onMoveChosen(m, destFolderName); - break; case ACTIVITY_CHOOSE_FOLDER_COPY: onCopyChosen(m, destFolderName); - break; } } + break; + } + case ACTIVITY_CHOOSE_FOLDER_MOVE_BATCH: + { + String destFolderName = data.getStringExtra(ChooseFolder.EXTRA_NEW_FOLDER); + onMoveChosenBatch(destFolderName); + break; + } + case ACTIVITY_CHOOSE_FOLDER_COPY_BATCH: + { + String destFolderName = data.getStringExtra(ChooseFolder.EXTRA_NEW_FOLDER); + onCopyChosenBatch(destFolderName); + break; + } } } @@ -987,16 +991,7 @@ public class MessageList int itemId = item.getItemId(); switch (itemId) { - case R.id.check_mail: - if (mFolderName != null) - { - checkMail(mAccount, mFolderName); - } - return true; - case R.id.send_messages: - sendMail(mAccount); - return true; - + case R.id.compose: onCompose(); @@ -1037,38 +1032,6 @@ public class MessageList return true; - case R.id.list_folders: - onShowFolderList(); - - return true; - } - - if (mQueryString != null) - { - return false; // none of the options after this point are "safe" for search results - } - - switch (itemId) - { - case R.id.mark_all_as_read: - if (mFolderName != null) - { - onMarkAllAsRead(mAccount, mFolderName); - } - return true; - - case R.id.folder_settings: - if (mFolderName != null) - { - FolderSettings.actionSettings(this, mAccount, mFolderName); - } - return true; - - case R.id.account_settings: - onEditAccount(); - - return true; - case R.id.batch_select_all: setAllSelected(true); toggleBatchButtons(); @@ -1078,15 +1041,7 @@ public class MessageList setAllSelected(false); toggleBatchButtons(); return true; - - case R.id.batch_copy_op: - moveOrCopySelected(false); - return true; - - case R.id.batch_move_op: - moveOrCopySelected(true); - return true; - + case R.id.batch_delete_op: deleteSelected(); return true; @@ -1107,6 +1062,58 @@ public class MessageList flagSelected(Flag.FLAGGED, false); return true; + } + + if (mQueryString != null) + { + return false; // none of the options after this point are "safe" for search results + } + + switch (itemId) + { + case R.id.check_mail: + if (mFolderName != null) + { + checkMail(mAccount, mFolderName); + } + return true; + case R.id.send_messages: + sendMail(mAccount); + return true; + + case R.id.list_folders: + onShowFolderList(); + + return true; + + case R.id.mark_all_as_read: + if (mFolderName != null) + { + onMarkAllAsRead(mAccount, mFolderName); + } + return true; + + case R.id.folder_settings: + if (mFolderName != null) + { + FolderSettings.actionSettings(this, mAccount, mFolderName); + } + return true; + + case R.id.account_settings: + onEditAccount(); + + return true; + + case R.id.batch_copy_op: + onCopyBatch(); + return true; + + case R.id.batch_move_op: + onMoveBatch(); + return true; + + case R.id.expunge: if (mCurrentFolder != null) { @@ -1138,19 +1145,37 @@ public class MessageList @Override public boolean onPrepareOptionsMenu(Menu menu) { - + boolean anySelected = anySelected(); + setOpsState(menu, true, anySelected); + if (mQueryString != null) { - menu.findItem(R.id.batch_ops).setVisible(false); menu.findItem(R.id.mark_all_as_read).setVisible(false); menu.findItem(R.id.folder_settings).setVisible(false); menu.findItem(R.id.account_settings).setVisible(false); menu.findItem(R.id.list_folders).setVisible(false); menu.findItem(R.id.expunge).setVisible(false); + menu.findItem(R.id.batch_move_op).setVisible(false); + menu.findItem(R.id.batch_copy_op).setVisible(false); + menu.findItem(R.id.check_mail).setVisible(false); + menu.findItem(R.id.send_messages).setVisible(false); } + else + { + if (mCurrentFolder != null && mCurrentFolder.outbox) + { + menu.findItem(R.id.check_mail).setVisible(false); + } + else + { + menu.findItem(R.id.send_messages).setVisible(false); + } - boolean anySelected = anySelected(); - setOpsState(menu, true, anySelected); + if (mCurrentFolder != null && K9.ERROR_FOLDER_NAME.equals(mCurrentFolder.name)) + { + menu.findItem(R.id.expunge).setVisible(false); + } + } boolean newFlagState = computeBatchDirection(true); boolean newReadState = computeBatchDirection(false); @@ -1160,24 +1185,7 @@ public class MessageList menu.findItem(R.id.batch_mark_unread_op).setVisible(!newReadState); menu.findItem(R.id.batch_deselect_all).setVisible(anySelected); menu.findItem(R.id.batch_select_all).setEnabled(true); - // TODO: batch move and copy not yet implemented - menu.findItem(R.id.batch_move_op).setVisible(false); - menu.findItem(R.id.batch_copy_op).setVisible(false); - - if (mCurrentFolder != null && mCurrentFolder.outbox) - { - menu.findItem(R.id.check_mail).setVisible(false); - } - else - { - menu.findItem(R.id.send_messages).setVisible(false); - } - - if (mCurrentFolder != null && K9.ERROR_FOLDER_NAME.equals(mCurrentFolder.name)) - { - menu.findItem(R.id.expunge).setVisible(false); - } return true; } @@ -1585,6 +1593,15 @@ public class MessageList super.pendingCommandCompleted(account, commandTitle); mHandler.refreshTitle(); } + public void messageUidChanged(Account account, String folder, String oldUid, String newUid) + { + if (updateForMe(account, folder)) + { + MessageInfoHolder holder = getMessage(oldUid); + holder.uid = newUid; + holder.message.setUid(newUid); + } + } }; @@ -1699,7 +1716,7 @@ public class MessageList LocalFolder local_folder = null; try { - LocalStore localStore = (LocalStore)Store.getInstance(account.getLocalStoreUri(), getApplication()); + LocalStore localStore = account.getLocalStore(); local_folder = localStore.getFolder(folder); return new FolderInfoHolder((Folder)local_folder, account); } @@ -2467,14 +2484,13 @@ public class MessageList { if (v == mBatchDeleteButton) { - mController.deleteMessages(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), null); + mController.deleteMessages(messageList.toArray(new Message[0]), null); mSelectedCount = 0; toggleBatchButtons(); } else { - mController.setFlag(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), - (v == mBatchReadButton ? Flag.SEEN : Flag.FLAGGED), newState); + mController.setFlag(messageList.toArray(new Message[0]), (v == mBatchReadButton ? Flag.SEEN : Flag.FLAGGED), newState); } } else @@ -2529,8 +2545,7 @@ public class MessageList } } } - mController.setFlag(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), - flag , newState); + mController.setFlag(messageList.toArray(new Message[0]), flag, newState); mHandler.sortMessages(); } @@ -2548,14 +2563,112 @@ public class MessageList } mAdapter.removeMessages(removeHolderList); - mController.deleteMessages(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), null); + mController.deleteMessages(messageList.toArray(new Message[0]), null); mSelectedCount = 0; toggleBatchButtons(); } - - private void moveOrCopySelected(boolean isMove) + + private void onMoveBatch() { - + if (mController.isMoveCapable(mAccount) == false) + { + return; + } + for (MessageInfoHolder holder : mAdapter.messages) + { + if (holder.selected) + { + Message message = holder.message; + if (mController.isMoveCapable(message) == false) + { + Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG); + toast.show(); + return; + } + } + } + Intent intent = new Intent(this, ChooseFolder.class); + intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid()); + intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mCurrentFolder.folder.getName()); + startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_MOVE_BATCH); } + private void onMoveChosenBatch(String folderName) + { + if (mController.isMoveCapable(mAccount) == false) + { + return; + } + List messageList = new ArrayList(); + List removeHolderList = new ArrayList(); + for (MessageInfoHolder holder : mAdapter.messages) + { + if (holder.selected) + { + Message message = holder.message; + if (mController.isMoveCapable(message) == false) + { + Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG); + toast.show(); + return; + } + messageList.add(holder.message); + removeHolderList.add(holder); + } + } + mAdapter.removeMessages(removeHolderList); + + mController.moveMessages(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), folderName, null); + mSelectedCount = 0; + toggleBatchButtons(); + } + private void onCopyBatch() + { + if (mController.isCopyCapable(mAccount) == false) + { + return; + } + for (MessageInfoHolder holder : mAdapter.messages) + { + if (holder.selected) + { + Message message = holder.message; + if (mController.isCopyCapable(message) == false) + { + Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG); + toast.show(); + return; + } + } + } + Intent intent = new Intent(this, ChooseFolder.class); + intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid()); + intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mCurrentFolder.folder.getName()); + startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_COPY_BATCH); + } + private void onCopyChosenBatch(String folderName) + { + if (mController.isCopyCapable(mAccount) == false) + { + return; + } + List messageList = new ArrayList(); + + for (MessageInfoHolder holder : mAdapter.messages) + { + if (holder.selected) + { + Message message = holder.message; + if (mController.isCopyCapable(message) == false) + { + Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG); + toast.show(); + return; + } + messageList.add(holder.message); + } + } + + mController.copyMessages(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), folderName, null); + } } diff --git a/src/com/fsck/k9/activity/MessageView.java b/src/com/fsck/k9/activity/MessageView.java index 55c297816..54a407f9c 100644 --- a/src/com/fsck/k9/activity/MessageView.java +++ b/src/com/fsck/k9/activity/MessageView.java @@ -35,7 +35,6 @@ import com.fsck.k9.mail.store.LocalStore.LocalMessage; import com.fsck.k9.mail.store.LocalStore.LocalTextBody; import com.fsck.k9.provider.AttachmentProvider; import org.apache.commons.io.IOUtils; - import java.io.*; import java.net.HttpURLConnection; import java.util.ArrayList; @@ -427,7 +426,7 @@ public class MessageView extends K9Activity public static void actionView(Context context, Account account, String folder, String messageUid, ArrayList folderUids, Bundle extras) { Intent i = new Intent(context, MessageView.class); - i.putExtra(EXTRA_ACCOUNT, account); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); i.putExtra(EXTRA_FOLDER, folder); i.putExtra(EXTRA_MESSAGE, messageUid); i.putExtra(EXTRA_MESSAGE_UIDS, folderUids); @@ -515,7 +514,8 @@ public class MessageView extends K9Activity if (icicle!=null) { - mAccount = (Account) icicle.getSerializable(EXTRA_ACCOUNT); + String accountUuid = icicle.getString(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mFolder = icicle.getString(EXTRA_FOLDER); mMessageUid = icicle.getString(EXTRA_MESSAGE); mMessageUids = icicle.getStringArrayList(EXTRA_MESSAGE_UIDS); @@ -524,7 +524,8 @@ public class MessageView extends K9Activity { if (uri==null) { - mAccount = (Account) intent.getSerializableExtra(EXTRA_ACCOUNT); + String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mFolder = intent.getStringExtra(EXTRA_FOLDER); mMessageUid = intent.getStringExtra(EXTRA_MESSAGE); mMessageUids = intent.getStringArrayListExtra(EXTRA_MESSAGE_UIDS); @@ -613,7 +614,7 @@ public class MessageView extends K9Activity @Override protected void onSaveInstanceState(Bundle outState) { - outState.putSerializable(EXTRA_ACCOUNT, mAccount); + outState.putString(EXTRA_ACCOUNT, mAccount.getUuid()); outState.putString(EXTRA_FOLDER, mFolder); outState.putString(EXTRA_MESSAGE, mMessageUid); outState.putStringArrayList(EXTRA_MESSAGE_UIDS, mMessageUids); @@ -702,8 +703,6 @@ public class MessageView extends K9Activity if (mMessage != null) { Message messageToDelete = mMessage; - String folderForDelete = mFolder; - Account accountForDelete = mAccount; findSurroundingMessagesUid(); @@ -711,8 +710,6 @@ public class MessageView extends K9Activity mMessageUids.remove(messageToDelete.getUid()); MessagingController.getInstance(getApplication()).deleteMessages( - accountForDelete, - folderForDelete, new Message[] { messageToDelete }, null); @@ -836,7 +833,7 @@ public class MessageView extends K9Activity return; } Intent intent = new Intent(this, ChooseFolder.class); - intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount); + intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid()); intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mFolder); intent.putExtra(ChooseFolder.EXTRA_MESSAGE_UID, mMessageUid); startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_MOVE); @@ -855,8 +852,7 @@ public class MessageView extends K9Activity return; } Intent intent = new Intent(this, ChooseFolder.class); - - intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount); + intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid()); intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mFolder); intent.putExtra(ChooseFolder.EXTRA_MESSAGE_UID, mMessageUid); startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_COPY); diff --git a/src/com/fsck/k9/activity/setup/AccountSettings.java b/src/com/fsck/k9/activity/setup/AccountSettings.java index a89dbdccb..cfc79e762 100644 --- a/src/com/fsck/k9/activity/setup/AccountSettings.java +++ b/src/com/fsck/k9/activity/setup/AccountSettings.java @@ -75,7 +75,7 @@ public class AccountSettings extends K9PreferenceActivity public static void actionSettings(Context context, Account account) { Intent i = new Intent(context, AccountSettings.class); - i.putExtra(EXTRA_ACCOUNT, account); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); context.startActivity(i); } @@ -84,15 +84,15 @@ public class AccountSettings extends K9PreferenceActivity { super.onCreate(savedInstanceState); - mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT); - mAccount.refresh(Preferences.getPreferences(this)); + String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); boolean isPushCapable = false; boolean isExpungeCapable = false; Store store = null; try { - store = Store.getInstance(mAccount.getStoreUri(), getApplication()); + store = mAccount.getRemoteStore(); isPushCapable = store.isPushCapable(); isExpungeCapable = store.isExpungeCapable(); } @@ -360,7 +360,7 @@ public class AccountSettings extends K9PreferenceActivity public void onResume() { super.onResume(); - mAccount.refresh(Preferences.getPreferences(this)); + //mAccount.refresh(Preferences.getPreferences(this)); } private void saveSettings() @@ -457,7 +457,7 @@ public class AccountSettings extends K9PreferenceActivity private void onManageIdentities() { Intent intent = new Intent(this, ManageIdentities.class); - intent.putExtra(ChooseIdentity.EXTRA_ACCOUNT, mAccount); + intent.putExtra(ChooseIdentity.EXTRA_ACCOUNT, mAccount.getUuid()); startActivityForResult(intent, ACTIVITY_MANAGE_IDENTITIES); } @@ -474,7 +474,7 @@ public class AccountSettings extends K9PreferenceActivity public void onChooseAutoExpandFolder() { Intent selectIntent = new Intent(this, ChooseFolder.class); - selectIntent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount); + selectIntent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid()); selectIntent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mAutoExpandFolder.getSummary()); selectIntent.putExtra(ChooseFolder.EXTRA_SHOW_CURRENT, "yes"); diff --git a/src/com/fsck/k9/activity/setup/AccountSetupAccountType.java b/src/com/fsck/k9/activity/setup/AccountSetupAccountType.java index 4a3ad66fe..987f91091 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupAccountType.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupAccountType.java @@ -12,8 +12,8 @@ import android.widget.Toast; import com.fsck.k9.Account; import com.fsck.k9.K9; import com.fsck.k9.K9Activity; +import com.fsck.k9.Preferences; import com.fsck.k9.R; - import java.net.URI; /** @@ -34,7 +34,7 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen public static void actionSelectAccountType(Context context, Account account, boolean makeDefault) { Intent i = new Intent(context, AccountSetupAccountType.class); - i.putExtra(EXTRA_ACCOUNT, account); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault); context.startActivity(i); } @@ -48,7 +48,8 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen ((Button)findViewById(R.id.imap)).setOnClickListener(this); ((Button)findViewById(R.id.webdav)).setOnClickListener(this); - mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT); + String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mMakeDefault = (boolean)getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false); } diff --git a/src/com/fsck/k9/activity/setup/AccountSetupBasics.java b/src/com/fsck/k9/activity/setup/AccountSetupBasics.java index aebbacfe3..b022b80d1 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupBasics.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupBasics.java @@ -21,15 +21,12 @@ import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import com.fsck.k9.*; - import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; import java.net.URLEncoder; -import org.apache.http.client.utils.URLEncodedUtils; - /** * Prompts the user for the email address and password. Also prompts for * "Use this account as default" if this is the 2nd+ account being set up. @@ -88,7 +85,8 @@ public class AccountSetupBasics extends K9Activity if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT)) { - mAccount = (Account)savedInstanceState.getSerializable(EXTRA_ACCOUNT); + String accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); } if (savedInstanceState != null && savedInstanceState.containsKey(STATE_KEY_PROVIDER)) @@ -108,7 +106,7 @@ public class AccountSetupBasics extends K9Activity public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putSerializable(EXTRA_ACCOUNT, mAccount); + outState.putString(EXTRA_ACCOUNT, mAccount.getUuid()); if (mProvider != null) { outState.putSerializable(STATE_KEY_PROVIDER, mProvider); @@ -274,7 +272,7 @@ public class AccountSetupBasics extends K9Activity return; } - mAccount = new Account(this); + mAccount = Preferences.getPreferences(this).newAccount(); mAccount.setName(getOwnerName()); mAccount.setEmail(email); mAccount.setStoreUri(incomingUri.toString()); @@ -337,7 +335,7 @@ public class AccountSetupBasics extends K9Activity String user = emailParts[0]; String domain = emailParts[1]; - mAccount = new Account(this); + mAccount = Preferences.getPreferences(this).newAccount(); mAccount.setName(getOwnerName()); mAccount.setEmail(email); try diff --git a/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java b/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java index fef2eca9c..c270435d1 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java @@ -20,7 +20,6 @@ import com.fsck.k9.mail.CertificateValidationException; import com.fsck.k9.mail.Store; import com.fsck.k9.mail.Transport; import com.fsck.k9.mail.store.TrustManagerFactory; - import java.security.cert.CertificateException; import java.security.cert.X509Certificate; @@ -62,7 +61,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList boolean checkIncoming, boolean checkOutgoing) { Intent i = new Intent(context, AccountSetupCheckSettings.class); - i.putExtra(EXTRA_ACCOUNT, account); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); i.putExtra(EXTRA_CHECK_INCOMING, checkIncoming); i.putExtra(EXTRA_CHECK_OUTGOING, checkOutgoing); context.startActivityForResult(i, ACTIVITY_REQUEST_CODE); @@ -80,7 +79,8 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList setMessage(R.string.account_setup_check_settings_retr_info_msg); mProgressBar.setIndeterminate(true); - mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT); + String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mCheckIncoming = (boolean)getIntent().getBooleanExtra(EXTRA_CHECK_INCOMING, false); mCheckOutgoing = (boolean)getIntent().getBooleanExtra(EXTRA_CHECK_OUTGOING, false); @@ -104,7 +104,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList if (mCheckIncoming) { setMessage(R.string.account_setup_check_settings_check_incoming_msg); - store = Store.getInstance(mAccount.getStoreUri(), getApplication()); + store = mAccount.getRemoteStore(); store.checkSettings(); MessagingController.getInstance(getApplication()).listFolders(mAccount, true, null); @@ -123,7 +123,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList if (mCheckOutgoing) { setMessage(R.string.account_setup_check_settings_check_outgoing_msg); - Transport transport = Transport.getInstance(mAccount.getTransportUri()); + Transport transport = Transport.getInstance(mAccount); transport.close(); transport.open(); transport.close(); diff --git a/src/com/fsck/k9/activity/setup/AccountSetupComposition.java b/src/com/fsck/k9/activity/setup/AccountSetupComposition.java index 4c17c02af..9fbe27da8 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupComposition.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupComposition.java @@ -5,7 +5,6 @@ import android.content.Intent; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; -import android.widget.Button; import android.widget.CompoundButton; import android.widget.CheckBox; import android.widget.EditText; @@ -36,7 +35,7 @@ public class AccountSetupComposition extends K9Activity { Intent i = new Intent(context, AccountSetupComposition.class); i.setAction(Intent.ACTION_EDIT); - i.putExtra(EXTRA_ACCOUNT, account); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); context.startActivity(i); } @@ -46,7 +45,8 @@ public class AccountSetupComposition extends K9Activity { super.onCreate(savedInstanceState); - mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT); + String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); setContentView(R.layout.account_setup_composition); @@ -56,7 +56,8 @@ public class AccountSetupComposition extends K9Activity */ if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT)) { - mAccount = (Account)savedInstanceState.getSerializable(EXTRA_ACCOUNT); + accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); } mAccountName = (EditText)findViewById(R.id.account_name); @@ -114,7 +115,7 @@ public class AccountSetupComposition extends K9Activity public void onResume() { super.onResume(); - mAccount.refresh(Preferences.getPreferences(this)); + //mAccount.refresh(Preferences.getPreferences(this)); } private void saveSettings() @@ -147,7 +148,7 @@ public class AccountSetupComposition extends K9Activity public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putSerializable(EXTRA_ACCOUNT, mAccount); + outState.putSerializable(EXTRA_ACCOUNT, mAccount.getUuid()); } @Override diff --git a/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java b/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java index 46ca64f9f..7ff0bd0f5 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java @@ -13,7 +13,6 @@ import android.view.View.OnClickListener; import android.widget.*; import com.fsck.k9.*; import com.fsck.k9.activity.ChooseFolder; - import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; @@ -28,7 +27,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener private static final int SELECT_DRAFT_FOLDER = 100; private static final int SELECT_SENT_FOLDER = 101; private static final int SELECT_TRASH_FOLDER = 102; - private static final int SELECT_OUTBOX_FOLDER = 103; + //private static final int SELECT_OUTBOX_FOLDER = 103; private static final int popPorts[] = { @@ -84,7 +83,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener public static void actionIncomingSettings(Activity context, Account account, boolean makeDefault) { Intent i = new Intent(context, AccountSetupIncoming.class); - i.putExtra(EXTRA_ACCOUNT, account); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault); context.startActivity(i); } @@ -93,7 +92,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener { Intent i = new Intent(context, AccountSetupIncoming.class); i.setAction(Intent.ACTION_EDIT); - i.putExtra(EXTRA_ACCOUNT, account); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); context.startActivity(i); } @@ -199,7 +198,8 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener */ mPortView.setKeyListener(DigitsKeyListener.getInstance("0123456789")); - mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT); + String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mMakeDefault = (boolean)getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false); /* @@ -208,7 +208,8 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener */ if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT)) { - mAccount = (Account)savedInstanceState.getSerializable(EXTRA_ACCOUNT); + accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); } try @@ -385,7 +386,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putSerializable(EXTRA_ACCOUNT, mAccount); + outState.putString(EXTRA_ACCOUNT, mAccount.getUuid()); } private void validateFields() @@ -580,7 +581,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener { selectIntent.putExtra(ChooseFolder.EXTRA_SHOW_FOLDER_NONE, "yes"); } - selectIntent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount); + selectIntent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid()); selectIntent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, curFolder); selectIntent.putExtra(ChooseFolder.EXTRA_SHOW_CURRENT, "yes"); startActivityForResult(selectIntent, activityCode); diff --git a/src/com/fsck/k9/activity/setup/AccountSetupNames.java b/src/com/fsck/k9/activity/setup/AccountSetupNames.java index d9b513a6f..af68d9edf 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupNames.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupNames.java @@ -13,7 +13,6 @@ import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import com.fsck.k9.*; -import com.fsck.k9.activity.FolderList; public class AccountSetupNames extends K9Activity implements OnClickListener { @@ -30,7 +29,7 @@ public class AccountSetupNames extends K9Activity implements OnClickListener public static void actionSetNames(Context context, Account account) { Intent i = new Intent(context, AccountSetupNames.class); - i.putExtra(EXTRA_ACCOUNT, account); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); context.startActivity(i); } @@ -63,7 +62,8 @@ public class AccountSetupNames extends K9Activity implements OnClickListener mName.setKeyListener(TextKeyListener.getInstance(false, Capitalize.WORDS)); - mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT); + String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); /* * Since this field is considered optional, we don't set this here. If diff --git a/src/com/fsck/k9/activity/setup/AccountSetupOptions.java b/src/com/fsck/k9/activity/setup/AccountSetupOptions.java index 0f3961bed..7fa4c014a 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupOptions.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupOptions.java @@ -33,7 +33,7 @@ public class AccountSetupOptions extends K9Activity implements OnClickListener public static void actionOptions(Context context, Account account, boolean makeDefault) { Intent i = new Intent(context, AccountSetupOptions.class); - i.putExtra(EXTRA_ACCOUNT, account); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault); context.startActivity(i); } @@ -103,7 +103,8 @@ public class AccountSetupOptions extends K9Activity implements OnClickListener displayCountsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mDisplayCountView.setAdapter(displayCountsAdapter); - mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT); + String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mNotifyView.setChecked(mAccount.isNotifyNewMail()); mNotifySyncView.setChecked(mAccount.isShowOngoing()); @@ -116,7 +117,7 @@ public class AccountSetupOptions extends K9Activity implements OnClickListener boolean isPushCapable = false; try { - Store store = Store.getInstance(mAccount.getStoreUri(), getApplication()); + Store store = mAccount.getRemoteStore(); isPushCapable = store.isPushCapable(); } catch (Exception e) diff --git a/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java b/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java index 621406fcf..41dd071b0 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java @@ -14,7 +14,6 @@ import android.view.ViewGroup; import android.widget.*; import android.widget.CompoundButton.OnCheckedChangeListener; import com.fsck.k9.*; - import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; @@ -37,6 +36,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, { "smtp", "smtp+ssl", "smtp+ssl+", "smtp+tls", "smtp+tls+" }; + /* private static final int webdavPorts[] = { 80, 443, 443, 443, 443 @@ -45,6 +45,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, { "webdav", "webdav+ssl", "webdav+ssl+", "webdav+tls", "webdav+tls+" }; + */ private static final String authTypes[] = { @@ -65,7 +66,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, public static void actionOutgoingSettings(Context context, Account account, boolean makeDefault) { Intent i = new Intent(context, AccountSetupOutgoing.class); - i.putExtra(EXTRA_ACCOUNT, account); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault); context.startActivity(i); } @@ -74,7 +75,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, { Intent i = new Intent(context, AccountSetupOutgoing.class); i.setAction(Intent.ACTION_EDIT); - i.putExtra(EXTRA_ACCOUNT, account); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); context.startActivity(i); } @@ -84,7 +85,8 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, super.onCreate(savedInstanceState); setContentView(R.layout.account_setup_outgoing); - mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT); + String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); try { @@ -190,7 +192,9 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, */ mPortView.setKeyListener(DigitsKeyListener.getInstance("0123456789")); - mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT); + //FIXME: get Account object again? + accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); mMakeDefault = (boolean)getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false); /* @@ -199,7 +203,8 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, */ if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT)) { - mAccount = (Account)savedInstanceState.getSerializable(EXTRA_ACCOUNT); + accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); } try @@ -284,7 +289,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener, public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putSerializable(EXTRA_ACCOUNT, mAccount); + outState.putString(EXTRA_ACCOUNT, mAccount.getUuid()); } private void validateFields() diff --git a/src/com/fsck/k9/activity/setup/FolderSettings.java b/src/com/fsck/k9/activity/setup/FolderSettings.java index ffe655d87..ad112ea8c 100644 --- a/src/com/fsck/k9/activity/setup/FolderSettings.java +++ b/src/com/fsck/k9/activity/setup/FolderSettings.java @@ -12,6 +12,7 @@ import com.fsck.k9.*; import com.fsck.k9.mail.Folder.FolderClass; import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.Store; +import com.fsck.k9.mail.store.LocalStore; import com.fsck.k9.mail.store.LocalStore.LocalFolder; import com.fsck.k9.service.MailService; @@ -36,7 +37,7 @@ public class FolderSettings extends K9PreferenceActivity { Intent i = new Intent(context, FolderSettings.class); i.putExtra(EXTRA_FOLDER_NAME, folderName); - i.putExtra(EXTRA_ACCOUNT, account); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); context.startActivity(i); } @@ -46,13 +47,13 @@ public class FolderSettings extends K9PreferenceActivity super.onCreate(savedInstanceState); String folderName = (String)getIntent().getSerializableExtra(EXTRA_FOLDER_NAME); - Account mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT); + String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); + Account mAccount = Preferences.getPreferences(this).getAccount(accountUuid); try { - Store localStore = Store.getInstance(mAccount.getLocalStoreUri(), - getApplication()); - mFolder = (LocalFolder) localStore.getFolder(folderName); + LocalStore localStore = mAccount.getLocalStore(); + mFolder = localStore.getFolder(folderName); mFolder.refresh(Preferences.getPreferences(this)); } catch (MessagingException me) @@ -65,7 +66,7 @@ public class FolderSettings extends K9PreferenceActivity Store store = null; try { - store = Store.getInstance(mAccount.getStoreUri(), getApplication()); + store = mAccount.getRemoteStore(); isPushCapable = store.isPushCapable(); } catch (Exception e) diff --git a/src/com/fsck/k9/mail/Folder.java b/src/com/fsck/k9/mail/Folder.java index 9e6c84adc..33cb72922 100644 --- a/src/com/fsck/k9/mail/Folder.java +++ b/src/com/fsck/k9/mail/Folder.java @@ -1,10 +1,13 @@ package com.fsck.k9.mail; +import com.fsck.k9.Account; import com.fsck.k9.Preferences; public abstract class Folder { + protected final Account mAccount; + private String status = null; private long lastChecked = 0; private long lastPush = 0; @@ -23,6 +26,11 @@ public abstract class Folder HOLDS_FOLDERS, HOLDS_MESSAGES, } + protected Folder(Account account) + { + mAccount = account; + } + /** * Forces an open of the MailProvider. If the provider is already open this * function returns without doing anything. @@ -205,5 +213,8 @@ public abstract class Folder this.status = status; } - + public Account getAccount() + { + return mAccount; + } } diff --git a/src/com/fsck/k9/mail/Store.java b/src/com/fsck/k9/mail/Store.java index 5931b534e..daba084a9 100644 --- a/src/com/fsck/k9/mail/Store.java +++ b/src/com/fsck/k9/mail/Store.java @@ -2,6 +2,8 @@ package com.fsck.k9.mail; import android.app.Application; + +import com.fsck.k9.Account; import com.fsck.k9.mail.store.ImapStore; import com.fsck.k9.mail.store.LocalStore; import com.fsck.k9.mail.store.Pop3Store; @@ -31,45 +33,41 @@ public abstract class Store private static HashMap mStores = new HashMap(); - /** - * Get an instance of a mail store. The URI is parsed as a standard URI and - * the scheme is used to determine which protocol will be used. The - * following schemes are currently recognized: imap - IMAP with no - * connection security. Ex: imap://username:password@host/ imap+tls - IMAP - * with TLS connection security, if the server supports it. Ex: - * imap+tls://username:password@host imap+tls+ - IMAP with required TLS - * connection security. Connection fails if TLS is not available. Ex: - * imap+tls+://username:password@host imap+ssl+ - IMAP with required SSL - * connection security. Connection fails if SSL is not available. Ex: - * imap+ssl+://username:password@host - * - * @param uri The URI of the store. - * @return - * @throws MessagingException - */ - public synchronized static Store getInstance(String uri, Application application) throws MessagingException + protected final Account mAccount; + + protected Store(Account account) { + mAccount = account; + } + + /** + * Get an instance of a remote mail store. + */ + public synchronized static Store getRemoteInstance(Account account) throws MessagingException + { + String uri = account.getStoreUri(); + + if (uri.startsWith("local")) + { + throw new RuntimeException("Asked to get non-local Store object but given LocalStore URI"); + } + Store store = mStores.get(uri); if (store == null) { if (uri.startsWith("imap")) { - store = new ImapStore(uri); + store = new ImapStore(account); } else if (uri.startsWith("pop3")) { - store = new Pop3Store(uri); - } - else if (uri.startsWith("local")) - { - store = new LocalStore(uri, application); + store = new Pop3Store(account); } else if (uri.startsWith("webdav")) { - store = new WebDavStore(uri); + store = new WebDavStore(account); } - if (store != null) { mStores.put(uri, store); @@ -84,6 +82,37 @@ public abstract class Store return store; } + /** + * Get an instance of a local mail store. + */ + public synchronized static LocalStore getLocalInstance(Account account, Application application) throws MessagingException + { + String uri = account.getLocalStoreUri(); + + if (!uri.startsWith("local")) + { + throw new RuntimeException("LocalStore URI doesn't start with 'local'"); + } + + Store store = mStores.get(uri); + if (store == null) + { + store = new LocalStore(account, application); + + if (store != null) + { + mStores.put(uri, store); + } + } + + if (store == null) + { + throw new MessagingException("Unable to locate an applicable Store for " + uri); + } + + return (LocalStore)store; + } + public abstract Folder getFolder(String name) throws MessagingException; public abstract Folder[] getPersonalNamespaces() throws MessagingException; @@ -121,4 +150,8 @@ public abstract class Store return null; } + public Account getAccount() + { + return mAccount; + } } diff --git a/src/com/fsck/k9/mail/Transport.java b/src/com/fsck/k9/mail/Transport.java index 66d99fc27..efc43ca9e 100644 --- a/src/com/fsck/k9/mail/Transport.java +++ b/src/com/fsck/k9/mail/Transport.java @@ -1,6 +1,7 @@ package com.fsck.k9.mail; +import com.fsck.k9.Account; import com.fsck.k9.mail.transport.SmtpTransport; import com.fsck.k9.mail.transport.WebDavTransport; @@ -11,15 +12,16 @@ public abstract class Transport // RFC 1047 protected static final int SOCKET_READ_TIMEOUT = 300000; - public synchronized static Transport getInstance(String uri) throws MessagingException + public synchronized static Transport getInstance(Account account) throws MessagingException { + String uri = account.getTransportUri(); if (uri.startsWith("smtp")) { return new SmtpTransport(uri); } else if (uri.startsWith("webdav")) { - return new WebDavTransport(uri); + return new WebDavTransport(account); } else { diff --git a/src/com/fsck/k9/mail/store/ImapStore.java b/src/com/fsck/k9/mail/store/ImapStore.java index 8ae9305ad..219cd0fb3 100644 --- a/src/com/fsck/k9/mail/store/ImapStore.java +++ b/src/com/fsck/k9/mail/store/ImapStore.java @@ -2,6 +2,8 @@ package com.fsck.k9.mail.store; import android.util.Log; + +import com.fsck.k9.Account; import com.fsck.k9.K9; import com.fsck.k9.PeekableInputStream; import com.fsck.k9.Utility; @@ -98,15 +100,15 @@ public class ImapStore extends Store * imap+tls+://auth:user:password@server:port CONNECTION_SECURITY_TLS_REQUIRED * imap+ssl+://auth:user:password@server:port CONNECTION_SECURITY_SSL_REQUIRED * imap+ssl://auth:user:password@server:port CONNECTION_SECURITY_SSL_OPTIONAL - * - * @param _uri */ - public ImapStore(String _uri) throws MessagingException + public ImapStore(Account account) throws MessagingException { + super(account); + URI uri; try { - uri = new URI(_uri); + uri = new URI(mAccount.getStoreUri()); } catch (URISyntaxException use) { @@ -438,6 +440,7 @@ public class ImapStore extends Store public ImapFolder(ImapStore nStore, String name) { + super(nStore.getAccount()); store = nStore; this.mName = name; } diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index 9077e6d87..237027c32 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -10,6 +10,7 @@ import android.database.sqlite.SQLiteException; import android.net.Uri; import android.text.util.Regex; import android.util.Log; +import com.fsck.k9.Account; import com.fsck.k9.K9; import com.fsck.k9.Preferences; import com.fsck.k9.Utility; @@ -58,17 +59,17 @@ 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 "; - /** - * @param uri local://localhost/path/to/database/uuid.db + * local://localhost/path/to/database/uuid.db */ - public LocalStore(String _uri, Application application) throws MessagingException + public LocalStore(Account account, Application application) throws MessagingException { + super(account); mApplication = application; URI uri = null; try { - uri = new URI(_uri); + uri = new URI(mAccount.getLocalStoreUri()); } catch (Exception e) { @@ -84,6 +85,7 @@ public class LocalStore extends Store implements Serializable // We need to associate the localstore with the account. Since we don't have the account // handy here, we'll take the filename from the DB and use the basename of the filename // Folders probably should have references to their containing accounts + //TODO: We do have an account object now File dbFile = new File(mPath); String[] tokens = dbFile.getName().split("\\."); uUid = tokens[0]; @@ -108,7 +110,6 @@ public class LocalStore extends Store implements Serializable } - private void doDbUpgrade(SQLiteDatabase mDb, Application application) { Log.i(K9.LOG_TAG, String.format("Upgrading database from version %d to version %d", @@ -676,6 +677,7 @@ public class LocalStore extends Store implements Serializable public LocalFolder(String name) { + super(LocalStore.this.mAccount); this.mName = name; if (K9.INBOX.equals(getName())) @@ -689,6 +691,7 @@ public class LocalStore extends Store implements Serializable public LocalFolder(long id) { + super(LocalStore.this.mAccount); this.mFolderId = id; } @@ -1376,7 +1379,11 @@ public class LocalStore extends Store implements Serializable ArrayList messages = new ArrayList(); for (String uid : uids) { - messages.add(getMessage(uid)); + Message message = getMessage(uid); + if (message != null) + { + messages.add(message); + } } return messages.toArray(new Message[] {}); } @@ -1452,7 +1459,7 @@ public class LocalStore extends Store implements Serializable * old message. It is implemented as a delete/insert. This functionality is used in saving * of drafts and re-synchronization of updated server messages. */ - public void appendMessages(Message[] messages, boolean copy) throws MessagingException + private void appendMessages(Message[] messages, boolean copy) throws MessagingException { open(OpenMode.READ_WRITE); for (Message message : messages) @@ -1463,10 +1470,13 @@ public class LocalStore extends Store implements Serializable } String uid = message.getUid(); - if (uid == null) + if (uid == null || copy) { uid = K9.LOCAL_UID_PREFIX + UUID.randomUUID().toString(); - message.setUid(uid); + if (!copy) + { + message.setUid(uid); + } } else { @@ -1903,6 +1913,12 @@ public class LocalStore extends Store implements Serializable return super.equals(o); } + @Override + public int hashCode() + { + return mName.hashCode(); + } + @Override public Flag[] getPermanentFlags() throws MessagingException { diff --git a/src/com/fsck/k9/mail/store/Pop3Store.java b/src/com/fsck/k9/mail/store/Pop3Store.java index d3d95ba1c..da271ee1f 100644 --- a/src/com/fsck/k9/mail/store/Pop3Store.java +++ b/src/com/fsck/k9/mail/store/Pop3Store.java @@ -3,6 +3,8 @@ package com.fsck.k9.mail.store; import android.util.Config; import android.util.Log; + +import com.fsck.k9.Account; import com.fsck.k9.K9; import com.fsck.k9.Utility; import com.fsck.k9.mail.*; @@ -69,15 +71,15 @@ public class Pop3Store extends Store * pop3+tls+://user:password@server:port CONNECTION_SECURITY_TLS_REQUIRED * pop3+ssl+://user:password@server:port CONNECTION_SECURITY_SSL_REQUIRED * pop3+ssl://user:password@server:port CONNECTION_SECURITY_SSL_OPTIONAL - * - * @param _uri */ - public Pop3Store(String _uri) throws MessagingException + public Pop3Store(Account account) throws MessagingException { + super(account); + URI uri; try { - uri = new URI(_uri); + uri = new URI(mAccount.getStoreUri()); } catch (URISyntaxException use) { @@ -197,6 +199,7 @@ public class Pop3Store extends Store public Pop3Folder(String name) { + super(Pop3Store.this.mAccount); this.mName = name; if (mName.equalsIgnoreCase("INBOX")) { diff --git a/src/com/fsck/k9/mail/store/WebDavStore.java b/src/com/fsck/k9/mail/store/WebDavStore.java index 836caeb10..3c2e50178 100644 --- a/src/com/fsck/k9/mail/store/WebDavStore.java +++ b/src/com/fsck/k9/mail/store/WebDavStore.java @@ -1,6 +1,8 @@ package com.fsck.k9.mail.store; import android.util.Log; + +import com.fsck.k9.Account; import com.fsck.k9.K9; import com.fsck.k9.Utility; import com.fsck.k9.mail.*; @@ -99,14 +101,14 @@ public class WebDavStore extends Store * webdav+tls+://user:password@server:port CONNECTION_SECURITY_TLS_REQUIRED * webdav+ssl+://user:password@server:port CONNECTION_SECURITY_SSL_REQUIRED * webdav+ssl://user:password@server:port CONNECTION_SECURITY_SSL_OPTIONAL - * - * @param _uri */ - public WebDavStore(String _uri) throws MessagingException + public WebDavStore(Account account) throws MessagingException { + super(account); + try { - mUri = new URI(_uri); + mUri = new URI(mAccount.getStoreUri()); } catch (URISyntaxException use) { @@ -1160,6 +1162,7 @@ public class WebDavStore extends Store public WebDavFolder(WebDavStore nStore, String name) { + super(nStore.getAccount()); store = nStore; this.mName = name; diff --git a/src/com/fsck/k9/mail/transport/WebDavTransport.java b/src/com/fsck/k9/mail/transport/WebDavTransport.java index 35f8227e9..2a65d556e 100644 --- a/src/com/fsck/k9/mail/transport/WebDavTransport.java +++ b/src/com/fsck/k9/mail/transport/WebDavTransport.java @@ -2,6 +2,8 @@ package com.fsck.k9.mail.transport; import android.util.Log; + +import com.fsck.k9.Account; import com.fsck.k9.K9; import com.fsck.k9.PeekableInputStream; import com.fsck.k9.mail.Message; @@ -42,9 +44,9 @@ public class WebDavTransport extends Transport * * @param _uri */ - public WebDavTransport(String _uri) throws MessagingException + public WebDavTransport(Account account) throws MessagingException { - store = new WebDavStore(_uri); + store = new WebDavStore(account); if (K9.DEBUG) Log.d(K9.LOG_TAG, ">>> New WebDavTransport creation complete"); }