Search in sources :

Example 1 with MessageStore

use of com.fsck.k9.mailstore.MessageStore 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)

Example 2 with MessageStore

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

the class MessagingController method getFolderId.

private long getFolderId(Account account, String folderServerId) {
    MessageStore messageStore = messageStoreManager.getMessageStore(account);
    Long folderId = messageStore.getFolderId(folderServerId);
    if (folderId == null) {
        throw new IllegalStateException("Folder not found (server ID: " + folderServerId + ")");
    }
    return folderId;
}
Also used : MessageStore(com.fsck.k9.mailstore.MessageStore)

Example 3 with MessageStore

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

the class MessagingController method moveOrDeleteSentMessage.

private void moveOrDeleteSentMessage(Account account, LocalStore localStore, LocalMessage message) throws MessagingException {
    if (!account.hasSentFolder() || !account.isUploadSentMessages()) {
        Timber.i("Not uploading sent message; deleting local message");
        message.destroy();
    } else {
        long sentFolderId = account.getSentFolderId();
        LocalFolder sentFolder = localStore.getFolder(sentFolderId);
        sentFolder.open();
        String sentFolderServerId = sentFolder.getServerId();
        Timber.i("Moving sent message to folder '%s' (%d)", sentFolderServerId, sentFolderId);
        MessageStore messageStore = messageStoreManager.getMessageStore(account);
        long destinationMessageId = messageStore.moveMessage(message.getDatabaseId(), sentFolderId);
        Timber.i("Moved sent message to folder '%s' (%d)", sentFolderServerId, sentFolderId);
        if (!sentFolder.isLocalOnly()) {
            String destinationUid = messageStore.getMessageServerId(destinationMessageId);
            PendingCommand command = PendingAppend.create(sentFolderId, destinationUid);
            queuePendingCommand(account, command);
            processPendingCommands(account);
        }
    }
    for (MessagingListener listener : getListeners()) {
        listener.folderStatusChanged(account, account.getOutboxFolderId());
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) MessageStore(com.fsck.k9.mailstore.MessageStore) PendingCommand(com.fsck.k9.controller.MessagingControllerCommands.PendingCommand)

Example 4 with MessageStore

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

the class MessagingController method clearNewMessagesBlocking.

private void clearNewMessagesBlocking(Account account) {
    MessageStore messageStore = messageStoreManager.getMessageStore(account);
    messageStore.clearNewMessageState();
}
Also used : MessageStore(com.fsck.k9.mailstore.MessageStore)

Example 5 with MessageStore

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

the class MessagingController method messagesPendingSend.

private boolean messagesPendingSend(final Account account) {
    Long outboxFolderId = account.getOutboxFolderId();
    if (outboxFolderId == null) {
        Timber.w("Could not get Outbox folder ID from Account");
        return false;
    }
    MessageStore messageStore = messageStoreManager.getMessageStore(account);
    return messageStore.getMessageCount(outboxFolderId) > 0;
}
Also used : MessageStore(com.fsck.k9.mailstore.MessageStore)

Aggregations

MessageStore (com.fsck.k9.mailstore.MessageStore)10 MessagingException (com.fsck.k9.mail.MessagingException)4 LocalFolder (com.fsck.k9.mailstore.LocalFolder)4 LocalStore (com.fsck.k9.mailstore.LocalStore)4 PendingCommand (com.fsck.k9.controller.MessagingControllerCommands.PendingCommand)2 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)2 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)2 LocalMessage (com.fsck.k9.mailstore.LocalMessage)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Backend (com.fsck.k9.backend.api.Backend)1 SyncConfig (com.fsck.k9.backend.api.SyncConfig)1 ExceptionHelper.getRootCauseMessage (com.fsck.k9.helper.ExceptionHelper.getRootCauseMessage)1 Message (com.fsck.k9.mail.Message)1 ServerSettings (com.fsck.k9.mail.ServerSettings)1 FolderDetailsAccessor (com.fsck.k9.mailstore.FolderDetailsAccessor)1 OutboxStateRepository (com.fsck.k9.mailstore.OutboxStateRepository)1 SaveMessageData (com.fsck.k9.mailstore.SaveMessageData)1 LinkedList (java.util.LinkedList)1