use of com.fsck.k9.mail.BodyPart in project k-9 by k9mail.
the class MessageTest method binaryBodyPart.
private MimeBodyPart binaryBodyPart() throws IOException, MessagingException {
String encodedTestString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz0123456789+/\r\n";
BinaryTempFileBody tempFileBody = new BinaryTempFileBody(MimeUtil.ENC_BASE64);
InputStream in = new ByteArrayInputStream(encodedTestString.getBytes("UTF-8"));
OutputStream out = tempFileBody.getOutputStream();
try {
IOUtils.copy(in, out);
} finally {
out.close();
}
MimeBodyPart bodyPart = new MimeBodyPart(tempFileBody, "application/octet-stream");
bodyPart.setEncoding(MimeUtil.ENC_BASE64);
return bodyPart;
}
use of com.fsck.k9.mail.BodyPart in project k-9 by k9mail.
the class MessageTest method textBodyPart.
private MimeBodyPart textBodyPart() throws MessagingException {
TextBody textBody = new TextBody("Testing.\r\n" + "This is a text body with some greek characters.\r\n" + "αβγδεζηθ\r\n" + "End of test.\r\n");
textBody.setCharset("utf-8");
MimeBodyPart bodyPart = new MimeBodyPart();
MimeMessageHelper.setBody(bodyPart, textBody);
CharsetSupport.setCharset("utf-8", bodyPart);
return bodyPart;
}
use of com.fsck.k9.mail.BodyPart in project k-9 by k9mail.
the class MessageTest method nestedMessage.
private MimeMessage nestedMessage(MimeMessage subMessage) throws MessagingException, IOException {
BinaryTempFileMessageBody tempMessageBody = new BinaryTempFileMessageBody(MimeUtil.ENC_8BIT);
OutputStream out = tempMessageBody.getOutputStream();
try {
subMessage.writeTo(out);
} finally {
out.close();
}
MimeBodyPart bodyPart = new MimeBodyPart(tempMessageBody, "message/rfc822");
bodyPart.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "attachment");
bodyPart.setEncoding(MimeUtil.ENC_7BIT);
MimeMessage parentMessage = sampleMessage();
((Multipart) parentMessage.getBody()).addBodyPart(bodyPart);
return parentMessage;
}
use of com.fsck.k9.mail.BodyPart in project k-9 by k9mail.
the class MessageCryptoStructureDetector method findPrimaryPartInMixed.
@Nullable
private static Part findPrimaryPartInMixed(Part part, List<Part> outputExtraParts) {
Body body = part.getBody();
boolean isMultipartMixed = part.isMimeType("multipart/mixed") && body instanceof Multipart;
if (!isMultipartMixed) {
return null;
}
Multipart multipart = (Multipart) body;
if (multipart.getCount() == 0) {
return null;
}
BodyPart firstBodyPart = multipart.getBodyPart(0);
Part foundPart;
if (isPartEncryptedOrSigned(firstBodyPart)) {
foundPart = firstBodyPart;
} else {
foundPart = findPrimaryPartInAlternative(firstBodyPart);
}
if (foundPart != null && outputExtraParts != null) {
for (int i = 1; i < multipart.getCount(); i++) {
outputExtraParts.add(multipart.getBodyPart(i));
}
}
return foundPart;
}
use of com.fsck.k9.mail.BodyPart in project k-9 by k9mail.
the class MessageCryptoStructureDetector method findMultipartEncryptedParts.
public static List<Part> findMultipartEncryptedParts(Part startPart) {
List<Part> encryptedParts = new ArrayList<>();
Stack<Part> partsToCheck = new Stack<>();
partsToCheck.push(startPart);
while (!partsToCheck.isEmpty()) {
Part part = partsToCheck.pop();
Body body = part.getBody();
if (isPartMultipartEncrypted(part)) {
encryptedParts.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 encryptedParts;
}
Aggregations