Search in sources :

Example 1 with SaveMessageData

use of com.fsck.k9.mailstore.SaveMessageData 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(Account account, Message message, String plaintextSubject, MessagingListener listener) {
    try {
        Long outboxFolderId = account.getOutboxFolderId();
        if (outboxFolderId == null) {
            if (BuildConfig.DEBUG) {
                throw new AssertionError("Outbox does not exist");
            }
            Timber.w("Outbox does not exist");
            outboxFolderId = specialLocalFoldersCreator.createOutbox(account);
        }
        message.setFlag(Flag.SEEN, true);
        MessageStore messageStore = messageStoreManager.getMessageStore(account);
        SaveMessageData messageData = saveMessageDataCreator.createSaveMessageData(message, MessageDownloadState.FULL, plaintextSubject);
        long messageId = messageStore.saveLocalMessage(outboxFolderId, messageData, null);
        LocalStore localStore = localStoreProvider.getInstance(account);
        OutboxStateRepository outboxStateRepository = localStore.getOutboxStateRepository();
        outboxStateRepository.initializeOutboxState(messageId);
        sendPendingMessages(account, listener);
    } catch (Exception e) {
        Timber.e(e, "Error sending message");
    }
}
Also used : MessageStore(com.fsck.k9.mailstore.MessageStore) OutboxStateRepository(com.fsck.k9.mailstore.OutboxStateRepository) SaveMessageData(com.fsck.k9.mailstore.SaveMessageData) LocalStore(com.fsck.k9.mailstore.LocalStore) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) MessagingException(com.fsck.k9.mail.MessagingException) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException)

Aggregations

AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)1 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)1 MessagingException (com.fsck.k9.mail.MessagingException)1 LocalStore (com.fsck.k9.mailstore.LocalStore)1 MessageStore (com.fsck.k9.mailstore.MessageStore)1 OutboxStateRepository (com.fsck.k9.mailstore.OutboxStateRepository)1 SaveMessageData (com.fsck.k9.mailstore.SaveMessageData)1