Don't pass Folder instance to Backend

This commit is contained in:
cketti 2019-12-18 01:13:57 +01:00
parent aa13a46e3e
commit 84327e085d
10 changed files with 65 additions and 104 deletions

View file

@ -667,7 +667,7 @@ public class MessagingController {
if (localFolder.getVisibleLimit() > 0) {
localFolder.setVisibleLimit(localFolder.getVisibleLimit() + account.getDisplayCount());
}
synchronizeMailbox(account, folder, listener, null);
synchronizeMailbox(account, folder, listener);
} catch (MessagingException me) {
throw new RuntimeException("Unable to set visible limit on folder", me);
}
@ -676,12 +676,11 @@ public class MessagingController {
/**
* Start background synchronization of the specified folder.
*/
public void synchronizeMailbox(final Account account, final String folder, final MessagingListener listener,
final Folder providedRemoteFolder) {
public void synchronizeMailbox(final Account account, final String folder, final MessagingListener listener) {
putBackground("synchronizeMailbox", listener, new Runnable() {
@Override
public void run() {
synchronizeMailboxSynchronous(account, folder, listener, providedRemoteFolder);
synchronizeMailboxSynchronous(account, folder, listener);
}
});
}
@ -693,15 +692,12 @@ public class MessagingController {
* TODO Break this method up into smaller chunks.
*/
@VisibleForTesting
void synchronizeMailboxSynchronous(final Account account, final String folder, final MessagingListener listener,
Folder providedRemoteFolder) {
void synchronizeMailboxSynchronous(final Account account, final String folder, final MessagingListener listener) {
Backend remoteMessageStore = getBackend(account);
syncFolder(account, folder, listener, providedRemoteFolder, remoteMessageStore);
syncFolder(account, folder, listener, remoteMessageStore);
}
private void syncFolder(Account account, String folder, MessagingListener listener, Folder providedRemoteFolder,
Backend remoteMessageStore) {
private void syncFolder(Account account, String folder, MessagingListener listener, Backend remoteMessageStore) {
Exception commandException = null;
try {
processPendingCommandsSynchronous(account);
@ -718,7 +714,7 @@ public class MessagingController {
SyncConfig syncConfig = createSyncConfig(account);
ControllerSyncListener syncListener = new ControllerSyncListener(account, listener);
remoteMessageStore.sync(folder, syncConfig, syncListener, providedRemoteFolder);
remoteMessageStore.sync(folder, syncConfig, syncListener);
if (commandException != null && !syncListener.syncFailed) {
String rootMessage = getRootCauseMessage(commandException);
@ -2582,7 +2578,7 @@ public class MessagingController {
}
showFetchingMailNotificationIfNecessary(account, folder);
try {
synchronizeMailboxSynchronous(account, folder.getServerId(), listener, null);
synchronizeMailboxSynchronous(account, folder.getServerId(), listener);
} finally {
clearFetchingMailNotificationIfNecessary(account);
}

View file

@ -58,7 +58,7 @@ public class MessagingControllerPushReceiver implements PushReceiver {
String message) {
latch.countDown();
}
}, null);
});
Timber.v("syncFolder(%s) about to await latch release", folderServerId);

View file

@ -505,7 +505,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
}
MessagingController.getInstance(getApplication()).listFoldersSynchronous(account, true, null);
MessagingController.getInstance(getApplication())
.synchronizeMailbox(account, account.getInboxFolder(), null, null);
.synchronizeMailbox(account, account.getInboxFolder(), null);
}
private boolean isWebDavAccount() {

View file

@ -2132,7 +2132,7 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
public void checkMail() {
if (isSingleAccountMode() && isSingleFolderMode()) {
messagingController.synchronizeMailbox(account, folderServerId, activityListener, null);
messagingController.synchronizeMailbox(account, folderServerId, activityListener);
messagingController.sendPendingMessages(account, activityListener);
} else if (allAccounts) {
messagingController.checkMail(context, null, true, true, activityListener);

View file

@ -3,7 +3,6 @@ package com.fsck.k9.backend.api
import com.fsck.k9.mail.BodyFactory
import com.fsck.k9.mail.FetchProfile
import com.fsck.k9.mail.Flag
import com.fsck.k9.mail.Folder
import com.fsck.k9.mail.Message
import com.fsck.k9.mail.MessagingException
import com.fsck.k9.mail.Part
@ -25,7 +24,7 @@ interface Backend {
fun refreshFolderList()
// TODO: Add a way to cancel the sync process
fun sync(folder: String, syncConfig: SyncConfig, listener: SyncListener, providedRemoteFolder: Folder<*>?)
fun sync(folder: String, syncConfig: SyncConfig, listener: SyncListener)
@Throws(MessagingException::class)
fun downloadMessage(syncConfig: SyncConfig, folderServerId: String, messageServerId: String)

View file

@ -12,7 +12,6 @@ import com.fsck.k9.backend.api.SyncListener;
import com.fsck.k9.mail.BodyFactory;
import com.fsck.k9.mail.FetchProfile;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.Part;
@ -113,9 +112,8 @@ public class ImapBackend implements Backend {
}
@Override
public void sync(@NotNull String folder, @NotNull SyncConfig syncConfig, @NotNull SyncListener listener,
Folder providedRemoteFolder) {
imapSync.sync(folder, syncConfig, listener, providedRemoteFolder);
public void sync(@NotNull String folder, @NotNull SyncConfig syncConfig, @NotNull SyncListener listener) {
imapSync.sync(folder, syncConfig, listener);
}
@Override

View file

@ -47,16 +47,14 @@ class ImapSync {
this.imapStore = imapStore;
}
void sync(String folder, SyncConfig syncConfig, SyncListener listener, Folder providedRemoteFolder) {
synchronizeMailboxSynchronous(folder, syncConfig, listener, providedRemoteFolder);
void sync(String folder, SyncConfig syncConfig, SyncListener listener) {
synchronizeMailboxSynchronous(folder, syncConfig, listener);
}
void synchronizeMailboxSynchronous(final String folder, SyncConfig syncConfig, final SyncListener listener,
Folder providedRemoteFolder) {
Folder remoteFolder = null;
void synchronizeMailboxSynchronous(final String folder, SyncConfig syncConfig, final SyncListener listener) {
Timber.i("Synchronizing folder %s:%s", accountName, folder);
ImapFolder remoteFolder = null;
BackendFolder backendFolder = null;
try {
Timber.v("SYNC: About to get local folder %s", folder);
@ -74,10 +72,6 @@ class ImapSync {
Map<String, Long> localUidMap = backendFolder.getAllMessagesAndEffectiveDates();
if (providedRemoteFolder != null) {
Timber.v("SYNC: using providedRemoteFolder %s", folder);
remoteFolder = providedRemoteFolder;
} else {
Timber.v("SYNC: About to get remote folder %s", folder);
remoteFolder = imapStore.getFolder(folder);
@ -110,8 +104,6 @@ class ImapSync {
}
remoteFolder.open(Folder.OPEN_MODE_RO);
}
listener.syncAuthenticationSuccess();
/*
@ -249,10 +241,8 @@ class ImapSync {
System.currentTimeMillis());
} finally {
if (providedRemoteFolder == null) {
closeFolder(remoteFolder);
}
}
}

View file

@ -81,13 +81,14 @@ public class ImapSyncTest {
configureSyncConfig();
configureBackendStorage();
configureRemoteStoreWithFolder();
}
@Test
public void sync_withOneMessageInRemoteFolder_shouldFinishWithoutError() {
messageCountInRemoteFolder(1);
imapSync.sync(FOLDER_NAME, syncConfig, listener, remoteFolder);
imapSync.sync(FOLDER_NAME, syncConfig, listener);
verify(listener).syncFinished(FOLDER_NAME, 1, 0);
}
@ -96,7 +97,7 @@ public class ImapSyncTest {
public void sync_withEmptyRemoteFolder_shouldFinishWithoutError() {
messageCountInRemoteFolder(0);
imapSync.sync(FOLDER_NAME, syncConfig, listener, remoteFolder);
imapSync.sync(FOLDER_NAME, syncConfig, listener);
verify(listener).syncFinished(FOLDER_NAME, 0, 0);
}
@ -105,46 +106,26 @@ public class ImapSyncTest {
public void sync_withNegativeMessageCountInRemoteFolder_shouldFinishWithError() {
messageCountInRemoteFolder(-1);
imapSync.sync(FOLDER_NAME, syncConfig, listener, remoteFolder);
imapSync.sync(FOLDER_NAME, syncConfig, listener);
verify(listener).syncFailed(eq(FOLDER_NAME), eq("Exception: Message count -1 for folder Folder"),
any(Exception.class));
}
@Test
public void sync_withRemoteFolderProvided_shouldNotOpenRemoteFolder() throws Exception {
public void sync_shouldOpenRemoteFolder() throws Exception {
messageCountInRemoteFolder(1);
imapSync.sync(FOLDER_NAME, syncConfig, listener, remoteFolder);
verify(remoteFolder, never()).open(Folder.OPEN_MODE_RW);
}
@Test
public void sync_withNoRemoteFolderProvided_shouldOpenRemoteFolderFromStore() throws Exception {
messageCountInRemoteFolder(1);
configureRemoteStoreWithFolder();
imapSync.sync(FOLDER_NAME, syncConfig, listener, null);
imapSync.sync(FOLDER_NAME, syncConfig, listener);
verify(remoteFolder).open(Folder.OPEN_MODE_RO);
}
@Test
public void sync_withRemoteFolderProvided_shouldNotCloseRemoteFolder() {
public void sync_shouldCloseRemoteFolder() {
messageCountInRemoteFolder(1);
imapSync.sync(FOLDER_NAME, syncConfig, listener, remoteFolder);
verify(remoteFolder, never()).close();
}
@Test
public void sync_withNoRemoteFolderProvided_shouldCloseRemoteFolderFromStore() {
messageCountInRemoteFolder(1);
configureRemoteStoreWithFolder();
imapSync.sync(FOLDER_NAME, syncConfig, listener, null);
imapSync.sync(FOLDER_NAME, syncConfig, listener);
verify(remoteFolder).close();
}
@ -153,9 +134,8 @@ public class ImapSyncTest {
public void sync_withAccountPolicySetToExpungeOnPoll_shouldExpungeRemoteFolder() throws Exception {
messageCountInRemoteFolder(1);
configureSyncConfigWithExpungePolicy(ExpungePolicy.ON_POLL);
configureRemoteStoreWithFolder();
imapSync.sync(FOLDER_NAME, syncConfig, listener, null);
imapSync.sync(FOLDER_NAME, syncConfig, listener);
verify(remoteFolder).expunge();
}
@ -165,7 +145,7 @@ public class ImapSyncTest {
messageCountInRemoteFolder(1);
configureSyncConfigWithExpungePolicy(ExpungePolicy.MANUALLY);
imapSync.sync(FOLDER_NAME, syncConfig, listener, null);
imapSync.sync(FOLDER_NAME, syncConfig, listener);
verify(remoteFolder, never()).expunge();
}
@ -176,7 +156,7 @@ public class ImapSyncTest {
configureSyncConfigWithSyncRemoteDeletions(true);
when(backendFolder.getAllMessagesAndEffectiveDates()).thenReturn(Collections.singletonMap(MESSAGE_UID1, 0L));
imapSync.sync(FOLDER_NAME, syncConfig, listener, remoteFolder);
imapSync.sync(FOLDER_NAME, syncConfig, listener);
verify(backendFolder).destroyMessages(messageListCaptor.capture());
assertEquals(MESSAGE_UID1, messageListCaptor.getValue().get(0));
@ -191,7 +171,7 @@ public class ImapSyncTest {
configureSyncConfigWithSyncRemoteDeletionsAndEarliestPollDate(dateOfEarliestPoll);
when(remoteMessage.olderThan(dateOfEarliestPoll)).thenReturn(false);
imapSync.sync(FOLDER_NAME, syncConfig, listener, remoteFolder);
imapSync.sync(FOLDER_NAME, syncConfig, listener);
verify(backendFolder, never()).destroyMessages(messageListCaptor.capture());
}
@ -206,7 +186,7 @@ public class ImapSyncTest {
when(remoteMessage.olderThan(dateOfEarliestPoll)).thenReturn(true);
when(backendFolder.getAllMessagesAndEffectiveDates()).thenReturn(Collections.singletonMap(MESSAGE_UID1, 0L));
imapSync.sync(FOLDER_NAME, syncConfig, listener, remoteFolder);
imapSync.sync(FOLDER_NAME, syncConfig, listener);
verify(backendFolder).destroyMessages(messageListCaptor.capture());
assertEquals(MESSAGE_UID1, messageListCaptor.getValue().get(0));
@ -217,7 +197,7 @@ public class ImapSyncTest {
messageCountInRemoteFolder(0);
configureSyncConfigWithSyncRemoteDeletions(false);
imapSync.sync(FOLDER_NAME, syncConfig, listener, remoteFolder);
imapSync.sync(FOLDER_NAME, syncConfig, listener);
verify(backendFolder, never()).destroyMessages(messageListCaptor.capture());
}
@ -228,7 +208,7 @@ public class ImapSyncTest {
hasUnsyncedRemoteMessage();
when(remoteFolder.supportsFetchingFlags()).thenReturn(true);
imapSync.sync(FOLDER_NAME, syncConfig, listener, remoteFolder);
imapSync.sync(FOLDER_NAME, syncConfig, listener);
verify(remoteFolder, atLeastOnce()).fetch(any(List.class), fetchProfileCaptor.capture(),
nullable(MessageRetrievalListener.class));
@ -245,7 +225,7 @@ public class ImapSyncTest {
when(remoteFolder.supportsFetchingFlags()).thenReturn(false);
respondToFetchEnvelopesWithMessage(smallMessage);
imapSync.sync(FOLDER_NAME, syncConfig, listener, remoteFolder);
imapSync.sync(FOLDER_NAME, syncConfig, listener);
verify(remoteFolder, atLeast(2)).fetch(any(List.class), fetchProfileCaptor.capture(),
nullable(MessageRetrievalListener.class));
@ -261,7 +241,7 @@ public class ImapSyncTest {
when(remoteFolder.supportsFetchingFlags()).thenReturn(false);
respondToFetchEnvelopesWithMessage(largeMessage);
imapSync.sync(FOLDER_NAME, syncConfig, listener, remoteFolder);
imapSync.sync(FOLDER_NAME, syncConfig, listener);
//TODO: Don't bother fetching messages of a size we don't have
verify(remoteFolder, atLeast(4)).fetch(any(List.class), fetchProfileCaptor.capture(),

View file

@ -7,7 +7,6 @@ import com.fsck.k9.backend.api.SyncListener
import com.fsck.k9.mail.BodyFactory
import com.fsck.k9.mail.FetchProfile
import com.fsck.k9.mail.Flag
import com.fsck.k9.mail.Folder
import com.fsck.k9.mail.Message
import com.fsck.k9.mail.Part
import com.fsck.k9.mail.PushReceiver
@ -41,7 +40,7 @@ class Pop3Backend(
commandRefreshFolderList.refreshFolderList()
}
override fun sync(folder: String, syncConfig: SyncConfig, listener: SyncListener, providedRemoteFolder: Folder<*>?) {
override fun sync(folder: String, syncConfig: SyncConfig, listener: SyncListener) {
pop3Sync.sync(folder, syncConfig, listener)
}

View file

@ -7,7 +7,6 @@ import com.fsck.k9.backend.api.SyncListener
import com.fsck.k9.mail.BodyFactory
import com.fsck.k9.mail.FetchProfile
import com.fsck.k9.mail.Flag
import com.fsck.k9.mail.Folder
import com.fsck.k9.mail.Message
import com.fsck.k9.mail.MessagingException
import com.fsck.k9.mail.Part
@ -45,7 +44,7 @@ class WebDavBackend(
commandGetFolders.refreshFolderList()
}
override fun sync(folder: String, syncConfig: SyncConfig, listener: SyncListener, providedRemoteFolder: Folder<*>?) {
override fun sync(folder: String, syncConfig: SyncConfig, listener: SyncListener) {
webDavSync.sync(folder, syncConfig, listener)
}