Move code to get folder list to Backend implementations
This commit is contained in:
parent
af13655de1
commit
3b393964e2
10 changed files with 80 additions and 12 deletions
|
@ -10,6 +10,9 @@ interface Backend {
|
|||
val supportsSeenFlag: Boolean
|
||||
val supportsExpunge: Boolean
|
||||
|
||||
@Throws(MessagingException::class)
|
||||
fun getFolders(forceListAll: Boolean): List<FolderInfo>
|
||||
|
||||
// TODO: Add a way to cancel the sync process
|
||||
fun sync(folder: String, syncConfig: SyncConfig, listener: SyncListener, providedRemoteFolder: Folder<*>?)
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
package com.fsck.k9.backend.api
|
||||
|
||||
data class FolderInfo(val serverId: String, val name: String)
|
|
@ -0,0 +1,14 @@
|
|||
package com.fsck.k9.backend.imap
|
||||
|
||||
|
||||
import com.fsck.k9.backend.api.FolderInfo
|
||||
import com.fsck.k9.mail.store.imap.ImapStore
|
||||
|
||||
|
||||
internal class CommandGetFolders(private val imapStore: ImapStore) {
|
||||
fun getFolders(forceListAll: Boolean): List<FolderInfo> {
|
||||
return imapStore.getPersonalNamespaces(forceListAll).map {
|
||||
FolderInfo(it.serverId, it.name)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import java.util.Map;
|
|||
|
||||
import com.fsck.k9.backend.api.Backend;
|
||||
import com.fsck.k9.backend.api.BackendStorage;
|
||||
import com.fsck.k9.backend.api.FolderInfo;
|
||||
import com.fsck.k9.backend.api.SyncConfig;
|
||||
import com.fsck.k9.backend.api.SyncListener;
|
||||
import com.fsck.k9.mail.Flag;
|
||||
|
@ -18,6 +19,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
|
||||
public class ImapBackend implements Backend {
|
||||
private final ImapSync imapSync;
|
||||
private final CommandGetFolders commandGetFolders;
|
||||
private final CommandSetFlag commandSetFlag;
|
||||
private final CommandMarkAllAsRead commandMarkAllAsRead;
|
||||
private final CommandExpunge commandExpunge;
|
||||
|
@ -30,6 +32,7 @@ public class ImapBackend implements Backend {
|
|||
commandMarkAllAsRead = new CommandMarkAllAsRead(imapStore);
|
||||
commandExpunge = new CommandExpunge(imapStore);
|
||||
commandMoveOrCopyMessages = new CommandMoveOrCopyMessages(imapStore);
|
||||
commandGetFolders = new CommandGetFolders(imapStore);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -42,6 +45,12 @@ public class ImapBackend implements Backend {
|
|||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<FolderInfo> getFolders(boolean forceListAll) {
|
||||
return commandGetFolders.getFolders(forceListAll);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sync(@NotNull String folder, @NotNull SyncConfig syncConfig, @NotNull SyncListener listener,
|
||||
Folder providedRemoteFolder) {
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package com.fsck.k9.backend.pop3
|
||||
|
||||
|
||||
import com.fsck.k9.backend.api.FolderInfo
|
||||
import com.fsck.k9.mail.store.pop3.Pop3Folder
|
||||
|
||||
|
||||
internal class CommandGetFolders {
|
||||
fun getFolders(): List<FolderInfo> {
|
||||
return listOf(FolderInfo(Pop3Folder.INBOX, Pop3Folder.INBOX))
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.fsck.k9.backend.pop3
|
|||
|
||||
import com.fsck.k9.backend.api.Backend
|
||||
import com.fsck.k9.backend.api.BackendStorage
|
||||
import com.fsck.k9.backend.api.FolderInfo
|
||||
import com.fsck.k9.backend.api.SyncConfig
|
||||
import com.fsck.k9.backend.api.SyncListener
|
||||
import com.fsck.k9.mail.Flag
|
||||
|
@ -10,11 +11,16 @@ import com.fsck.k9.mail.store.pop3.Pop3Store
|
|||
|
||||
class Pop3Backend(accountName: String, backendStorage: BackendStorage, pop3Store: Pop3Store) : Backend {
|
||||
private val pop3Sync: Pop3Sync = Pop3Sync(accountName, backendStorage, pop3Store)
|
||||
private val commandGetFolders = CommandGetFolders()
|
||||
private val commandSetFlag = CommandSetFlag(pop3Store)
|
||||
|
||||
override val supportsSeenFlag: Boolean = false
|
||||
override val supportsExpunge: Boolean = false
|
||||
|
||||
override fun getFolders(forceListAll: Boolean): List<FolderInfo> {
|
||||
return commandGetFolders.getFolders()
|
||||
}
|
||||
|
||||
override fun sync(folder: String, syncConfig: SyncConfig, listener: SyncListener, providedRemoteFolder: Folder<*>?) {
|
||||
pop3Sync.sync(folder, syncConfig, listener)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package com.fsck.k9.backend.webdav
|
||||
|
||||
|
||||
import com.fsck.k9.backend.api.FolderInfo
|
||||
import com.fsck.k9.mail.store.webdav.WebDavStore
|
||||
|
||||
|
||||
internal class CommandGetFolders(private val webDavStore: WebDavStore) {
|
||||
fun getFolders(forceListAll: Boolean): List<FolderInfo> {
|
||||
return webDavStore.getPersonalNamespaces(forceListAll).map {
|
||||
FolderInfo(it.serverId, it.name)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.fsck.k9.backend.webdav
|
|||
|
||||
import com.fsck.k9.backend.api.Backend
|
||||
import com.fsck.k9.backend.api.BackendStorage
|
||||
import com.fsck.k9.backend.api.FolderInfo
|
||||
import com.fsck.k9.backend.api.SyncConfig
|
||||
import com.fsck.k9.backend.api.SyncListener
|
||||
import com.fsck.k9.mail.Flag
|
||||
|
@ -11,6 +12,7 @@ import com.fsck.k9.mail.store.webdav.WebDavStore
|
|||
|
||||
class WebDavBackend(accountName: String, backendStorage: BackendStorage, webDavStore: WebDavStore) : Backend {
|
||||
private val webDavSync: WebDavSync = WebDavSync(accountName, backendStorage, webDavStore)
|
||||
private val commandGetFolders = CommandGetFolders(webDavStore)
|
||||
private val commandSetFlag = CommandSetFlag(webDavStore)
|
||||
private val commandMarkAllAsRead = CommandMarkAllAsRead(webDavStore)
|
||||
private val commandMoveOrCopyMessages = CommandMoveOrCopyMessages(webDavStore)
|
||||
|
@ -19,6 +21,10 @@ class WebDavBackend(accountName: String, backendStorage: BackendStorage, webDavS
|
|||
override val supportsExpunge: Boolean = true
|
||||
|
||||
|
||||
override fun getFolders(forceListAll: Boolean): List<FolderInfo> {
|
||||
return commandGetFolders.getFolders(forceListAll)
|
||||
}
|
||||
|
||||
override fun sync(folder: String, syncConfig: SyncConfig, listener: SyncListener, providedRemoteFolder: Folder<*>?) {
|
||||
webDavSync.sync(folder, syncConfig, listener)
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ import com.fsck.k9.activity.MessageReference;
|
|||
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
|
||||
import com.fsck.k9.backend.BackendManager;
|
||||
import com.fsck.k9.backend.api.Backend;
|
||||
import com.fsck.k9.backend.api.FolderInfo;
|
||||
import com.fsck.k9.backend.api.MessageRemovalListener;
|
||||
import com.fsck.k9.backend.api.SyncConfig;
|
||||
import com.fsck.k9.backend.api.SyncListener;
|
||||
|
@ -433,12 +434,11 @@ public class MessagingController {
|
|||
void refreshRemoteSynchronous(final Account account, final MessagingListener listener) {
|
||||
List<LocalFolder> localFolders = null;
|
||||
try {
|
||||
RemoteStore store = account.getRemoteStore();
|
||||
|
||||
List<? extends Folder> remoteFolders = store.getPersonalNamespaces(false);
|
||||
Backend backend = getBackend(account);
|
||||
List<FolderInfo> folders = backend.getFolders(false);
|
||||
|
||||
LocalStore localStore = account.getLocalStore();
|
||||
Map<String, Folder> remoteFolderMap = new HashMap<>();
|
||||
Map<String, String> remoteFolderNameMap = new HashMap<>();
|
||||
List<LocalFolder> foldersToCreate = new LinkedList<>();
|
||||
|
||||
localFolders = localStore.getPersonalNamespaces(false);
|
||||
|
@ -447,12 +447,13 @@ public class MessagingController {
|
|||
localFolderServerIds.add(localFolder.getServerId());
|
||||
}
|
||||
|
||||
for (Folder remoteFolder : remoteFolders) {
|
||||
if (!localFolderServerIds.contains(remoteFolder.getServerId())) {
|
||||
LocalFolder localFolder = localStore.getFolder(remoteFolder.getServerId());
|
||||
for (FolderInfo folder : folders) {
|
||||
String folderServerId = folder.getServerId();
|
||||
if (!localFolderServerIds.contains(folderServerId)) {
|
||||
LocalFolder localFolder = localStore.getFolder(folderServerId);
|
||||
foldersToCreate.add(localFolder);
|
||||
}
|
||||
remoteFolderMap.put(remoteFolder.getServerId(), remoteFolder);
|
||||
remoteFolderNameMap.put(folderServerId, folder.getName());
|
||||
}
|
||||
localStore.createFolders(foldersToCreate, account.getDisplayCount());
|
||||
|
||||
|
@ -470,10 +471,10 @@ public class MessagingController {
|
|||
localFolder.delete(false);
|
||||
}
|
||||
|
||||
boolean folderExistsOnServer = remoteFolderMap.containsKey(localFolderServerId);
|
||||
boolean folderExistsOnServer = remoteFolderNameMap.containsKey(localFolderServerId);
|
||||
if (folderExistsOnServer) {
|
||||
Folder remoteFolder = remoteFolderMap.get(localFolderServerId);
|
||||
localFolder.setName(remoteFolder.getName());
|
||||
String folderName = remoteFolderNameMap.get(localFolderServerId);
|
||||
localFolder.setName(folderName);
|
||||
} else if (!account.isSpecialFolder(localFolderServerId)) {
|
||||
localFolder.delete(false);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ import static com.fsck.k9.mail.store.pop3.Pop3Commands.*;
|
|||
* POP3 only supports one folder, "Inbox". So the folder name is the ID here.
|
||||
*/
|
||||
public class Pop3Folder extends Folder<Pop3Message> {
|
||||
static final String INBOX = "INBOX";
|
||||
public static final String INBOX = "INBOX";
|
||||
|
||||
|
||||
private Pop3Store pop3Store;
|
||||
|
|
Loading…
Reference in a new issue