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());
}
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);
}
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);
}
}
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);
}
}
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);
}
}
}
Aggregations