Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 31809908 authored by Daniel Applebaum's avatar Daniel Applebaum
Browse files

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.

parent 45339457
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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>
+6 −0
Original line number Diff line number Diff line
@@ -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"
+16 −1
Original line number Diff line number Diff line
@@ -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,6 +216,7 @@ 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",
@@ -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;
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -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)
@@ -259,6 +261,9 @@ public class AccountSettings extends K9PreferenceActivity
            }
        });
        
        mSyncRemoteDeletions = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_REMOTE_DELETIONS);
        mSyncRemoteDeletions.setChecked(mAccount.syncRemoteDeletions());

        mSearchableFolders = (ListPreference) findPreference(PREFERENCE_SEARCHABLE_FOLDERS);
        mSearchableFolders.setValue(mAccount.getSearchableFolders().name());
        mSearchableFolders.setSummary(mSearchableFolders.getEntry());
@@ -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());

+25 −17
Original line number Diff line number Diff line
@@ -1177,7 +1177,8 @@ 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
             */
           
            if (account.syncRemoteDeletions())
            {
                for (Message localMessage : localMessages)
                {
                    if (remoteUidMap.get(localMessage.getUid()) == null && !localMessage.isSet(Flag.DELETED))
@@ -1194,6 +1195,7 @@ public class MessagingController implements Runnable
                        }
                    }
                }
            }
            localMessages = null;

            /*
@@ -1891,10 +1893,15 @@ public class MessagingController implements Runnable
            return false;
        }
        if (remoteMessage.isSet(Flag.DELETED))
        {
            if (localMessage.getFolder().getAccount().syncRemoteDeletions())
            {
                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))
@@ -1903,6 +1910,7 @@ public class MessagingController implements Runnable
                    messageChanged = true;
                }
            }
        }
        return messageChanged;
    }
    private String getRootCauseMessage(Throwable t)