Search in sources :

Example 86 with Part

use of com.fsck.k9.mail.Part in project k-9 by k9mail.

the class MessageCryptoHelper method extractClearsignedTextReplacementPart.

private static MimeBodyPart extractClearsignedTextReplacementPart(Part part) {
    try {
        String clearsignedText = MessageExtractor.getTextFromPart(part);
        String replacementText = OpenPgpUtils.extractClearsignedMessage(clearsignedText);
        if (replacementText == null) {
            Timber.e("failed to extract clearsigned text for replacement part");
            return NO_REPLACEMENT_PART;
        }
        return new MimeBodyPart(new TextBody(replacementText), "text/plain");
    } catch (MessagingException e) {
        Timber.e(e, "failed to create clearsigned text replacement part");
        return NO_REPLACEMENT_PART;
    }
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) MessagingException(com.fsck.k9.mail.MessagingException) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart)

Example 87 with Part

use of com.fsck.k9.mail.Part in project k-9 by k9mail.

the class MessageCryptoHelper method getDataSourceForSignedData.

private OpenPgpDataSource getDataSourceForSignedData(final Part signedPart) throws IOException {
    return new OpenPgpDataSource() {

        @Override
        public void writeTo(OutputStream os) throws IOException {
            try {
                Multipart multipartSignedMultipart = (Multipart) signedPart.getBody();
                BodyPart signatureBodyPart = multipartSignedMultipart.getBodyPart(0);
                Timber.d("signed data type: %s", signatureBodyPart.getMimeType());
                signatureBodyPart.writeTo(os);
            } catch (MessagingException e) {
                Timber.e(e, "Exception while writing message to crypto provider");
            }
        }
    };
}
Also used : MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) BodyPart(com.fsck.k9.mail.BodyPart) Multipart(com.fsck.k9.mail.Multipart) MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) MessagingException(com.fsck.k9.mail.MessagingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) OpenPgpDataSource(org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource)

Example 88 with Part

use of com.fsck.k9.mail.Part in project k-9 by k9mail.

the class MessageCryptoHelper method getMultipartSignedContentPartIfAvailable.

@Nullable
private static MimeBodyPart getMultipartSignedContentPartIfAvailable(Part part) {
    MimeBodyPart replacementPart = NO_REPLACEMENT_PART;
    Body body = part.getBody();
    if (body instanceof MimeMultipart) {
        MimeMultipart multipart = ((MimeMultipart) part.getBody());
        if (multipart.getCount() >= 1) {
            replacementPart = (MimeBodyPart) multipart.getBodyPart(0);
        }
    }
    return replacementPart;
}
Also used : MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) TextBody(com.fsck.k9.mail.internet.TextBody) Body(com.fsck.k9.mail.Body) Nullable(android.support.annotation.Nullable)

Example 89 with Part

use of com.fsck.k9.mail.Part in project k-9 by k9mail.

the class MessageCryptoHelper method addCryptoResultAnnotationToMessage.

private void addCryptoResultAnnotationToMessage(CryptoResultAnnotation resultAnnotation) {
    Part part = currentCryptoPart.part;
    messageAnnotations.put(part, resultAnnotation);
    propagateEncapsulatedSignedPart(resultAnnotation, part);
}
Also used : MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part)

Example 90 with Part

use of com.fsck.k9.mail.Part 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)

Aggregations

Part (com.fsck.k9.mail.Part)113 Test (org.junit.Test)92 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)78 BodyPart (com.fsck.k9.mail.BodyPart)73 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)39 Message (com.fsck.k9.mail.Message)32 MessageCreationHelper.createTextPart (com.fsck.k9.message.MessageCreationHelper.createTextPart)30 Body (com.fsck.k9.mail.Body)29 Multipart (com.fsck.k9.mail.Multipart)27 ArrayList (java.util.ArrayList)27 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)20 MessageCreationHelper.createEmptyPart (com.fsck.k9.message.MessageCreationHelper.createEmptyPart)19 MessagingException (com.fsck.k9.mail.MessagingException)16 MessageCreationHelper.createPart (com.fsck.k9.message.MessageCreationHelper.createPart)16 TextBody (com.fsck.k9.mail.internet.TextBody)14 AttachmentViewInfo (com.fsck.k9.mailstore.AttachmentViewInfo)13 Viewable (com.fsck.k9.mail.internet.Viewable)10 Uri (android.net.Uri)8 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)6 BinaryMemoryBody (com.fsck.k9.mailstore.BinaryMemoryBody)6