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 MessageCryptoHelper method getDataSourceForEncryptedOrInlineData.
private OpenPgpDataSource getDataSourceForEncryptedOrInlineData() throws IOException {
return new OpenPgpApi.OpenPgpDataSource() {
@Override
public Long getSizeForProgress() {
Part part = currentCryptoPart.part;
CryptoPartType cryptoPartType = currentCryptoPart.type;
Body body;
if (cryptoPartType == CryptoPartType.PGP_ENCRYPTED) {
Multipart multipartEncryptedMultipart = (Multipart) part.getBody();
BodyPart encryptionPayloadPart = multipartEncryptedMultipart.getBodyPart(1);
body = encryptionPayloadPart.getBody();
} else if (cryptoPartType == CryptoPartType.PGP_INLINE) {
body = part.getBody();
} else {
throw new IllegalStateException("part to stream must be encrypted or inline!");
}
if (body instanceof SizeAware) {
long bodySize = ((SizeAware) body).getSize();
if (bodySize > PROGRESS_SIZE_THRESHOLD) {
return bodySize;
}
}
return null;
}
@Override
@WorkerThread
public void writeTo(OutputStream os) throws IOException {
try {
Part part = currentCryptoPart.part;
CryptoPartType cryptoPartType = currentCryptoPart.type;
if (cryptoPartType == CryptoPartType.PGP_ENCRYPTED) {
Multipart multipartEncryptedMultipart = (Multipart) part.getBody();
BodyPart encryptionPayloadPart = multipartEncryptedMultipart.getBodyPart(1);
Body encryptionPayloadBody = encryptionPayloadPart.getBody();
encryptionPayloadBody.writeTo(os);
} else if (cryptoPartType == CryptoPartType.PGP_INLINE) {
String text = MessageExtractor.getTextFromPart(part);
os.write(text.getBytes());
} else {
throw new IllegalStateException("part to stream must be encrypted or inline!");
}
} catch (MessagingException e) {
Timber.e(e, "MessagingException while writing message to crypto provider");
}
}
};
}
Aggregations