Search in sources :

Example 1 with CryptoMessageParts

use of com.fsck.k9.ui.crypto.MessageCryptoSplitter.CryptoMessageParts in project k-9 by k9mail.

the class MessageCryptoSplitter method split.

@Nullable
public static CryptoMessageParts split(@NonNull Message message, @Nullable MessageCryptoAnnotations annotations) {
    ArrayList<Part> extraParts = new ArrayList<>();
    Part primaryPart = MessageDecryptVerifier.findPrimaryEncryptedOrSignedPart(message, extraParts);
    if (primaryPart == null) {
        return null;
    }
    if (annotations == null) {
        CryptoResultAnnotation rootPartAnnotation = CryptoResultAnnotation.createErrorAnnotation(CryptoError.OPENPGP_ENCRYPTED_NO_PROVIDER, null);
        return new CryptoMessageParts(primaryPart, rootPartAnnotation, extraParts);
    }
    CryptoResultAnnotation rootPartAnnotation = annotations.get(primaryPart);
    Part rootPart;
    if (rootPartAnnotation != null && rootPartAnnotation.hasReplacementData()) {
        rootPart = rootPartAnnotation.getReplacementData();
    } else {
        rootPart = primaryPart;
    }
    return new CryptoMessageParts(rootPart, rootPartAnnotation, extraParts);
}
Also used : Part(com.fsck.k9.mail.Part) CryptoResultAnnotation(com.fsck.k9.mailstore.CryptoResultAnnotation) ArrayList(java.util.ArrayList) Nullable(android.support.annotation.Nullable)

Example 2 with CryptoMessageParts

use of com.fsck.k9.ui.crypto.MessageCryptoSplitter.CryptoMessageParts 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)

Aggregations

Part (com.fsck.k9.mail.Part)2 ArrayList (java.util.ArrayList)2 Nullable (android.support.annotation.Nullable)1 WorkerThread (android.support.annotation.WorkerThread)1 CryptoResultAnnotation (com.fsck.k9.mailstore.CryptoResultAnnotation)1 CryptoMessageParts (com.fsck.k9.ui.crypto.MessageCryptoSplitter.CryptoMessageParts)1