Merge pull request #4839 from k9mail/local_only_operations

Don't attempt to perform remote operations on local-only folders
This commit is contained in:
cketti 2020-06-19 16:57:47 +02:00 committed by GitHub
commit 74942150e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 29 deletions

View file

@ -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,11 +1104,19 @@ public class MessagingController {
l.folderStatusChanged(account, folderId);
}
// TODO: Skip the remote part for all local-only folders
// Send flag change to server
queueSetFlag(account, folderId, newState, flag, uids);
processPendingCommands(account);
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
List<String> uids = getUidsFromMessages(messages);
queueSetFlag(account, folderId, newState, flag, uids);
processPendingCommands(account);
// 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,9 +1601,11 @@ public class MessagingController {
Timber.i("Moved sent message to folder '%s' (%d)", sentFolderServerId, sentFolderId);
PendingCommand command = PendingAppend.create(sentFolderId, message.getUid());
queuePendingCommand(account, command);
processPendingCommands(account);
if (!sentFolder.isLocalOnly()) {
PendingCommand command = PendingAppend.create(sentFolderId, message.getUid());
queuePendingCommand(account, command);
processPendingCommands(account);
}
}
}
@ -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);

View file

@ -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)
}
}

View file

@ -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

View file

@ -60,7 +60,7 @@ public class ImapBackend implements Backend {
}
@Override
public boolean getSupportsSeenFlag() {
public boolean getSupportsFlags() {
return true;
}

View file

@ -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

View file

@ -23,7 +23,7 @@ class Pop3Backend(
private val commandSetFlag = CommandSetFlag(pop3Store)
private val commandFetchMessage = CommandFetchMessage(pop3Store)
override val supportsSeenFlag = false
override val supportsFlags = false
override val supportsExpunge = false
override val supportsMove = false
override val supportsCopy = false

View file

@ -27,7 +27,7 @@ class WebDavBackend(
private val commandFetchMessage = CommandFetchMessage(webDavStore)
private val commandUploadMessage = CommandUploadMessage(webDavStore)
override val supportsSeenFlag = true
override val supportsFlags = true
override val supportsExpunge = true
override val supportsMove = true
override val supportsCopy = true