Search in sources :

Example 21 with MessageViewInfo

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

the class MessageViewInfoExtractorTest method extractMessage_openPgpEncrypted_withProtectedSubject.

@Test
public void extractMessage_openPgpEncrypted_withProtectedSubject() throws Exception {
    MimeBodyPart encryptedPayload = bodypart("text/plain", "encrypted text");
    Message message = messageFromBody(multipart("encrypted", "protocol=\"application/pgp-encrypted\"", bodypart("application/pgp-encrypted"), bodypart("application/octet-stream")));
    encryptedPayload.setHeader("Content-Type", encryptedPayload.getHeader("Content-Type")[0] + "; protected-headers=v1");
    encryptedPayload.setHeader("Subject", PROTECTED_SUBJECT);
    MessageCryptoAnnotations cryptoAnnotations = new MessageCryptoAnnotations();
    OpenPgpDecryptionResult decryptionResult = new OpenPgpDecryptionResult(OpenPgpDecryptionResult.RESULT_ENCRYPTED);
    CryptoResultAnnotation openPgpResultAnnotation = CryptoResultAnnotation.createOpenPgpResultAnnotation(decryptionResult, null, null, null, encryptedPayload, false);
    cryptoAnnotations.put(message, openPgpResultAnnotation);
    MessageViewInfo messageViewInfo = messageViewInfoExtractor.extractMessageForView(message, cryptoAnnotations, true);
    assertSame(openPgpResultAnnotation, messageViewInfo.cryptoResultAnnotation);
    assertEquals("<pre dir=\"auto\" class=\"k9mail\">encrypted text</pre>", messageViewInfo.text);
    assertEquals(PROTECTED_SUBJECT, messageViewInfo.subject);
    assertTrue(messageViewInfo.attachments.isEmpty());
    assertTrue(messageViewInfo.extraAttachments.isEmpty());
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) OpenPgpDecryptionResult(org.openintents.openpgp.OpenPgpDecryptionResult) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) K9RobolectricTest(com.fsck.k9.K9RobolectricTest) Test(org.junit.Test)

Example 22 with MessageViewInfo

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

the class MessageCompose method processDraftMessage.

private void processDraftMessage(MessageViewInfo messageViewInfo) {
    Message message = messageViewInfo.message;
    draftMessageId = messagingController.getId(message);
    subjectView.setText(messageViewInfo.subject);
    replyToPresenter.initFromDraftMessage(message);
    recipientPresenter.initFromDraftMessage(message);
    // Read In-Reply-To header from draft
    final String[] inReplyTo = message.getHeader("In-Reply-To");
    if (inReplyTo.length >= 1) {
        repliedToMessageId = inReplyTo[0];
    }
    // Read References header from draft
    final String[] references = message.getHeader("References");
    if (references.length >= 1) {
        referencedMessageIds = references[0];
    }
    if (!relatedMessageProcessed) {
        attachmentPresenter.loadAllAvailableAttachments(messageViewInfo);
    }
    // Decode the identity header when loading a draft.
    // See buildIdentityHeader(TextBody) for a detailed description of the composition of this blob.
    Map<IdentityField, String> k9identity = new HashMap<>();
    String[] identityHeaders = message.getHeader(K9.IDENTITY_HEADER);
    if (identityHeaders.length == 0) {
        identityHeaders = messageViewInfo.rootPart.getHeader(K9.IDENTITY_HEADER);
    }
    if (identityHeaders.length > 0 && identityHeaders[0] != null) {
        k9identity = IdentityHeaderParser.parse(identityHeaders[0]);
    }
    Identity newIdentity = new Identity();
    if (k9identity.containsKey(IdentityField.SIGNATURE)) {
        newIdentity = newIdentity.withSignatureUse(true).withSignature(k9identity.get(IdentityField.SIGNATURE));
        signatureChanged = true;
    } else {
        if (message instanceof LocalMessage) {
            newIdentity = newIdentity.withSignatureUse(((LocalMessage) message).getFolder().getSignatureUse());
        }
        newIdentity = newIdentity.withSignature(identity.getSignature());
    }
    if (k9identity.containsKey(IdentityField.NAME)) {
        newIdentity = newIdentity.withName(k9identity.get(IdentityField.NAME));
        identityChanged = true;
    } else {
        newIdentity = newIdentity.withName(identity.getName());
    }
    if (k9identity.containsKey(IdentityField.EMAIL)) {
        newIdentity = newIdentity.withEmail(k9identity.get(IdentityField.EMAIL));
        identityChanged = true;
    } else {
        newIdentity = newIdentity.withEmail(identity.getEmail());
    }
    if (k9identity.containsKey(IdentityField.ORIGINAL_MESSAGE)) {
        relatedMessageReference = null;
        String originalMessage = k9identity.get(IdentityField.ORIGINAL_MESSAGE);
        MessageReference messageReference = MessageReference.parse(originalMessage);
        if (messageReference != null) {
            // Check if this is a valid account in our database
            Account account = preferences.getAccount(messageReference.getAccountUuid());
            if (account != null) {
                relatedMessageReference = messageReference;
            }
        }
    }
    identity = newIdentity;
    updateSignature();
    updateFrom();
    replyToPresenter.setIdentity(identity);
    quotedMessagePresenter.processDraftMessage(messageViewInfo, k9identity);
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) Account(com.fsck.k9.Account) LocalMessage(com.fsck.k9.mailstore.LocalMessage) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) HashMap(java.util.HashMap) Identity(com.fsck.k9.Identity) MessageReference(com.fsck.k9.controller.MessageReference) IdentityField(com.fsck.k9.message.IdentityField)

Example 23 with MessageViewInfo

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

the class MessageLoaderHelper method startOrResumeDecodeMessage.

// decode message
private void startOrResumeDecodeMessage() {
    LocalMessageExtractorLoader loader = (LocalMessageExtractorLoader) loaderManager.<MessageViewInfo>getLoader(DECODE_MESSAGE_LOADER_ID);
    boolean isLoaderStale = (loader == null) || !loader.isCreatedFor(localMessage, messageCryptoAnnotations);
    if (isLoaderStale) {
        Timber.d("Creating new decode message loader");
        loaderManager.restartLoader(DECODE_MESSAGE_LOADER_ID, null, decodeMessageLoaderCallback);
    } else {
        Timber.d("Reusing decode message loader");
        loaderManager.initLoader(DECODE_MESSAGE_LOADER_ID, null, decodeMessageLoaderCallback);
    }
}
Also used : LocalMessageExtractorLoader(com.fsck.k9.ui.message.LocalMessageExtractorLoader)

Example 24 with MessageViewInfo

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

the class AttachmentPresenter method processMessageToForwardAsAttachment.

public void processMessageToForwardAsAttachment(MessageViewInfo messageViewInfo) throws MessagingException {
    if (messageViewInfo.isMessageIncomplete) {
        attachmentMvpView.showMissingAttachmentsPartialMessageForwardWarning();
    } else {
        LocalMessage localMessage = (LocalMessage) messageViewInfo.message;
        MessageReference messageReference = localMessage.makeMessageReference();
        Uri rawMessageUri = RawMessageProvider.getRawMessageUri(messageReference);
        addInternalAttachment(rawMessageUri, "message/rfc822", true);
    }
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MessageReference(com.fsck.k9.controller.MessageReference) Uri(android.net.Uri)

Example 25 with MessageViewInfo

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

the class MessageContainerView method renderAttachments.

public void renderAttachments(MessageViewInfo messageViewInfo) {
    if (messageViewInfo.attachments != null) {
        for (AttachmentViewInfo attachment : messageViewInfo.attachments) {
            attachments.put(attachment.internalUri, attachment);
            if (attachment.inlineAttachment) {
                continue;
            }
            AttachmentView view = (AttachmentView) mInflater.inflate(R.layout.message_view_attachment, mAttachments, false);
            view.setCallback(attachmentCallback);
            view.setAttachment(attachment);
            attachmentViewMap.put(attachment, view);
            mAttachments.addView(view);
        }
    }
    if (messageViewInfo.extraAttachments != null) {
        for (AttachmentViewInfo attachment : messageViewInfo.extraAttachments) {
            attachments.put(attachment.internalUri, attachment);
            if (attachment.inlineAttachment) {
                continue;
            }
            LockedAttachmentView view = (LockedAttachmentView) mInflater.inflate(R.layout.message_view_attachment_locked, mAttachments, false);
            view.setCallback(attachmentCallback);
            view.setAttachment(attachment);
            // attachments.put(attachment, view);
            mAttachments.addView(view);
        }
    }
}
Also used : AttachmentViewInfo(com.fsck.k9.mailstore.AttachmentViewInfo)

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