Search in sources :

Example 6 with LocalBodyPart

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);
}
Also used : MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Test(org.junit.Test)

Example 7 with LocalBodyPart

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());
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) Multipart(com.fsck.k9.mail.Multipart) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Test(org.junit.Test)

Example 8 with LocalBodyPart

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);
}
Also used : LocalBodyPart(com.fsck.k9.mailstore.LocalBodyPart) AttachmentViewInfo(com.fsck.k9.mailstore.AttachmentViewInfo) Test(org.junit.Test)

Aggregations

Part (com.fsck.k9.mail.Part)6 Test (org.junit.Test)6 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)4 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)4 Multipart (com.fsck.k9.mail.Multipart)3 Body (com.fsck.k9.mail.Body)2 BodyPart (com.fsck.k9.mail.BodyPart)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 FetchProfile (com.fsck.k9.mail.FetchProfile)1 Message (com.fsck.k9.mail.Message)1 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)1 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)1 AttachmentViewInfo (com.fsck.k9.mailstore.AttachmentViewInfo)1 LocalBodyPart (com.fsck.k9.mailstore.LocalBodyPart)1 File (java.io.File)1 Stack (java.util.Stack)1