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