Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 80bee972 authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #2996 from k9mail/message_sync_refactor

Split synchronization code #2
parents c4c266c5 a47ab9d7
Loading
Loading
Loading
Loading
+33 −6
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import com.fsck.k9.controller.MessagingControllerCommands.PendingMarkAllAsRead;
import com.fsck.k9.controller.MessagingControllerCommands.PendingMoveOrCopy;
import com.fsck.k9.controller.MessagingControllerCommands.PendingSetFlag;
import com.fsck.k9.controller.ProgressBodyFactory.ProgressListener;
import com.fsck.k9.controller.imap.ImapMessageStore;
import com.fsck.k9.helper.Contacts;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.AuthenticationFailedException;
@@ -121,7 +122,7 @@ import static com.fsck.k9.mail.Flag.X_REMOTE_COPY_STARTED;
public class MessagingController {
    public static final long INVALID_MESSAGE_ID = -1;

    private static final Set<Flag> SYNC_FLAGS = EnumSet.of(Flag.SEEN, Flag.FLAGGED, Flag.ANSWERED, Flag.FORWARDED);
    public static final Set<Flag> SYNC_FLAGS = EnumSet.of(Flag.SEEN, Flag.FLAGGED, Flag.ANSWERED, Flag.FORWARDED);


    private static MessagingController inst = null;
@@ -141,6 +142,8 @@ public class MessagingController {
    private final MemorizingMessagingListener memorizingMessagingListener = new MemorizingMessagingListener();
    private final TransportProvider transportProvider;

    private ImapMessageStore imapMessageStore;


    private MessagingListener checkMailListener = null;
    private volatile boolean stopped = false;
@@ -254,6 +257,19 @@ public class MessagingController {
        throw new Error(e);
    }

    private RemoteMessageStore getRemoteMessageStore(Account account) {
        return account.getStoreUri().startsWith("imap") ? getImapMessageStore() : null;
    }

    private ImapMessageStore getImapMessageStore() {
        if (imapMessageStore == null) {
            imapMessageStore = new ImapMessageStore(notificationController, this, context);
        }

        return imapMessageStore;
    }


    public void addListener(MessagingListener listener) {
        listeners.add(listener);
        refreshListener(listener);
@@ -296,7 +312,7 @@ public class MessagingController {
        cache.unhideMessages(messages);
    }

    private boolean isMessageSuppressed(LocalMessage message) {
    public boolean isMessageSuppressed(LocalMessage message) {
        long messageId = message.getDatabaseId();
        long folderId = message.getFolder().getDatabaseId();

@@ -721,6 +737,17 @@ public class MessagingController {
    @VisibleForTesting
    void synchronizeMailboxSynchronous(final Account account, final String folder, final MessagingListener listener,
            Folder providedRemoteFolder) {
        RemoteMessageStore remoteMessageStore = getRemoteMessageStore(account);
        if (remoteMessageStore != null) {
            remoteMessageStore.sync(account, folder, listener, providedRemoteFolder);
        } else {
            synchronizeMailboxSynchronousLegacy(account, folder, listener, providedRemoteFolder);
        }
    }

    void synchronizeMailboxSynchronousLegacy(final Account account, final String folder, final MessagingListener listener,
        Folder providedRemoteFolder) {

        Folder remoteFolder = null;
        LocalFolder tLocalFolder = null;

@@ -984,11 +1011,11 @@ public class MessagingController {

    }

    void handleAuthenticationFailure(Account account, boolean incoming) {
    public void handleAuthenticationFailure(Account account, boolean incoming) {
        notificationController.showAuthenticationErrorNotification(account, incoming);
    }

    private void updateMoreMessages(Folder remoteFolder, LocalFolder localFolder, Date earliestDate, int remoteStart)
    public void updateMoreMessages(Folder remoteFolder, LocalFolder localFolder, Date earliestDate, int remoteStart)
            throws MessagingException, IOException {

        if (remoteStart == 1) {
@@ -1653,7 +1680,7 @@ public class MessagingController {
        });
    }

    private void processPendingCommandsSynchronous(Account account) throws MessagingException {
    public void processPendingCommandsSynchronous(Account account) throws MessagingException {
        LocalStore localStore = account.getLocalStore();
        List<PendingCommand> commands = localStore.getPendingCommands();

@@ -3709,7 +3736,7 @@ public class MessagingController {
    }


    private boolean shouldNotifyForMessage(Account account, LocalFolder localFolder, Message message) {
    public boolean shouldNotifyForMessage(Account account, LocalFolder localFolder, Message message) {
        // If we don't even have an account name, don't show the notification.
        // (This happens during initial account setup)
        if (account.getName() == null) {
+15 −0
Original line number Diff line number Diff line
package com.fsck.k9.controller;


import com.fsck.k9.Account;
import com.fsck.k9.mail.Folder;


public interface RemoteMessageStore {
    // TODO: Nicer interface
    //       Instead of using Account pass in "remote store config", "sync config", "local mail store" (like LocalStore
    //       only with an interface/implementation optimized for sync; eventually this can replace LocalStore which does
    //       many things we don't need and does badly some of the things we do need), "folder id", "sync listener"
    // TODO: Add a way to cancel the sync process
    void sync(Account account, String folder, MessagingListener listener, Folder providedRemoteFolder);
}
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ import java.util.Comparator;
import com.fsck.k9.mail.Message;


class UidReverseComparator implements Comparator<Message> {
public class UidReverseComparator implements Comparator<Message> {
    @Override
    public int compare(Message messageLeft, Message messageRight) {
        Long uidLeft = getUidForMessage(messageLeft);
+27 −0
Original line number Diff line number Diff line
package com.fsck.k9.controller.imap;


import android.content.Context;

import com.fsck.k9.Account;
import com.fsck.k9.controller.MessagingController;
import com.fsck.k9.controller.MessagingListener;
import com.fsck.k9.controller.RemoteMessageStore;
import com.fsck.k9.mail.Folder;
import com.fsck.k9.notification.NotificationController;


public class ImapMessageStore implements RemoteMessageStore {
    private final ImapSync imapSync;


    public ImapMessageStore(NotificationController notificationController, MessagingController controller,
            Context context) {
        this.imapSync = new ImapSync(notificationController, controller, context);
    }

    @Override
    public void sync(Account account, String folder, MessagingListener listener, Folder providedRemoteFolder) {
        imapSync.sync(account, folder, listener, providedRemoteFolder);
    }
}
+971 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading