use of com.fsck.k9.mail.Multipart in project k-9 by k9mail.
the class MessageDecryptVerifier method getSignatureData.
public static byte[] getSignatureData(Part part) throws IOException, MessagingException {
if (isPartMultipartSigned(part)) {
Body body = part.getBody();
if (body instanceof Multipart) {
Multipart multi = (Multipart) body;
BodyPart signatureBody = multi.getBodyPart(1);
if (isSameMimeType(signatureBody.getMimeType(), APPLICATION_PGP_SIGNATURE)) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
signatureBody.getBody().writeTo(bos);
return bos.toByteArray();
}
}
}
return null;
}
use of com.fsck.k9.mail.Multipart in project k-9 by k9mail.
the class MessageDecryptVerifier method findPgpInlineParts.
public static List<Part> findPgpInlineParts(Part startPart) {
List<Part> inlineParts = new ArrayList<>();
Stack<Part> partsToCheck = new Stack<>();
partsToCheck.push(startPart);
while (!partsToCheck.isEmpty()) {
Part part = partsToCheck.pop();
Body body = part.getBody();
if (isPartPgpInlineEncryptedOrSigned(part)) {
inlineParts.add(part);
continue;
}
if (body instanceof Multipart) {
Multipart multipart = (Multipart) body;
for (int i = multipart.getCount() - 1; i >= 0; i--) {
BodyPart bodyPart = multipart.getBodyPart(i);
partsToCheck.push(bodyPart);
}
}
}
return inlineParts;
}
use of com.fsck.k9.mail.Multipart in project k-9 by k9mail.
the class MessageDecryptVerifier method findPrimaryPartInAlternative.
private static Part findPrimaryPartInAlternative(Part part) {
Body body = part.getBody();
if (part.isMimeType("multipart/alternative") && body instanceof Multipart) {
Multipart multipart = (Multipart) body;
if (multipart.getCount() == 0) {
return null;
}
BodyPart firstBodyPart = multipart.getBodyPart(0);
if (isPartPgpInlineEncryptedOrSigned(firstBodyPart)) {
return firstBodyPart;
}
}
return null;
}
use of com.fsck.k9.mail.Multipart in project k-9 by k9mail.
the class AttachmentResolver method buildCidToAttachmentUriMap.
@VisibleForTesting
static Map<String, Uri> buildCidToAttachmentUriMap(AttachmentInfoExtractor attachmentInfoExtractor, Part rootPart) {
HashMap<String, Uri> result = new HashMap<>();
Stack<Part> partsToCheck = new Stack<>();
partsToCheck.push(rootPart);
while (!partsToCheck.isEmpty()) {
Part part = partsToCheck.pop();
Body body = part.getBody();
if (body instanceof Multipart) {
Multipart multipart = (Multipart) body;
for (Part bodyPart : multipart.getBodyParts()) {
partsToCheck.push(bodyPart);
}
} else {
try {
String contentId = part.getContentId();
if (contentId != null) {
AttachmentViewInfo attachmentInfo = attachmentInfoExtractor.extractAttachmentInfo(part);
result.put(contentId, attachmentInfo.internalUri);
}
} catch (MessagingException e) {
Timber.e(e, "Error extracting attachment info");
}
}
}
return Collections.unmodifiableMap(result);
}
use of com.fsck.k9.mail.Multipart in project k-9 by k9mail.
the class MessageDecryptVerifierTest method findEncrypted__withMultipartMixedSubEncryptedAndText__shouldReturnEncrypted.
@Test
public void findEncrypted__withMultipartMixedSubEncryptedAndText__shouldReturnEncrypted() throws Exception {
Message message = messageFromBody(multipart("mixed", multipart("encrypted", bodypart("application/pgp-encrypted"), bodypart("application/octet-stream")), bodypart("text/plain")));
List<Part> encryptedParts = MessageDecryptVerifier.findEncryptedParts(message);
assertEquals(1, encryptedParts.size());
assertSame(getPart(message, 0), encryptedParts.get(0));
}
Aggregations