Search in sources :

Example 1 with MessageViewInfo

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

the class MessageViewInfoExtractor method extractMessageForView.

@WorkerThread
public MessageViewInfo extractMessageForView(Message message, @Nullable MessageCryptoAnnotations annotations) throws MessagingException {
    Part rootPart;
    CryptoResultAnnotation cryptoResultAnnotation;
    List<Part> extraParts;
    CryptoMessageParts cryptoMessageParts = MessageCryptoSplitter.split(message, annotations);
    if (cryptoMessageParts != null) {
        rootPart = cryptoMessageParts.contentPart;
        cryptoResultAnnotation = cryptoMessageParts.contentCryptoAnnotation;
        extraParts = cryptoMessageParts.extraParts;
    } else {
        if (annotations != null && !annotations.isEmpty()) {
            Timber.e("Got message annotations but no crypto root part!");
        }
        rootPart = message;
        cryptoResultAnnotation = null;
        extraParts = null;
    }
    List<AttachmentViewInfo> attachmentInfos = new ArrayList<>();
    ViewableExtractedText viewable = extractViewableAndAttachments(Collections.singletonList(rootPart), attachmentInfos);
    List<AttachmentViewInfo> extraAttachmentInfos = new ArrayList<>();
    String extraViewableText = null;
    if (extraParts != null) {
        ViewableExtractedText extraViewable = extractViewableAndAttachments(extraParts, extraAttachmentInfos);
        extraViewableText = extraViewable.text;
    }
    AttachmentResolver attachmentResolver = AttachmentResolver.createFromPart(rootPart);
    boolean isMessageIncomplete = !message.isSet(Flag.X_DOWNLOADED_FULL) || MessageExtractor.hasMissingParts(message);
    return MessageViewInfo.createWithExtractedContent(message, isMessageIncomplete, rootPart, viewable.html, attachmentInfos, cryptoResultAnnotation, attachmentResolver, extraViewableText, extraAttachmentInfos);
}
Also used : CryptoMessageParts(com.fsck.k9.ui.crypto.MessageCryptoSplitter.CryptoMessageParts) Part(com.fsck.k9.mail.Part) ArrayList(java.util.ArrayList) WorkerThread(android.support.annotation.WorkerThread)

Example 2 with MessageViewInfo

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

the class MessageCompose method processMessageToForward.

private void processMessageToForward(MessageViewInfo messageViewInfo) throws MessagingException {
    Message message = messageViewInfo.message;
    String subject = message.getSubject();
    if (subject != null && !subject.toLowerCase(Locale.US).startsWith("fwd:")) {
        subjectView.setText("Fwd: " + subject);
    } else {
        subjectView.setText(subject);
    }
    // even if there are multiple references.
    if (!TextUtils.isEmpty(message.getMessageId())) {
        repliedToMessageId = message.getMessageId();
        referencedMessageIds = repliedToMessageId;
    } else {
        Timber.d("could not get Message-ID.");
    }
    // Quote the message and setup the UI.
    quotedMessagePresenter.processMessageToForward(messageViewInfo);
    attachmentPresenter.processMessageToForward(messageViewInfo);
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message)

Example 3 with MessageViewInfo

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

the class MessageLoaderHelper method onLoadMessageFromDatabaseFinished.

@UiThread
private void onLoadMessageFromDatabaseFinished() {
    if (callback == null) {
        throw new IllegalStateException("unexpected call when callback is already detached");
    }
    callback.onMessageDataLoadFinished(localMessage);
    boolean downloadedCompletely = localMessage.isSet(Flag.X_DOWNLOADED_FULL);
    boolean downloadedPartially = localMessage.isSet(Flag.X_DOWNLOADED_PARTIAL);
    boolean messageIncomplete = !downloadedCompletely && !downloadedPartially;
    if (messageIncomplete) {
        startDownloadingMessageBody(false);
        return;
    }
    if (onlyLoadMetadata) {
        MessageViewInfo messageViewInfo = MessageViewInfo.createForMetadataOnly(localMessage, !downloadedCompletely);
        onDecodeMessageFinished(messageViewInfo);
        return;
    }
    String openPgpProvider = account.getOpenPgpProvider();
    if (openPgpProvider != null) {
        startOrResumeCryptoOperation(openPgpProvider);
        return;
    }
    startOrResumeDecodeMessage();
}
Also used : MessageViewInfo(com.fsck.k9.mailstore.MessageViewInfo) UiThread(androidx.annotation.UiThread)

Example 4 with MessageViewInfo

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

the class MessageCompose method processMessageToForward.

private void processMessageToForward(MessageViewInfo messageViewInfo, boolean asAttachment) throws MessagingException {
    Message message = messageViewInfo.message;
    String subject = messageViewInfo.subject;
    if (subject != null && !subject.toLowerCase(Locale.US).startsWith("fwd:")) {
        subjectView.setText("Fwd: " + subject);
    } else {
        subjectView.setText(subject);
    }
    // even if there are multiple references.
    if (!TextUtils.isEmpty(message.getMessageId())) {
        repliedToMessageId = message.getMessageId();
        referencedMessageIds = repliedToMessageId;
    } else {
        Timber.d("could not get Message-ID.");
    }
    // Quote the message and setup the UI.
    if (asAttachment) {
        attachmentPresenter.processMessageToForwardAsAttachment(messageViewInfo);
    } else {
        quotedMessagePresenter.processMessageToForward(messageViewInfo);
        attachmentPresenter.processMessageToForward(messageViewInfo);
    }
    setIdentityFromMessage(message);
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message)

Example 5 with MessageViewInfo

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

the class MessageCompose method processMessageToReplyTo.

private void processMessageToReplyTo(MessageViewInfo messageViewInfo) throws MessagingException {
    Message message = messageViewInfo.message;
    if (messageViewInfo.subject != null) {
        final String subject = PREFIX.matcher(messageViewInfo.subject).replaceFirst("");
        if (!subject.toLowerCase(Locale.US).startsWith("re:")) {
            subjectView.setText("Re: " + subject);
        } else {
            subjectView.setText(subject);
        }
    } else {
        subjectView.setText("");
    }
    /*
         * If a reply-to was included with the message use that, otherwise use the from
         * or sender address.
         */
    boolean isReplyAll = action == Action.REPLY_ALL;
    recipientPresenter.initFromReplyToMessage(message, isReplyAll);
    if (message.getMessageId() != null && message.getMessageId().length() > 0) {
        repliedToMessageId = message.getMessageId();
        String[] refs = message.getReferences();
        if (refs != null && refs.length > 0) {
            referencedMessageIds = TextUtils.join("", refs) + " " + repliedToMessageId;
        } else {
            referencedMessageIds = repliedToMessageId;
        }
    } else {
        Timber.d("could not get Message-ID.");
    }
    // Quote the message and setup the UI.
    quotedMessagePresenter.initFromReplyToMessage(messageViewInfo, action);
    if (action == Action.REPLY || action == Action.REPLY_ALL) {
        setIdentityFromMessage(message);
    }
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message)

Aggregations

Message (com.fsck.k9.mail.Message)14 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)14 K9RobolectricTest (com.fsck.k9.K9RobolectricTest)10 Test (org.junit.Test)10 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)8 LocalMessage (com.fsck.k9.mailstore.LocalMessage)5 BodyPart (com.fsck.k9.mail.BodyPart)4 Part (com.fsck.k9.mail.Part)4 MessageFormat (com.fsck.k9.Account.MessageFormat)2 MessageReference (com.fsck.k9.controller.MessageReference)2 MessagingException (com.fsck.k9.mail.MessagingException)2 SimpleMessageFormat (com.fsck.k9.message.SimpleMessageFormat)2 ArrayList (java.util.ArrayList)2 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 WorkerThread (android.support.annotation.WorkerThread)1 UiThread (androidx.annotation.UiThread)1 WorkerThread (androidx.annotation.WorkerThread)1 Account (com.fsck.k9.Account)1 ShowPictures (com.fsck.k9.Account.ShowPictures)1