Search in sources :

Example 56 with Account

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

the class MessagingController method queueMoveOrCopy.

private void queueMoveOrCopy(Account account, String srcFolder, String destFolder, boolean isCopy, List<String> uids, Map<String, String> uidMap) {
    if (uidMap == null || uidMap.isEmpty()) {
        queueMoveOrCopy(account, srcFolder, destFolder, isCopy, uids);
    } else {
        if (account.getErrorFolderName().equals(srcFolder)) {
            return;
        }
        PendingCommand command = PendingMoveOrCopy.create(srcFolder, destFolder, isCopy, uidMap);
        queuePendingCommand(account, command);
    }
}
Also used : PendingCommand(com.fsck.k9.controller.MessagingControllerCommands.PendingCommand)

Example 57 with Account

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

the class MessagingController method notifyUserIfCertificateProblem.

public void notifyUserIfCertificateProblem(Account account, Exception exception, boolean incoming) {
    if (!(exception instanceof CertificateValidationException)) {
        return;
    }
    CertificateValidationException cve = (CertificateValidationException) exception;
    if (!cve.needsUserAttention()) {
        return;
    }
    notificationController.showCertificateErrorNotification(account, incoming);
}
Also used : CertificateValidationException(com.fsck.k9.mail.CertificateValidationException)

Example 58 with Account

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

the class MessagingController method listFoldersSynchronous.

/**
     * Lists folders that are available locally and remotely. This method calls
     * listFoldersCallback for local folders before it returns, and then for
     * remote folders at some later point. If there are no local folders
     * includeRemote is forced by this method. This method is called in the
     * foreground.
     * TODO this needs to cache the remote folder list
     */
public void listFoldersSynchronous(final Account account, final boolean refreshRemote, final MessagingListener listener) {
    for (MessagingListener l : getListeners(listener)) {
        l.listFoldersStarted(account);
    }
    List<LocalFolder> localFolders = null;
    if (!account.isAvailable(context)) {
        Timber.i("not listing folders of unavailable account");
    } else {
        try {
            LocalStore localStore = account.getLocalStore();
            localFolders = localStore.getPersonalNamespaces(false);
            if (refreshRemote || localFolders.isEmpty()) {
                doRefreshRemote(account, listener);
                return;
            }
            for (MessagingListener l : getListeners(listener)) {
                l.listFolders(account, localFolders);
            }
        } catch (Exception e) {
            for (MessagingListener l : getListeners(listener)) {
                l.listFoldersFailed(account, e.getMessage());
            }
            addErrorMessage(account, null, e);
            return;
        } finally {
            if (localFolders != null) {
                for (Folder localFolder : localFolders) {
                    closeFolder(localFolder);
                }
            }
        }
    }
    for (MessagingListener l : getListeners(listener)) {
        l.listFoldersFinished(account);
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) LocalStore(com.fsck.k9.mailstore.LocalStore) Folder(com.fsck.k9.mail.Folder) LocalFolder(com.fsck.k9.mailstore.LocalFolder) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) UnavailableStorageException(com.fsck.k9.mailstore.UnavailableStorageException) IOException(java.io.IOException) MessagingException(com.fsck.k9.mail.MessagingException) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException)

Example 59 with Account

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

the class MessagingController method refreshRemoteSynchronous.

@VisibleForTesting
void refreshRemoteSynchronous(final Account account, final MessagingListener listener) {
    List<LocalFolder> localFolders = null;
    try {
        Store store = account.getRemoteStore();
        List<? extends Folder> remoteFolders = store.getPersonalNamespaces(false);
        LocalStore localStore = account.getLocalStore();
        Set<String> remoteFolderNames = new HashSet<>();
        List<LocalFolder> foldersToCreate = new LinkedList<>();
        localFolders = localStore.getPersonalNamespaces(false);
        Set<String> localFolderNames = new HashSet<>();
        for (Folder localFolder : localFolders) {
            localFolderNames.add(localFolder.getName());
        }
        for (Folder remoteFolder : remoteFolders) {
            if (!localFolderNames.contains(remoteFolder.getName())) {
                LocalFolder localFolder = localStore.getFolder(remoteFolder.getName());
                foldersToCreate.add(localFolder);
            }
            remoteFolderNames.add(remoteFolder.getName());
        }
        localStore.createFolders(foldersToCreate, account.getDisplayCount());
        localFolders = localStore.getPersonalNamespaces(false);
        /*
             * Clear out any folders that are no longer on the remote store.
             */
        for (Folder localFolder : localFolders) {
            String localFolderName = localFolder.getName();
            //        special placeholder folder "-NONE-".
            if (K9.FOLDER_NONE.equals(localFolderName)) {
                localFolder.delete(false);
            }
            if (!account.isSpecialFolder(localFolderName) && !remoteFolderNames.contains(localFolderName)) {
                localFolder.delete(false);
            }
        }
        localFolders = localStore.getPersonalNamespaces(false);
        for (MessagingListener l : getListeners(listener)) {
            l.listFolders(account, localFolders);
        }
        for (MessagingListener l : getListeners(listener)) {
            l.listFoldersFinished(account);
        }
    } catch (Exception e) {
        for (MessagingListener l : getListeners(listener)) {
            l.listFoldersFailed(account, "");
        }
        addErrorMessage(account, null, e);
    } finally {
        if (localFolders != null) {
            for (Folder localFolder : localFolders) {
                closeFolder(localFolder);
            }
        }
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) LocalStore(com.fsck.k9.mailstore.LocalStore) Store(com.fsck.k9.mail.Store) Pop3Store(com.fsck.k9.mail.store.pop3.Pop3Store) LocalStore(com.fsck.k9.mailstore.LocalStore) Folder(com.fsck.k9.mail.Folder) LocalFolder(com.fsck.k9.mailstore.LocalFolder) LinkedList(java.util.LinkedList) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) UnavailableStorageException(com.fsck.k9.mailstore.UnavailableStorageException) IOException(java.io.IOException) MessagingException(com.fsck.k9.mail.MessagingException) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException) HashSet(java.util.HashSet) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 60 with Account

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

the class MessagingController method removeFlagFromCache.

private void removeFlagFromCache(final Account account, final List<Long> messageIds, final Flag flag) {
    EmailProviderCache cache = EmailProviderCache.getCache(account.getUuid(), context);
    String columnName = LocalStore.getColumnNameForFlag(flag);
    cache.removeValueForMessages(messageIds, columnName);
}
Also used : EmailProviderCache(com.fsck.k9.cache.EmailProviderCache)

Aggregations

Account (com.fsck.k9.Account)122 Test (org.junit.Test)81 MessagingException (com.fsck.k9.mail.MessagingException)53 LocalFolder (com.fsck.k9.mailstore.LocalFolder)44 LocalMessage (com.fsck.k9.mailstore.LocalMessage)43 LocalStore (com.fsck.k9.mailstore.LocalStore)42 ArrayList (java.util.ArrayList)34 MessageReference (com.fsck.k9.activity.MessageReference)32 Message (com.fsck.k9.mail.Message)29 Folder (com.fsck.k9.mail.Folder)27 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)25 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)22 IOException (java.io.IOException)22 Cursor (android.database.Cursor)21 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)20 Store (com.fsck.k9.mail.Store)20 SearchAccount (com.fsck.k9.search.SearchAccount)20 PendingIntent (android.app.PendingIntent)19 Pop3Store (com.fsck.k9.mail.store.pop3.Pop3Store)19 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)18