Search in sources :

Example 1 with FolderDetailsAccessor

use of com.fsck.k9.mailstore.FolderDetailsAccessor in project k-9 by k9mail.

the class MessagingController method syncFolder.

private void syncFolder(Account account, long folderId, boolean notify, MessagingListener listener, Backend backend, NotificationState notificationState) {
    ServerSettings serverSettings = account.getIncomingServerSettings();
    if (serverSettings.isMissingCredentials()) {
        handleAuthenticationFailure(account, true);
        return;
    }
    Exception commandException = null;
    try {
        processPendingCommandsSynchronous(account);
    } catch (Exception e) {
        Timber.e(e, "Failure processing command, but allow message sync attempt");
        commandException = e;
    }
    LocalFolder localFolder;
    try {
        LocalStore localStore = localStoreProvider.getInstance(account);
        localFolder = localStore.getFolder(folderId);
        localFolder.open();
    } catch (MessagingException e) {
        Timber.e(e, "syncFolder: Couldn't load local folder %d", folderId);
        return;
    }
    // We can't sync local folders
    if (localFolder.isLocalOnly()) {
        return;
    }
    final boolean suppressNotifications;
    if (notify) {
        MessageStore messageStore = messageStoreManager.getMessageStore(account);
        Long lastChecked = messageStore.getFolder(folderId, FolderDetailsAccessor::getLastChecked);
        suppressNotifications = lastChecked == null;
    } else {
        suppressNotifications = true;
    }
    String folderServerId = localFolder.getServerId();
    SyncConfig syncConfig = createSyncConfig(account);
    ControllerSyncListener syncListener = new ControllerSyncListener(account, listener, suppressNotifications, notificationState);
    backend.sync(folderServerId, syncConfig, syncListener);
    if (commandException != null && !syncListener.syncFailed) {
        String rootMessage = getRootCauseMessage(commandException);
        Timber.e("Root cause failure in %s:%s was '%s'", account, folderServerId, rootMessage);
        updateFolderStatus(account, folderServerId, rootMessage);
        listener.synchronizeMailboxFailed(account, folderId, rootMessage);
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) MessageStore(com.fsck.k9.mailstore.MessageStore) MessagingException(com.fsck.k9.mail.MessagingException) FolderDetailsAccessor(com.fsck.k9.mailstore.FolderDetailsAccessor) ServerSettings(com.fsck.k9.mail.ServerSettings) LocalStore(com.fsck.k9.mailstore.LocalStore) SyncConfig(com.fsck.k9.backend.api.SyncConfig) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) MessagingException(com.fsck.k9.mail.MessagingException) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException)

Aggregations

SyncConfig (com.fsck.k9.backend.api.SyncConfig)1 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)1 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)1 MessagingException (com.fsck.k9.mail.MessagingException)1 ServerSettings (com.fsck.k9.mail.ServerSettings)1 FolderDetailsAccessor (com.fsck.k9.mailstore.FolderDetailsAccessor)1 LocalFolder (com.fsck.k9.mailstore.LocalFolder)1 LocalStore (com.fsck.k9.mailstore.LocalStore)1 MessageStore (com.fsck.k9.mailstore.MessageStore)1