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

Unverified Commit 74942150 authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #4839 from k9mail/local_only_operations

Don't attempt to perform remote operations on local-only folders
parents 3afdb8cc 5c5f2409
Loading
Loading
Loading
Loading
+33 −23
Original line number Diff line number Diff line
@@ -1021,7 +1021,7 @@ public class MessagingController {
        }

        Backend backend = getBackend(account);
        if (backend.getSupportsSeenFlag()) {
        if (backend.getSupportsFlags()) {
            backend.markAllAsRead(folderServerId);
        }
    }
@@ -1092,6 +1092,8 @@ public class MessagingController {
            return;
        }

        boolean accountSupportsFlags = supportsFlags(account);

        // Loop over all folders
        for (Entry<Long, List<String>> entry : folderMap.entrySet()) {
            long folderId = entry.getKey();
@@ -1102,12 +1104,20 @@ public class MessagingController {
                l.folderStatusChanged(account, folderId);
            }

            // TODO: Skip the remote part for all local-only folders

            if (accountSupportsFlags) {
                LocalFolder localFolder = localStore.getFolder(folderId);
                try {
                    localFolder.open();
                    if (!localFolder.isLocalOnly()) {
                        // Send flag change to server
                        queueSetFlag(account, folderId, newState, flag, uids);
                        processPendingCommands(account);
                    }
                } catch (MessagingException e) {
                    Timber.e(e, "Couldn't open folder. Account: %s, folder ID: %d", account, folderId);
                }
            }
        }
    }

    /**
@@ -1131,16 +1141,12 @@ public class MessagingController {
                l.folderStatusChanged(account, folderId);
            }


            /*
             * Handle the remote side
             */

            // TODO: Skip the remote part for all local-only folders

            // Handle the remote side
            if (supportsFlags(account) && !localFolder.isLocalOnly()) {
                List<String> uids = getUidsFromMessages(messages);
                queueSetFlag(account, folderId, newState, flag, uids);
                processPendingCommands(account);
            }
        } catch (MessagingException me) {
            throw new RuntimeException(me);
        }
@@ -1595,11 +1601,13 @@ public class MessagingController {

            Timber.i("Moved sent message to folder '%s' (%d)", sentFolderServerId, sentFolderId);

            if (!sentFolder.isLocalOnly()) {
                PendingCommand command = PendingAppend.create(sentFolderId, message.getUid());
                queuePendingCommand(account, command);
                processPendingCommands(account);
            }
        }
    }

    private void handleSendFailure(Account account, LocalFolder localFolder, Message message, Exception exception)
            throws MessagingException {
@@ -1652,8 +1660,8 @@ public class MessagingController {
        return getBackend(account).isPushCapable();
    }

    public boolean supportsSeenFlag(Account account) {
        return getBackend(account).getSupportsSeenFlag();
    public boolean supportsFlags(Account account) {
        return getBackend(account).getSupportsFlags();
    }

    public boolean supportsExpunge(Account account) {
@@ -1996,7 +2004,7 @@ public class MessagingController {
            Timber.d("Delete policy for account %s is %s", account.getDescription(), account.getDeletePolicy());

            Long outboxFolderId = account.getOutboxFolderId();
            if (outboxFolderId != null && folderId == outboxFolderId) {
            if (outboxFolderId != null && folderId == outboxFolderId && supportsUpload(account)) {
                for (Message message : messages) {
                    // If the message was in the Outbox, then it has been copied to local Trash, and has
                    // to be copied to remote trash
@@ -2004,6 +2012,8 @@ public class MessagingController {
                    queuePendingCommand(account, command);
                }
                processPendingCommands(account);
            } else if (localFolder.isLocalOnly()) {
                // Nothing to do on the remote side
            } else if (!syncedMessageUids.isEmpty()) {
                if (account.getDeletePolicy() == DeletePolicy.ON_DELETE) {
                    if (!account.hasTrashFolder() || folderId == trashFolderId ||
@@ -2526,7 +2536,7 @@ public class MessagingController {
                localMessage.setCachedDecryptedSubject(plaintextSubject);
            }

            if (saveRemotely) {
            if (saveRemotely && supportsUpload(account)) {
                PendingCommand command = PendingAppend.create(localFolder.getDatabaseId(), localMessage.getUid());
                queuePendingCommand(account, command);
                processPendingCommands(account);
+1 −1
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), ConfirmationDialogFr

    private fun initializeDeletePolicy(account: Account) {
        (findPreference(PREFERENCE_DELETE_POLICY) as? ListPreference)?.apply {
            if (!messagingController.supportsSeenFlag(account)) {
            if (!messagingController.supportsFlags(account)) {
                removeEntry(DELETE_POLICY_MARK_AS_READ)
            }
        }
+1 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ import com.fsck.k9.mail.MessagingException
import com.fsck.k9.mail.Part

interface Backend {
    val supportsSeenFlag: Boolean
    val supportsFlags: Boolean
    val supportsExpunge: Boolean
    val supportsMove: Boolean
    val supportsCopy: Boolean
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ public class ImapBackend implements Backend {
    }

    @Override
    public boolean getSupportsSeenFlag() {
    public boolean getSupportsFlags() {
        return true;
    }

+1 −1
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ class JmapBackend(
    private val commandDelete = CommandDelete(jmapClient, accountId)
    private val commandMove = CommandMove(jmapClient, accountId)
    private val commandUpload = CommandUpload(jmapClient, okHttpClient, httpAuthentication, accountId)
    override val supportsSeenFlag = true
    override val supportsFlags = true
    override val supportsExpunge = false
    override val supportsMove = true
    override val supportsCopy = true
Loading