use of com.fsck.k9.activity.misc.Attachment in project k-9 by k9mail.
the class MessageBuilderTest method build_withAttachment_shouldSucceed.
@Test
public void build_withAttachment_shouldSucceed() throws Exception {
MessageBuilder messageBuilder = createSimpleMessageBuilder();
Attachment attachment = createAttachmentWithContent("text/plain", "attach.txt", TEST_ATTACHMENT_TEXT);
messageBuilder.setAttachments(Collections.singletonList(attachment));
messageBuilder.buildAsync(callback);
MimeMessage message = getMessageFromCallback();
assertEquals(MESSAGE_HEADERS + MESSAGE_CONTENT_WITH_ATTACH, getMessageContents(message));
}
use of com.fsck.k9.activity.misc.Attachment in project k-9 by k9mail.
the class MessageViewInfoExtractorTest method testTextPlusRfc822Message.
@Test
public void testTextPlusRfc822Message() throws MessagingException {
Locale.setDefault(Locale.US);
TimeZone.setDefault(TimeZone.getTimeZone("GMT+01:00"));
String innerBodyText = "Hey there. I'm inside a message/rfc822 (inline) attachment.";
// Create text/plain body
TextBody textBody = new TextBody(BODY_TEXT);
// Create inner text/plain body
TextBody innerBody = new TextBody(innerBodyText);
// Create message/rfc822 body
MimeMessage innerMessage = new MimeMessage();
innerMessage.addSentDate(new Date(112, 02, 17), false);
innerMessage.setRecipients(RecipientType.TO, new Address[] { new Address("to@example.com") });
innerMessage.setSubject("Subject");
innerMessage.setFrom(new Address("from@example.com"));
MimeMessageHelper.setBody(innerMessage, innerBody);
// Create multipart/mixed part
MimeMultipart multipart = MimeMultipart.newInstance();
MimeBodyPart bodyPart1 = new MimeBodyPart(textBody, "text/plain");
MimeBodyPart bodyPart2 = new MimeBodyPart(innerMessage, "message/rfc822");
bodyPart2.setHeader("Content-Disposition", "inline; filename=\"message.eml\"");
multipart.addBodyPart(bodyPart1);
multipart.addBodyPart(bodyPart2);
// Create message
MimeMessage message = new MimeMessage();
MimeMessageHelper.setBody(message, multipart);
// Extract text
List<Part> outputNonViewableParts = new ArrayList<Part>();
ArrayList<Viewable> outputViewableParts = new ArrayList<>();
MessageExtractor.findViewablesAndAttachments(message, outputViewableParts, outputNonViewableParts);
ViewableExtractedText container = messageViewInfoExtractor.extractTextFromViewables(outputViewableParts);
String expectedText = BODY_TEXT + "\r\n\r\n" + "----- message.eml ------------------------------------------------------" + "\r\n\r\n" + "From: from@example.com" + "\r\n" + "To: to@example.com" + "\r\n" + "Sent: Sat Mar 17 00:00:00 GMT+01:00 2012" + "\r\n" + "Subject: Subject" + "\r\n" + "\r\n" + innerBodyText;
String expectedHtml = "<pre class=\"k9mail\">" + BODY_TEXT_HTML + "</pre>" + "<p style=\"margin-top: 2.5em; margin-bottom: 1em; border-bottom: " + "1px solid #000\">message.eml</p>" + "<table style=\"border: 0\">" + "<tr>" + "<th style=\"text-align: left; vertical-align: top;\">From:</th>" + "<td>from@example.com</td>" + "</tr><tr>" + "<th style=\"text-align: left; vertical-align: top;\">To:</th>" + "<td>to@example.com</td>" + "</tr><tr>" + "<th style=\"text-align: left; vertical-align: top;\">Sent:</th>" + "<td>Sat Mar 17 00:00:00 GMT+01:00 2012</td>" + "</tr><tr>" + "<th style=\"text-align: left; vertical-align: top;\">Subject:</th>" + "<td>Subject</td>" + "</tr>" + "</table>" + "<pre class=\"k9mail\">" + innerBodyText + "</pre>";
assertEquals(expectedText, container.text);
assertEquals(expectedHtml, getHtmlBodyText(container.html));
}
use of com.fsck.k9.activity.misc.Attachment in project k-9 by k9mail.
the class MigrationTest method migrateMixedWithAttachments.
@Test
public void migrateMixedWithAttachments() throws Exception {
SQLiteDatabase db = createV50Database();
insertMixedWithAttachments(db);
db.close();
LocalStore localStore = LocalStore.getInstance(account, RuntimeEnvironment.application);
LocalMessage msg = localStore.getFolder("dev").getMessage("4");
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.BODY);
localStore.getFolder("dev").fetch(Collections.singletonList(msg), fp, null);
Assert.assertEquals(3, msg.getId());
Assert.assertEquals(8, msg.getHeaderNames().size());
Assert.assertEquals("multipart/mixed", msg.getMimeType());
Assert.assertEquals(1, msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE).length);
Assert.assertEquals("multipart/mixed", MimeUtility.getHeaderParameter(msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0], null));
Assert.assertEquals("----5D6OUTIYLNN2X63O0R2M0V53TOUAQP", MimeUtility.getHeaderParameter(msg.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0], "boundary"));
Assert.assertEquals(2, msg.getAttachmentCount());
Multipart body = (Multipart) msg.getBody();
Assert.assertEquals(3, body.getCount());
Assert.assertEquals("multipart/alternative", body.getBodyPart(0).getMimeType());
LocalBodyPart attachmentPart = (LocalBodyPart) body.getBodyPart(1);
Assert.assertEquals("image/png", attachmentPart.getMimeType());
Assert.assertEquals("2", attachmentPart.getServerExtra());
Assert.assertEquals("attachment", MimeUtility.getHeaderParameter(attachmentPart.getDisposition(), null));
Assert.assertEquals("k9small.png", MimeUtility.getHeaderParameter(attachmentPart.getDisposition(), "filename"));
Assert.assertEquals("2250", MimeUtility.getHeaderParameter(attachmentPart.getDisposition(), "size"));
FileBackedBody attachmentBody = (FileBackedBody) attachmentPart.getBody();
Assert.assertEquals(2250, attachmentBody.getSize());
Assert.assertEquals(MimeUtil.ENC_BINARY, attachmentBody.getEncoding());
Assert.assertEquals("application/whatevs", body.getBodyPart(2).getMimeType());
Assert.assertNull(body.getBodyPart(2).getBody());
}
use of com.fsck.k9.activity.misc.Attachment in project k-9 by k9mail.
the class MessageContainerView method renderAttachments.
public void renderAttachments(MessageViewInfo messageViewInfo) {
if (messageViewInfo.attachments != null) {
for (AttachmentViewInfo attachment : messageViewInfo.attachments) {
attachments.put(attachment.internalUri, attachment);
if (attachment.inlineAttachment) {
continue;
}
AttachmentView view = (AttachmentView) mInflater.inflate(R.layout.message_view_attachment, mAttachments, false);
view.setCallback(attachmentCallback);
view.setAttachment(attachment);
attachmentViewMap.put(attachment, view);
mAttachments.addView(view);
}
}
if (messageViewInfo.extraAttachments != null) {
for (AttachmentViewInfo attachment : messageViewInfo.extraAttachments) {
attachments.put(attachment.internalUri, attachment);
if (attachment.inlineAttachment) {
continue;
}
LockedAttachmentView view = (LockedAttachmentView) mInflater.inflate(R.layout.message_view_attachment_locked, mAttachments, false);
view.setCallback(attachmentCallback);
view.setAttachment(attachment);
// attachments.put(attachment, view);
mAttachments.addView(view);
}
}
}
use of com.fsck.k9.activity.misc.Attachment in project k-9 by k9mail.
the class MessageViewFragment method onSaveAttachmentToUserProvidedDirectory.
@Override
public void onSaveAttachmentToUserProvidedDirectory(final AttachmentViewInfo attachment) {
//TODO: check if we have to download the attachment first
currentAttachmentViewInfo = attachment;
FileBrowserHelper.getInstance().showFileBrowserActivity(MessageViewFragment.this, null, ACTIVITY_CHOOSE_DIRECTORY, new FileBrowserFailOverCallback() {
@Override
public void onPathEntered(String path) {
getAttachmentController(attachment).saveAttachmentTo(path);
}
@Override
public void onCancel() {
// Do nothing
}
});
}
Aggregations