Merge pull request #4388 from k9mail/imap_cleanup

Message/Folder related cleanup
This commit is contained in:
cketti 2019-12-19 13:54:04 +01:00 committed by GitHub
commit 34ad4a418a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 141 additions and 180 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

@ -32,21 +32,21 @@ public class MessagingControllerPushReceiver implements PushReceiver {
this.context = context;
}
public void messagesFlagsChanged(Folder folder, List<Message> messages) {
syncFolder(folder);
public void messagesFlagsChanged(String folderServerId, List<Message> messages) {
syncFolder(folderServerId);
}
public void messagesArrived(Folder folder, List<Message> messages) {
syncFolder(folder);
public void messagesArrived(String folderServerId, List<Message> messages) {
syncFolder(folderServerId);
}
public void messagesRemoved(Folder folder, List<Message> messages) {
syncFolder(folder);
public void messagesRemoved(String folderServerId, List<Message> messages) {
syncFolder(folderServerId);
}
public void syncFolder(Folder folder) {
Timber.v("syncFolder(%s)", folder.getServerId());
public void syncFolder(String folderServerId) {
Timber.v("syncFolder(%s)", folderServerId);
final CountDownLatch latch = new CountDownLatch(1);
controller.synchronizeMailbox(account, folder.getServerId(), new SimpleMessagingListener() {
controller.synchronizeMailbox(account, folderServerId, new SimpleMessagingListener() {
@Override
public void synchronizeMailboxFinished(Account account, String folderServerId,
int totalMessagesInMailbox, int numNewMessages) {
@ -58,13 +58,13 @@ public class MessagingControllerPushReceiver implements PushReceiver {
String message) {
latch.countDown();
}
}, folder);
});
Timber.v("syncFolder(%s) about to await latch release", folder.getServerId());
Timber.v("syncFolder(%s) about to await latch release", folderServerId);
try {
latch.await();
Timber.v("syncFolder(%s) got latch release", folder.getServerId());
Timber.v("syncFolder(%s) got latch release", folderServerId);
} catch (Exception e) {
Timber.e(e, "Interrupted while awaiting latch release");
}

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

@ -25,12 +25,12 @@ import com.fsck.k9.mail.DefaultBodyFactory;
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.MessageRetrievalListener;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.Part;
import com.fsck.k9.mail.internet.MessageExtractor;
import com.fsck.k9.mail.store.imap.ImapFolder;
import com.fsck.k9.mail.store.imap.ImapMessage;
import com.fsck.k9.mail.store.imap.ImapStore;
import timber.log.Timber;
@ -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();
/*
@ -125,8 +117,8 @@ class ImapSync {
visibleLimit = syncConfig.getDefaultVisibleLimit();
}
final List<Message> remoteMessages = new ArrayList<>();
Map<String, Message> remoteUidMap = new HashMap<>();
final List<ImapMessage> remoteMessages = new ArrayList<>();
Map<String, ImapMessage> remoteUidMap = new HashMap<>();
Timber.v("SYNC: Remote message count for folder %s is %d", folder, remoteMessageCount);
@ -150,12 +142,12 @@ class ImapSync {
listener.syncHeadersStarted(folder, folderName);
List<? extends Message> remoteMessageArray =
List<ImapMessage> remoteMessageArray =
remoteFolder.getMessages(remoteStart, remoteMessageCount, earliestDate, null);
int messageCount = remoteMessageArray.size();
for (Message thisMess : remoteMessageArray) {
for (ImapMessage thisMess : remoteMessageArray) {
headerProgress.incrementAndGet();
listener.syncHeadersProgress(folder, headerProgress.get(), messageCount);
@ -249,10 +241,8 @@ class ImapSync {
System.currentTimeMillis());
} finally {
if (providedRemoteFolder == null) {
closeFolder(remoteFolder);
}
}
}
@ -262,7 +252,7 @@ class ImapSync {
ImapFolder remoteFolder = imapStore.getFolder(folderServerId);
try {
remoteFolder.open(Folder.OPEN_MODE_RO);
Message remoteMessage = remoteFolder.getMessage(messageServerId);
ImapMessage remoteMessage = remoteFolder.getMessage(messageServerId);
downloadMessages(
syncConfig,
@ -293,19 +283,19 @@ class ImapSync {
*
* @throws MessagingException
*/
private int downloadMessages(SyncConfig syncConfig, Folder remoteFolder, BackendFolder backendFolder,
List<Message> inputMessages, boolean flagSyncOnly, Long lastUid,
private int downloadMessages(SyncConfig syncConfig, ImapFolder remoteFolder, BackendFolder backendFolder,
List<ImapMessage> inputMessages, boolean flagSyncOnly, Long lastUid,
final SyncListener listener) throws MessagingException {
final String folder = remoteFolder.getServerId();
List<Message> syncFlagMessages = new ArrayList<>();
List<Message> unsyncedMessages = new ArrayList<>();
List<ImapMessage> syncFlagMessages = new ArrayList<>();
List<ImapMessage> unsyncedMessages = new ArrayList<>();
final AtomicInteger newMessages = new AtomicInteger(0);
List<Message> messages = new ArrayList<>(inputMessages);
List<ImapMessage> messages = new ArrayList<>(inputMessages);
for (Message message : messages) {
for (ImapMessage message : messages) {
evaluateMessageForDownload(message, backendFolder, remoteFolder, unsyncedMessages, syncFlagMessages,
flagSyncOnly);
}
@ -317,8 +307,8 @@ class ImapSync {
Timber.d("SYNC: Have %d unsynced messages", unsyncedMessages.size());
messages.clear();
final List<Message> largeMessages = new ArrayList<>();
final List<Message> smallMessages = new ArrayList<>();
final List<ImapMessage> largeMessages = new ArrayList<>();
final List<ImapMessage> smallMessages = new ArrayList<>();
if (!unsyncedMessages.isEmpty()) {
Collections.sort(unsyncedMessages, new UidReverseComparator());
int visibleLimit = backendFolder.getVisibleLimit();
@ -338,7 +328,7 @@ class ImapSync {
todo, fp, listener);
String updatedPushState = backendFolder.getPushState();
for (Message message : unsyncedMessages) {
for (ImapMessage message : unsyncedMessages) {
String newPushState = remoteFolder.getNewPushState(updatedPushState, message);
if (newPushState != null) {
updatedPushState = newPushState;
@ -387,8 +377,8 @@ class ImapSync {
return newMessages.get();
}
private void evaluateMessageForDownload(Message message, BackendFolder backendFolder, Folder remoteFolder,
List<Message> unsyncedMessages, List<Message> syncFlagMessages, boolean flagSyncOnly) {
private void evaluateMessageForDownload(ImapMessage message, BackendFolder backendFolder, ImapFolder remoteFolder,
List<ImapMessage> unsyncedMessages, List<ImapMessage> syncFlagMessages, boolean flagSyncOnly) {
String messageServerId = message.getUid();
if (message.isSet(Flag.DELETED)) {
@ -443,12 +433,12 @@ class ImapSync {
return false;
}
private <T extends Message> void fetchUnsyncedMessages(
private void fetchUnsyncedMessages(
final SyncConfig syncConfig,
final Folder<T> remoteFolder,
List<T> unsyncedMessages,
final List<Message> smallMessages,
final List<Message> largeMessages,
final ImapFolder remoteFolder,
List<ImapMessage> unsyncedMessages,
final List<ImapMessage> smallMessages,
final List<ImapMessage> largeMessages,
final AtomicInteger progress,
final int todo,
FetchProfile fp,
@ -456,9 +446,9 @@ class ImapSync {
final String folder = remoteFolder.getServerId();
remoteFolder.fetch(unsyncedMessages, fp,
new MessageRetrievalListener<T>() {
new MessageRetrievalListener<ImapMessage>() {
@Override
public void messageFinished(T message, int number, int ofTotal) {
public void messageFinished(ImapMessage message, int number, int ofTotal) {
try {
if (message.isSet(Flag.DELETED)) {
Timber.v("Newly downloaded message %s:%s:%s was marked deleted on server, skipping",
@ -495,10 +485,10 @@ class ImapSync {
});
}
private <T extends Message> void downloadSmallMessages(
final Folder<T> remoteFolder,
private void downloadSmallMessages(
final ImapFolder remoteFolder,
final BackendFolder backendFolder,
List<T> smallMessages,
List<ImapMessage> smallMessages,
final AtomicInteger progress,
final AtomicInteger newMessages,
final int todo,
@ -510,9 +500,9 @@ class ImapSync {
Timber.d("SYNC: Fetching %d small messages for folder %s", smallMessages.size(), folder);
remoteFolder.fetch(smallMessages,
fp, new MessageRetrievalListener<T>() {
fp, new MessageRetrievalListener<ImapMessage>() {
@Override
public void messageFinished(final T message, int number, int ofTotal) {
public void messageFinished(final ImapMessage message, int number, int ofTotal) {
try {
// Store the updated message locally
backendFolder.saveCompleteMessage(message);
@ -551,10 +541,10 @@ class ImapSync {
Timber.d("SYNC: Done fetching small messages for folder %s", folder);
}
private <T extends Message> void downloadLargeMessages(
final Folder<T> remoteFolder,
private void downloadLargeMessages(
final ImapFolder remoteFolder,
final BackendFolder backendFolder,
List<T> largeMessages,
List<ImapMessage> largeMessages,
final AtomicInteger progress,
final AtomicInteger newMessages,
final int todo,
@ -566,7 +556,7 @@ class ImapSync {
Timber.d("SYNC: Fetching large messages for folder %s", folder);
remoteFolder.fetch(largeMessages, fp, null);
for (T message : largeMessages) {
for (ImapMessage message : largeMessages) {
if (message.getBody() == null) {
downloadSaneBody(remoteFolder, backendFolder, message);
} else {
@ -599,9 +589,9 @@ class ImapSync {
private void refreshLocalMessageFlags(
SyncConfig syncConfig,
final Folder remoteFolder,
final ImapFolder remoteFolder,
final BackendFolder backendFolder,
List<Message> syncFlagMessages,
List<ImapMessage> syncFlagMessages,
final AtomicInteger progress,
final int todo,
SyncListener listener
@ -613,15 +603,15 @@ class ImapSync {
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.FLAGS);
List<Message> undeletedMessages = new LinkedList<>();
for (Message message : syncFlagMessages) {
List<ImapMessage> undeletedMessages = new LinkedList<>();
for (ImapMessage message : syncFlagMessages) {
if (!message.isSet(Flag.DELETED)) {
undeletedMessages.add(message);
}
}
remoteFolder.fetch(undeletedMessages, fp, null);
for (Message remoteMessage : syncFlagMessages) {
for (ImapMessage remoteMessage : syncFlagMessages) {
boolean messageChanged = syncFlags(syncConfig, backendFolder, remoteMessage);
if (messageChanged) {
listener.syncFlagChanged(folder, remoteMessage.getUid());
@ -631,7 +621,7 @@ class ImapSync {
}
}
private void downloadSaneBody(Folder remoteFolder, BackendFolder backendFolder, Message message)
private void downloadSaneBody(ImapFolder remoteFolder, BackendFolder backendFolder, ImapMessage message)
throws MessagingException {
/*
* The provider was unable to get the structure of the message, so
@ -653,7 +643,7 @@ class ImapSync {
backendFolder.savePartialMessage(message);
}
private void downloadPartial(Folder remoteFolder, BackendFolder backendFolder, Message message)
private void downloadPartial(ImapFolder remoteFolder, BackendFolder backendFolder, ImapMessage message)
throws MessagingException {
/*
* We have a structure to deal with, from which
@ -675,7 +665,7 @@ class ImapSync {
backendFolder.savePartialMessage(message);
}
private boolean syncFlags(SyncConfig syncConfig, BackendFolder backendFolder, Message remoteMessage) {
private boolean syncFlags(SyncConfig syncConfig, BackendFolder backendFolder, ImapMessage remoteMessage) {
String messageServerId = remoteMessage.getUid();
if (!backendFolder.isMessagePresent(messageServerId)) {
@ -704,13 +694,13 @@ class ImapSync {
return messageChanged;
}
private static void closeFolder(Folder folder) {
private static void closeFolder(ImapFolder folder) {
if (folder != null) {
folder.close();
}
}
private void updateMoreMessages(Folder remoteFolder, BackendFolder backendFolder, Date earliestDate, int remoteStart)
private void updateMoreMessages(ImapFolder remoteFolder, BackendFolder backendFolder, Date earliestDate, int remoteStart)
throws MessagingException, IOException {
if (remoteStart == 1) {

View file

@ -15,10 +15,10 @@ import com.fsck.k9.backend.api.SyncListener;
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.MessageRetrievalListener;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.store.imap.ImapFolder;
import com.fsck.k9.mail.store.imap.ImapMessage;
import com.fsck.k9.mail.store.imap.ImapStore;
import org.junit.Before;
import org.junit.Test;
@ -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));
@ -187,11 +167,11 @@ public class ImapSyncTest {
throws Exception {
messageCountInRemoteFolder(1);
Date dateOfEarliestPoll = new Date();
Message remoteMessage = messageOnServer();
ImapMessage remoteMessage = messageOnServer();
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());
}
@ -200,13 +180,13 @@ public class ImapSyncTest {
public void sync_withAccountSetToSyncRemoteDeletions_shouldDeleteLocalCopiesOfExistingMessagesBeforeEarliestPollDate()
throws Exception {
messageCountInRemoteFolder(1);
Message remoteMessage = messageOnServer();
ImapMessage remoteMessage = messageOnServer();
Date dateOfEarliestPoll = new Date();
configureSyncConfigWithSyncRemoteDeletionsAndEarliestPollDate(dateOfEarliestPoll);
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));
@ -239,13 +219,13 @@ public class ImapSyncTest {
@Test
public void sync_withUnsyncedNewSmallMessage_shouldFetchBodyOfSmallMessage() throws Exception {
Message smallMessage = buildSmallNewMessage();
ImapMessage smallMessage = buildSmallNewMessage();
messageCountInRemoteFolder(1);
hasUnsyncedRemoteMessage();
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));
@ -255,13 +235,13 @@ public class ImapSyncTest {
@Test
public void sync_withUnsyncedNewSmallMessage_shouldFetchStructureAndLimitedBodyOfLargeMessage() throws Exception {
Message largeMessage = buildLargeNewMessage();
ImapMessage largeMessage = buildLargeNewMessage();
messageCountInRemoteFolder(1);
hasUnsyncedRemoteMessage();
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(),
@ -272,7 +252,7 @@ public class ImapSyncTest {
assertEquals(FetchProfile.Item.BODY_SANE, fetchProfileCaptor.getAllValues().get(3).get(0));
}
private void respondToFetchEnvelopesWithMessage(final Message message) throws MessagingException {
private void respondToFetchEnvelopesWithMessage(final ImapMessage message) throws MessagingException {
doAnswer(new Answer() {
@Override
public Void answer(InvocationOnMock invocation) {
@ -290,15 +270,15 @@ public class ImapSyncTest {
}).when(remoteFolder).fetch(any(List.class), any(FetchProfile.class), nullable(MessageRetrievalListener.class));
}
private Message buildSmallNewMessage() {
Message message = mock(Message.class);
private ImapMessage buildSmallNewMessage() {
ImapMessage message = mock(ImapMessage.class);
when(message.olderThan(nullable(Date.class))).thenReturn(false);
when(message.getSize()).thenReturn((long) MAXIMUM_SMALL_MESSAGE_SIZE);
return message;
}
private Message buildLargeNewMessage() {
Message message = mock(Message.class);
private ImapMessage buildLargeNewMessage() {
ImapMessage message = mock(ImapMessage.class);
when(message.olderThan(nullable(Date.class))).thenReturn(false);
when(message.getSize()).thenReturn((long) (MAXIMUM_SMALL_MESSAGE_SIZE + 1));
return message;
@ -308,9 +288,9 @@ public class ImapSyncTest {
when(remoteFolder.getMessageCount()).thenReturn(value);
}
private Message messageOnServer() throws MessagingException {
private ImapMessage messageOnServer() throws MessagingException {
String messageUid = "UID";
Message remoteMessage = mock(Message.class);
ImapMessage remoteMessage = mock(ImapMessage.class);
when(remoteMessage.getUid()).thenReturn(messageUid);
when(remoteFolder.getMessages(anyInt(), anyInt(), nullable(Date.class),
@ -320,7 +300,7 @@ public class ImapSyncTest {
private void hasUnsyncedRemoteMessage() throws MessagingException {
String messageUid = "UID";
Message remoteMessage = mock(Message.class);
ImapMessage remoteMessage = mock(ImapMessage.class);
when(remoteMessage.getUid()).thenReturn(messageUid);
when(remoteFolder.getMessages(anyInt(), anyInt(), nullable(Date.class),
nullable(MessageRetrievalListener.class))).thenReturn(Collections.singletonList(remoteMessage));

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

View file

@ -7,10 +7,10 @@ import com.fsck.k9.mail.power.WakeLock;
public interface PushReceiver {
void syncFolder(Folder folder);
void messagesArrived(Folder folder, List<Message> mess);
void messagesFlagsChanged(Folder folder, List<Message> mess);
void messagesRemoved(Folder folder, List<Message> mess);
void syncFolder(String folderServerId);
void messagesArrived(String folderServerId, List<Message> mess);
void messagesFlagsChanged(String folderServerId, List<Message> mess);
void messagesRemoved(String folderServerId, List<Message> mess);
String getPushState(String folderServerId);
void pushError(String errorMessage, Exception e);
void authenticationFailed();

View file

@ -592,7 +592,7 @@ class ImapFolderPusher extends ImapFolder {
}
if (!messages.isEmpty()) {
pushReceiver.messagesArrived(ImapFolderPusher.this, messages);
pushReceiver.messagesArrived(getServerId(), messages);
}
}
}
@ -604,7 +604,7 @@ class ImapFolderPusher extends ImapFolder {
List<? extends Message> messageList = getMessages(messageSeqSet, true, null);
List<Message> messages = new ArrayList<>(messageList);
pushReceiver.messagesFlagsChanged(ImapFolderPusher.this, messages);
pushReceiver.messagesFlagsChanged(getServerId(), messages);
} catch (Exception e) {
pushReceiver.pushError("Exception while processing Push untagged responses", e);
}
@ -637,7 +637,7 @@ class ImapFolderPusher extends ImapFolder {
messages.add(message);
}
pushReceiver.messagesRemoved(ImapFolderPusher.this, messages);
pushReceiver.messagesRemoved(getServerId(), messages);
} catch (Exception e) {
Timber.e("Cannot remove EXPUNGEd messages");
}
@ -650,7 +650,7 @@ class ImapFolderPusher extends ImapFolder {
throw new MessagingException("Message count = -1 for idling");
}
pushReceiver.syncFolder(ImapFolderPusher.this);
pushReceiver.syncFolder(getServerId());
}
private void notifyMessagesArrived(long startUid, long uidNext) {
@ -666,7 +666,7 @@ class ImapFolderPusher extends ImapFolder {
messages.add(message);
}
pushReceiver.messagesArrived(ImapFolderPusher.this, messages);
pushReceiver.messagesArrived(getServerId(), messages);
}
private long getOldUidNext() {