mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Fixes Issue 794
Implements new setting "Sync remote deletions" which is checked by default. When unchecked, K-9 Mail will no longer remove messages from local storage just because the message was removed from the server. This functionality works for all account types. Messages will still be removed from the local store in order to stay within the limit imposed by the "Number of messages to display" setting.
This commit is contained in:
parent
45339457f8
commit
318099082f
@ -545,6 +545,9 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
|
||||
<string name="account_settings_folder_target_mode_first_and_second_class">1st and 2nd Class folders</string>
|
||||
<string name="account_settings_folder_target_mode_not_second_class">All except 2nd Class folders</string>
|
||||
|
||||
<string name="account_settings_sync_remote_deletetions_label">Sync remote deletions</string>
|
||||
<string name="account_settings_sync_remote_deletetions_summary">Remove messages when deleted on server</string>
|
||||
|
||||
<string name="folder_settings_title">Folder settings</string>
|
||||
|
||||
<string name="folder_settings_in_top_group_label">Show in top group</string>
|
||||
|
@ -109,6 +109,12 @@
|
||||
android:entryValues="@array/account_setup_expunge_policy_values"
|
||||
android:dialogTitle="@string/account_setup_expunge_policy_label" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="account_sync_remote_deletetions"
|
||||
android:title="@string/account_settings_sync_remote_deletetions_label"
|
||||
android:defaultValue="true"
|
||||
android:summary="@string/account_settings_sync_remote_deletetions_summary" />
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="incoming"
|
||||
android:title="@string/account_settings_incoming_label"
|
||||
|
@ -101,6 +101,7 @@ public class Account implements BaseAccount
|
||||
// current set of fetched messages
|
||||
private boolean mRingNotified;
|
||||
private String mQuotePrefix;
|
||||
private boolean mSyncRemoteDeletions;
|
||||
|
||||
private List<Identity> identities;
|
||||
|
||||
@ -153,6 +154,7 @@ public class Account implements BaseAccount
|
||||
subscribedFoldersOnly = false;
|
||||
maximumPolledMessageAge = -1;
|
||||
mQuotePrefix = DEFAULT_QUOTE_PREFIX;
|
||||
mSyncRemoteDeletions = true;
|
||||
|
||||
searchableFolders = Searchable.ALL;
|
||||
|
||||
@ -214,7 +216,8 @@ public class Account implements BaseAccount
|
||||
mOutboxFolderName = preferences.getPreferences().getString(mUuid + ".outboxFolderName",
|
||||
"Outbox");
|
||||
mExpungePolicy = preferences.getPreferences().getString(mUuid + ".expungePolicy", EXPUNGE_IMMEDIATELY);
|
||||
|
||||
mSyncRemoteDeletions = preferences.getPreferences().getBoolean(mUuid + ".syncRemoteDeletions", true);
|
||||
|
||||
mMaxPushFolders = preferences.getPreferences().getInt(mUuid + ".maxPushFolders", 10);
|
||||
goToUnreadMessageSearch = preferences.getPreferences().getBoolean(mUuid + ".goToUnreadMessageSearch",
|
||||
false);
|
||||
@ -393,6 +396,7 @@ public class Account implements BaseAccount
|
||||
editor.remove(mUuid + ".hideButtonsEnum");
|
||||
editor.remove(mUuid + ".signatureBeforeQuotedText");
|
||||
editor.remove(mUuid + ".expungePolicy");
|
||||
editor.remove(mUuid + ".syncRemoteDeletions");
|
||||
editor.remove(mUuid + ".maxPushFolders");
|
||||
editor.remove(mUuid + ".searchableFolders");
|
||||
editor.remove(mUuid + ".chipColor");
|
||||
@ -481,6 +485,7 @@ public class Account implements BaseAccount
|
||||
editor.putString(mUuid + ".folderTargetMode", mFolderTargetMode.name());
|
||||
editor.putBoolean(mUuid + ".signatureBeforeQuotedText", this.mIsSignatureBeforeQuotedText);
|
||||
editor.putString(mUuid + ".expungePolicy", mExpungePolicy);
|
||||
editor.putBoolean(mUuid + ".syncRemoteDeletions", mSyncRemoteDeletions);
|
||||
editor.putInt(mUuid + ".maxPushFolders", mMaxPushFolders);
|
||||
editor.putString(mUuid + ".searchableFolders", searchableFolders.name());
|
||||
editor.putInt(mUuid + ".chipColor", mChipColor);
|
||||
@ -1329,4 +1334,14 @@ public class Account implements BaseAccount
|
||||
{
|
||||
mQuotePrefix = quotePrefix;
|
||||
}
|
||||
|
||||
public boolean syncRemoteDeletions()
|
||||
{
|
||||
return mSyncRemoteDeletions;
|
||||
}
|
||||
|
||||
public void setSyncRemoteDeletions(boolean syncRemoteDeletions)
|
||||
{
|
||||
mSyncRemoteDeletions = syncRemoteDeletions;
|
||||
}
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ public class AccountSettings extends K9PreferenceActivity
|
||||
private static final String PREFERENCE_NOTIFICATION_OPENS_UNREAD = "notification_opens_unread";
|
||||
private static final String PREFERENCE_MESSAGE_AGE = "account_message_age";
|
||||
private static final String PREFERENCE_QUOTE_PREFIX = "account_quote_prefix";
|
||||
private static final String PREFERENCE_SYNC_REMOTE_DELETIONS = "account_sync_remote_deletetions";
|
||||
|
||||
|
||||
private Account mAccount;
|
||||
@ -86,6 +87,7 @@ public class AccountSettings extends K9PreferenceActivity
|
||||
private boolean mIncomingChanged = false;
|
||||
private CheckBoxPreference mNotificationOpensUnread;
|
||||
private EditTextPreference mAccountQuotePrefix;
|
||||
private CheckBoxPreference mSyncRemoteDeletions;
|
||||
|
||||
|
||||
public static void actionSettings(Context context, Account account)
|
||||
@ -258,6 +260,9 @@ public class AccountSettings extends K9PreferenceActivity
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
mSyncRemoteDeletions = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_REMOTE_DELETIONS);
|
||||
mSyncRemoteDeletions.setChecked(mAccount.syncRemoteDeletions());
|
||||
|
||||
mSearchableFolders = (ListPreference) findPreference(PREFERENCE_SEARCHABLE_FOLDERS);
|
||||
mSearchableFolders.setValue(mAccount.getSearchableFolders().name());
|
||||
@ -491,6 +496,7 @@ public class AccountSettings extends K9PreferenceActivity
|
||||
mAccount.setFolderTargetMode(Account.FolderMode.valueOf(mTargetMode.getValue()));
|
||||
mAccount.setDeletePolicy(Integer.parseInt(mDeletePolicy.getValue()));
|
||||
mAccount.setExpungePolicy(mExpungePolicy.getValue());
|
||||
mAccount.setSyncRemoteDeletions(mSyncRemoteDeletions.isChecked());
|
||||
mAccount.setSearchableFolders(Account.Searchable.valueOf(mSearchableFolders.getValue()));
|
||||
mAccount.setQuotePrefix(mAccountQuotePrefix.getText());
|
||||
|
||||
|
@ -1177,20 +1177,22 @@ public class MessagingController implements Runnable
|
||||
/*
|
||||
* Remove any messages that are in the local store but no longer on the remote store or are too old
|
||||
*/
|
||||
|
||||
for (Message localMessage : localMessages)
|
||||
if (account.syncRemoteDeletions())
|
||||
{
|
||||
if (remoteUidMap.get(localMessage.getUid()) == null && !localMessage.isSet(Flag.DELETED))
|
||||
for (Message localMessage : localMessages)
|
||||
{
|
||||
localMessage.setFlag(Flag.X_DESTROYED, true);
|
||||
|
||||
for (MessagingListener l : getListeners())
|
||||
if (remoteUidMap.get(localMessage.getUid()) == null && !localMessage.isSet(Flag.DELETED))
|
||||
{
|
||||
l.synchronizeMailboxRemovedMessage(account, folder, localMessage);
|
||||
}
|
||||
if (listener != null && getListeners().contains(listener) == false)
|
||||
{
|
||||
listener.synchronizeMailboxRemovedMessage(account, folder, localMessage);
|
||||
localMessage.setFlag(Flag.X_DESTROYED, true);
|
||||
|
||||
for (MessagingListener l : getListeners())
|
||||
{
|
||||
l.synchronizeMailboxRemovedMessage(account, folder, localMessage);
|
||||
}
|
||||
if (listener != null && getListeners().contains(listener) == false)
|
||||
{
|
||||
listener.synchronizeMailboxRemovedMessage(account, folder, localMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1892,17 +1894,23 @@ public class MessagingController implements Runnable
|
||||
}
|
||||
if (remoteMessage.isSet(Flag.DELETED))
|
||||
{
|
||||
localMessage.setFlag(Flag.DELETED, true);
|
||||
messageChanged = true;
|
||||
}
|
||||
for (Flag flag : new Flag[] { Flag.SEEN, Flag.FLAGGED, Flag.ANSWERED })
|
||||
{
|
||||
if (remoteMessage.isSet(flag) != localMessage.isSet(flag))
|
||||
if (localMessage.getFolder().getAccount().syncRemoteDeletions())
|
||||
{
|
||||
localMessage.setFlag(flag, remoteMessage.isSet(flag));
|
||||
localMessage.setFlag(Flag.DELETED, true);
|
||||
messageChanged = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Flag flag : new Flag[] { Flag.SEEN, Flag.FLAGGED, Flag.ANSWERED })
|
||||
{
|
||||
if (remoteMessage.isSet(flag) != localMessage.isSet(flag))
|
||||
{
|
||||
localMessage.setFlag(flag, remoteMessage.isSet(flag));
|
||||
messageChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return messageChanged;
|
||||
}
|
||||
private String getRootCauseMessage(Throwable t)
|
||||
|
Loading…
Reference in New Issue
Block a user