use of com.fsck.k9.mailstore.LocalBodyPart in project k-9 by k9mail.
the class LocalStoreTest method findPartById__withNestedLocalBodyPart.
@Test
public void findPartById__withNestedLocalBodyPart() throws Exception {
LocalBodyPart searchRoot = new LocalBodyPart(null, null, 1L, -1L);
LocalBodyPart needlePart = new LocalBodyPart(null, null, 123L, -1L);
MimeMultipart mimeMultipart = new MimeMultipart("boundary");
mimeMultipart.addBodyPart(needlePart);
searchRoot.setBody(mimeMultipart);
Part part = LocalStore.findPartById(searchRoot, 123L);
assertSame(needlePart, part);
}
use of com.fsck.k9.mailstore.LocalBodyPart 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.mailstore.LocalBodyPart in project k-9 by k9mail.
the class AttachmentInfoExtractorTest method extractInfo__fromLocalBodyPart__shouldReturnProvidedValues.
@Test
public void extractInfo__fromLocalBodyPart__shouldReturnProvidedValues() throws Exception {
LocalBodyPart part = new LocalBodyPart(TEST_ACCOUNT_UUID, null, TEST_ID, TEST_SIZE);
part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, TEST_MIME_TYPE);
AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfo(part);
assertEquals(AttachmentProvider.getAttachmentUri(TEST_ACCOUNT_UUID, TEST_ID), attachmentViewInfo.internalUri);
assertEquals(TEST_SIZE, attachmentViewInfo.size);
assertEquals(TEST_MIME_TYPE, attachmentViewInfo.mimeType);
}
Aggregations