Search in sources :

Example 66 with LocalStore

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

the class SqlQueryBuilder method getFolderId.

private static long getFolderId(Account account, String folderName) {
    long folderId = 0;
    try {
        LocalStore localStore = account.getLocalStore();
        LocalFolder folder = localStore.getFolder(folderName);
        folder.open(Folder.OPEN_MODE_RO);
        folderId = folder.getId();
    } catch (MessagingException e) {
        //FIXME
        e.printStackTrace();
    }
    return folderId;
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) MessagingException(com.fsck.k9.mail.MessagingException) LocalStore(com.fsck.k9.mailstore.LocalStore)

Example 67 with LocalStore

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

the class MessagingController method loadMessageMetadata.

public LocalMessage loadMessageMetadata(Account account, long folderId, String uid) throws MessagingException {
    LocalStore localStore = localStoreProvider.getInstance(account);
    LocalFolder localFolder = localStore.getFolder(folderId);
    localFolder.open();
    LocalMessage message = localFolder.getMessage(uid);
    if (message == null || message.getDatabaseId() == 0) {
        String folderName = localFolder.getName();
        throw new IllegalArgumentException("Message not found: folder=" + folderName + ", uid=" + uid);
    }
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.ENVELOPE);
    localFolder.fetch(Collections.singletonList(message), fp, null);
    return message;
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) LocalMessage(com.fsck.k9.mailstore.LocalMessage) FetchProfile(com.fsck.k9.mail.FetchProfile) LocalStore(com.fsck.k9.mailstore.LocalStore)

Example 68 with LocalStore

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

the class MessagingController method deleteDraft.

public void deleteDraft(final Account account, long id) {
    try {
        Long folderId = account.getDraftsFolderId();
        if (folderId == null) {
            Timber.w("No Drafts folder configured. Can't delete draft.");
            return;
        }
        LocalStore localStore = localStoreProvider.getInstance(account);
        LocalFolder localFolder = localStore.getFolder(folderId);
        localFolder.open();
        String uid = localFolder.getMessageUidById(id);
        if (uid != null) {
            MessageReference messageReference = new MessageReference(account.getUuid(), folderId, uid);
            deleteMessage(messageReference);
        }
    } catch (MessagingException me) {
        Timber.e(me, "Error deleting draft");
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) MessagingException(com.fsck.k9.mail.MessagingException) LocalStore(com.fsck.k9.mailstore.LocalStore)

Example 69 with LocalStore

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

the class MessagingController method setFlagSynchronous.

private void setFlagSynchronous(final Account account, final List<Long> ids, final Flag flag, final boolean newState, final boolean threadedList) {
    LocalStore localStore;
    try {
        localStore = localStoreProvider.getInstance(account);
    } catch (MessagingException e) {
        Timber.e(e, "Couldn't get LocalStore instance");
        return;
    }
    // can be updated with the new state.
    try {
        if (threadedList) {
            localStore.setFlagForThreads(ids, flag, newState);
            removeFlagForThreadsFromCache(account, ids, flag);
        } else {
            localStore.setFlag(ids, flag, newState);
            removeFlagFromCache(account, ids, flag);
        }
    } catch (MessagingException e) {
        Timber.e(e, "Couldn't set flags in local database");
    }
    // Read folder ID and UID of messages from the database
    Map<Long, List<String>> folderMap;
    try {
        folderMap = localStore.getFolderIdsAndUids(ids, threadedList);
    } catch (MessagingException e) {
        Timber.e(e, "Couldn't get folder name and UID of messages");
        return;
    }
    boolean accountSupportsFlags = supportsFlags(account);
    // Loop over all folders
    for (Entry<Long, List<String>> entry : folderMap.entrySet()) {
        long folderId = entry.getKey();
        List<String> uids = entry.getValue();
        // Notify listeners of changed folder status
        for (MessagingListener l : getListeners()) {
            l.folderStatusChanged(account, folderId);
        }
        if (flag == Flag.SEEN && newState) {
            cancelNotificationsForMessages(account, folderId, uids);
        }
        if (accountSupportsFlags) {
            LocalFolder localFolder = localStore.getFolder(folderId);
            try {
                localFolder.open();
                if (!localFolder.isLocalOnly()) {
                    // Send flag change to server
                    queueSetFlag(account, folderId, newState, flag, uids);
                    processPendingCommands(account);
                }
            } catch (MessagingException e) {
                Timber.e(e, "Couldn't open folder. Account: %s, folder ID: %d", account, folderId);
            }
        }
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) MessagingException(com.fsck.k9.mail.MessagingException) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) LocalStore(com.fsck.k9.mailstore.LocalStore)

Example 70 with LocalStore

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

the class MessagingController method getFolderUnreadMessageCount.

public int getFolderUnreadMessageCount(Account account, Long folderId) throws MessagingException {
    LocalStore localStore = localStoreProvider.getInstance(account);
    LocalFolder localFolder = localStore.getFolder(folderId);
    return localFolder.getUnreadMessageCount();
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) LocalStore(com.fsck.k9.mailstore.LocalStore)

Aggregations

LocalStore (com.fsck.k9.mailstore.LocalStore)63 LocalFolder (com.fsck.k9.mailstore.LocalFolder)53 MessagingException (com.fsck.k9.mail.MessagingException)46 LocalMessage (com.fsck.k9.mailstore.LocalMessage)27 FetchProfile (com.fsck.k9.mail.FetchProfile)17 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)16 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)16 Store (com.fsck.k9.mail.Store)16 Folder (com.fsck.k9.mail.Folder)15 Pop3Store (com.fsck.k9.mail.store.pop3.Pop3Store)15 Account (com.fsck.k9.Account)13 Message (com.fsck.k9.mail.Message)13 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)13 ArrayList (java.util.ArrayList)13 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)10 Test (org.junit.Test)10 Backend (com.fsck.k9.backend.api.Backend)9 IOException (java.io.IOException)9 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)8 SuppressLint (android.annotation.SuppressLint)7