Move protocol capability flags to Backend implementations

This commit is contained in:
cketti 2018-06-18 02:44:05 +02:00
parent e46c0699da
commit d2dd21de97
5 changed files with 35 additions and 30 deletions

View file

@ -13,6 +13,9 @@ import com.fsck.k9.mail.Part
interface Backend {
val supportsSeenFlag: Boolean
val supportsExpunge: Boolean
val supportsMove: Boolean
val supportsCopy: Boolean
val supportsTrashFolder: Boolean
@Throws(MessagingException::class)
fun getFolders(forceListAll: Boolean): List<FolderInfo>

View file

@ -60,6 +60,21 @@ public class ImapBackend implements Backend {
return true;
}
@Override
public boolean getSupportsMove() {
return true;
}
@Override
public boolean getSupportsCopy() {
return true;
}
@Override
public boolean getSupportsTrashFolder() {
return true;
}
@NotNull
@Override
public List<FolderInfo> getFolders(boolean forceListAll) {

View file

@ -20,8 +20,11 @@ class Pop3Backend(accountName: String, backendStorage: BackendStorage, pop3Store
private val commandDeleteAll = CommandDeleteAll(pop3Store)
private val commandFetchMessage = CommandFetchMessage(pop3Store)
override val supportsSeenFlag: Boolean = false
override val supportsExpunge: Boolean = false
override val supportsSeenFlag = false
override val supportsExpunge = false
override val supportsMove = false
override val supportsCopy = false
override val supportsTrashFolder = false
override fun getFolders(forceListAll: Boolean): List<FolderInfo> {
return commandGetFolders.getFolders()

View file

@ -24,9 +24,11 @@ class WebDavBackend(accountName: String, backendStorage: BackendStorage, webDavS
private val commandFetchMessage = CommandFetchMessage(webDavStore)
private val commandUploadMessage = CommandUploadMessage(webDavStore)
override val supportsSeenFlag: Boolean = true
override val supportsExpunge: Boolean = true
override val supportsSeenFlag = true
override val supportsExpunge = true
override val supportsMove = true
override val supportsCopy = true
override val supportsTrashFolder = true
override fun getFolders(forceListAll: Boolean): List<FolderInfo> {
return commandGetFolders.getFolders(forceListAll)

View file

@ -86,7 +86,6 @@ import com.fsck.k9.mail.internet.MimeUtility;
import com.fsck.k9.mail.power.TracingPowerManager;
import com.fsck.k9.mail.power.TracingPowerManager.TracingWakeLock;
import com.fsck.k9.mail.store.RemoteStore;
import com.fsck.k9.mail.store.pop3.Pop3Store;
import com.fsck.k9.mailstore.LocalFolder;
import com.fsck.k9.mailstore.LocalMessage;
import com.fsck.k9.mailstore.LocalStore;
@ -2372,24 +2371,11 @@ public class MessagingController {
}
public boolean isMoveCapable(final Account account) {
try {
RemoteStore remoteStore = account.getRemoteStore();
return remoteStore.isMoveCapable();
} catch (MessagingException me) {
Timber.e(me, "Exception while ascertaining move capability");
return false;
}
return getBackend(account).getSupportsMove();
}
public boolean isCopyCapable(final Account account) {
try {
RemoteStore remoteStore = account.getRemoteStore();
return remoteStore.isCopyCapable();
} catch (MessagingException me) {
Timber.e(me, "Exception while ascertaining copy capability");
return false;
}
return getBackend(account).getSupportsCopy();
}
public void moveMessages(final Account srcAccount, final String srcFolder,
@ -2483,11 +2469,10 @@ public class MessagingController {
try {
LocalStore localStore = account.getLocalStore();
RemoteStore remoteStore = account.getRemoteStore();
if (!isCopy && !remoteStore.isMoveCapable()) {
if (!isCopy && !isMoveCapable(account)) {
return;
}
if (isCopy && !remoteStore.isCopyCapable()) {
if (isCopy && !isCopyCapable(account)) {
return;
}
@ -2899,13 +2884,10 @@ public class MessagingController {
*
* @return {@code true} if the account only has a local Trash folder that is not synchronized
* with a folder on the server. {@code false} otherwise.
*
* @throws MessagingException
* In case of an error.
*/
private boolean isTrashLocalOnly(Account account) throws MessagingException {
// TODO: Get rid of the tight coupling once we properly support local folders
return (account.getRemoteStore() instanceof Pop3Store);
private boolean isTrashLocalOnly(Account account) {
Backend backend = getBackend(account);
return !backend.getSupportsTrashFolder();
}
public void sendAlternate(Context context, Account account, LocalMessage message) {