use of com.fsck.k9.mail.Body in project k-9 by k9mail.
the class ImapFolderTest method buildImapFetchResponse.
private ImapResponse buildImapFetchResponse(ImapResponseCallback callback) {
ImapResponse response = ImapResponse.newContinuationRequest(callback);
response.add("1");
response.add("FETCH");
ImapList fetchList = new ImapList();
fetchList.add("UID");
fetchList.add("1");
fetchList.add("BODY");
fetchList.add("1.1");
fetchList.add("text");
response.add(fetchList);
return response;
}
use of com.fsck.k9.mail.Body 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.Body in project k-9 by k9mail.
the class ReconstructMessageFromDatabaseTest method testAddMissingPart.
public void testAddMissingPart() throws MessagingException, IOException {
LocalFolder folder = createFolderInDatabase();
MimeMessage message = new MimeMessage();
message.addHeader("To", "to@example.com");
message.addHeader("MIME-Version", "1.0");
message.addHeader("Content-Type", "text/plain");
message.setServerExtra("text");
saveMessageToDatabase(folder, message);
LocalMessage localMessage = readMessageFromDatabase(folder, message);
assertEquals("to@example.com", localMessage.getHeader("To")[0]);
assertEquals("text/plain", localMessage.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0]);
assertEquals("text", localMessage.getServerExtra());
assertNull(localMessage.getBody());
Body body = new BinaryMemoryBody("Test message body".getBytes(), MimeUtil.ENC_7BIT);
localMessage.setBody(body);
folder.addPartToMessage(localMessage, localMessage);
LocalMessage completeLocalMessage = readMessageFromDatabase(folder, message);
String reconstructedMessage = writeMessageToString(completeLocalMessage);
assertEquals("To: to@example.com\r\n" + "MIME-Version: 1.0\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "Test message body", reconstructedMessage);
}
use of com.fsck.k9.mail.Body in project sms-backup-plus by jberkel.
the class Attachment method createPart.
private static MimeBodyPart createPart(Body body, final String filename, final String contentType) throws MessagingException {
MimeBodyPart part = new MimeBodyPart(body, contentType);
String contentTypeHeader = TextUtils.isEmpty(contentType) ? "application/octet-stream" : contentType;
String disposition = "attachment";
if (!TextUtils.isEmpty(filename)) {
// should set both name and filename parameters
// http://www.imc.org/ietf-smtp/mail-archive/msg05023.html
disposition += encodeRFC2231("filename", filename);
contentTypeHeader += encodeRFC2231("name", filename);
}
part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentTypeHeader);
part.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, disposition);
part.setHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING, "base64");
return part;
}
use of com.fsck.k9.mail.Body 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;
}
Aggregations