Search in sources :

Example 16 with Account

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

the class MessagingController method sendMessage.

/**
     * Stores the given message in the Outbox and starts a sendPendingMessages command to
     * attempt to send the message.
     */
public void sendMessage(final Account account, final Message message, MessagingListener listener) {
    try {
        LocalStore localStore = account.getLocalStore();
        LocalFolder localFolder = localStore.getFolder(account.getOutboxFolderName());
        localFolder.open(Folder.OPEN_MODE_RW);
        localFolder.appendMessages(Collections.singletonList(message));
        Message localMessage = localFolder.getMessage(message.getUid());
        localMessage.setFlag(Flag.X_DOWNLOADED_FULL, true);
        localFolder.close();
        sendPendingMessages(account, listener);
    } catch (Exception e) {
        /*
            for (MessagingListener l : getListeners())
            {
                // TODO general failed
            }
            */
        addErrorMessage(account, null, e);
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) LocalStore(com.fsck.k9.mailstore.LocalStore) 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 17 with Account

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

the class MessagingController method actOnMessageGroup.

private void actOnMessageGroup(Account account, String folderName, List<MessageReference> messageReferences, MessageActor actor) {
    try {
        LocalFolder messageFolder = account.getLocalStore().getFolder(folderName);
        List<LocalMessage> localMessages = messageFolder.getMessagesByReference(messageReferences);
        actor.act(account, messageFolder, localMessages);
    } catch (MessagingException e) {
        Timber.e(e, "Error loading account?!");
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) LocalMessage(com.fsck.k9.mailstore.LocalMessage) MessagingException(com.fsck.k9.mail.MessagingException)

Example 18 with Account

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

the class MessagingController method loadMessage.

public LocalMessage loadMessage(Account account, String folderName, String uid) throws MessagingException {
    LocalStore localStore = account.getLocalStore();
    LocalFolder localFolder = localStore.getFolder(folderName);
    localFolder.open(Folder.OPEN_MODE_RW);
    LocalMessage message = localFolder.getMessage(uid);
    if (message == null || message.getId() == 0) {
        throw new IllegalArgumentException("Message not found: folder=" + folderName + ", uid=" + uid);
    }
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.BODY);
    localFolder.fetch(Collections.singletonList(message), fp, null);
    localFolder.close();
    notificationController.removeNewMailNotification(account, message.makeMessageReference());
    markMessageAsReadOnView(account, message);
    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 19 with Account

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

the class MessagingController method loadMoreMessages.

public void loadMoreMessages(Account account, String folder, MessagingListener listener) {
    try {
        LocalStore localStore = account.getLocalStore();
        LocalFolder localFolder = localStore.getFolder(folder);
        if (localFolder.getVisibleLimit() > 0) {
            localFolder.setVisibleLimit(localFolder.getVisibleLimit() + account.getDisplayCount());
        }
        synchronizeMailbox(account, folder, listener, null);
    } catch (MessagingException me) {
        addErrorMessage(account, null, me);
        throw new RuntimeException("Unable to set visible limit on folder", me);
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) MessagingException(com.fsck.k9.mail.MessagingException) LocalStore(com.fsck.k9.mailstore.LocalStore)

Example 20 with Account

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

the class MessagingController method processPendingExpunge.

void processPendingExpunge(PendingExpunge command, Account account) throws MessagingException {
    String folder = command.folder;
    if (account.getErrorFolderName().equals(folder)) {
        return;
    }
    Timber.d("processPendingExpunge: folder = %s", folder);
    Store remoteStore = account.getRemoteStore();
    Folder remoteFolder = remoteStore.getFolder(folder);
    try {
        if (!remoteFolder.exists()) {
            return;
        }
        remoteFolder.open(Folder.OPEN_MODE_RW);
        if (remoteFolder.getMode() != Folder.OPEN_MODE_RW) {
            return;
        }
        remoteFolder.expunge();
        Timber.d("processPendingExpunge: complete for folder = %s", folder);
    } finally {
        closeFolder(remoteFolder);
    }
}
Also used : LocalStore(com.fsck.k9.mailstore.LocalStore) Store(com.fsck.k9.mail.Store) Pop3Store(com.fsck.k9.mail.store.pop3.Pop3Store) Folder(com.fsck.k9.mail.Folder) LocalFolder(com.fsck.k9.mailstore.LocalFolder)

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