use of com.fsck.k9.mail.Multipart in project k-9 by k9mail.
the class MessageTest method sampleMessage.
private MimeMessage sampleMessage() throws MessagingException, IOException {
MimeMessage message = new MimeMessage();
message.setFrom(new Address("from@example.com"));
message.setRecipient(RecipientType.TO, new Address("to@example.com"));
message.setSubject("Test Message");
message.setHeader("Date", "Wed, 28 Aug 2013 08:51:09 -0400");
message.setEncoding(MimeUtil.ENC_7BIT);
MimeMultipart multipartBody = new MimeMultipart("multipart/mixed", generateBoundary());
multipartBody.addBodyPart(textBodyPart());
multipartBody.addBodyPart(binaryBodyPart());
MimeMessageHelper.setBody(message, multipartBody);
return message;
}
use of com.fsck.k9.mail.Multipart 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.Multipart 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