use of com.fsck.k9.mail.Multipart in project k-9 by k9mail.
the class LocalFolder method addChildrenToStack.
private void addChildrenToStack(Stack<PartContainer> stack, Part part, long parentMessageId) {
Body body = part.getBody();
if (body instanceof Multipart) {
Multipart multipart = (Multipart) body;
for (int i = multipart.getCount() - 1; i >= 0; i--) {
BodyPart childPart = multipart.getBodyPart(i);
stack.push(new PartContainer(parentMessageId, childPart));
}
} else if (body instanceof Message) {
Message innerMessage = (Message) body;
stack.push(new PartContainer(parentMessageId, innerMessage));
}
}
use of com.fsck.k9.mail.Multipart in project k-9 by k9mail.
the class TextPartFinder method findFirstTextPart.
@Nullable
public Part findFirstTextPart(@NonNull Part part) {
String mimeType = part.getMimeType();
Body body = part.getBody();
if (body instanceof Multipart) {
Multipart multipart = (Multipart) body;
if (isSameMimeType(mimeType, "multipart/alternative")) {
return findTextPartInMultipartAlternative(multipart);
} else {
return findTextPartInMultipart(multipart);
}
} else if (isSameMimeType(mimeType, "text/plain") || isSameMimeType(mimeType, "text/html")) {
return part;
}
return null;
}
use of com.fsck.k9.mail.Multipart in project k-9 by k9mail.
the class TextPartFinder method findTextPartInMultipart.
private Part findTextPartInMultipart(Multipart multipart) {
for (BodyPart bodyPart : multipart.getBodyParts()) {
String mimeType = bodyPart.getMimeType();
Body body = bodyPart.getBody();
if (body instanceof Multipart) {
Part candidatePart = findFirstTextPart(bodyPart);
if (candidatePart != null) {
return candidatePart;
}
} else if (isSameMimeType(mimeType, "text/plain") || isSameMimeType(mimeType, "text/html")) {
return bodyPart;
}
}
return null;
}
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;
}
Aggregations