Search in sources :

Example 16 with AttachmentViewInfo

use of com.fsck.k9.mailstore.AttachmentViewInfo in project k-9 by k9mail.

the class AttachmentInfoExtractorTest method extractInfo__withDeferredFileBody.

@Test
public void extractInfo__withDeferredFileBody() throws Exception {
    attachmentInfoExtractor = new AttachmentInfoExtractor(context) {

        @Nullable
        @Override
        protected Uri getDecryptedFileProviderUri(DeferredFileBody decryptedTempFileBody, String mimeType) {
            return TEST_URI;
        }
    };
    DeferredFileBody body = mock(DeferredFileBody.class);
    when(body.getSize()).thenReturn(TEST_SIZE);
    MimeBodyPart part = new MimeBodyPart();
    part.setBody(body);
    part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, TEST_MIME_TYPE);
    AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfo(part);
    assertEquals(TEST_URI, attachmentViewInfo.internalUri);
    assertEquals(TEST_SIZE, attachmentViewInfo.size);
    assertEquals(TEST_MIME_TYPE, attachmentViewInfo.mimeType);
    assertFalse(attachmentViewInfo.inlineAttachment);
    assertTrue(attachmentViewInfo.isContentAvailable);
}
Also used : MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Uri(android.net.Uri) Nullable(android.support.annotation.Nullable) DeferredFileBody(com.fsck.k9.mailstore.DeferredFileBody) AttachmentViewInfo(com.fsck.k9.mailstore.AttachmentViewInfo) Test(org.junit.Test)

Example 17 with AttachmentViewInfo

use of com.fsck.k9.mailstore.AttachmentViewInfo in project k-9 by k9mail.

the class AttachmentInfoExtractorTest method extractInfoForDb__withDispositionInlineAndContentId__shouldReturnInlineAttachment.

@Test
public void extractInfoForDb__withDispositionInlineAndContentId__shouldReturnInlineAttachment() throws Exception {
    Part part = new MimeBodyPart();
    part.addRawHeader(MimeHeader.HEADER_CONTENT_ID, MimeHeader.HEADER_CONTENT_ID + ": " + TEST_CONTENT_ID);
    part.addRawHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, MimeHeader.HEADER_CONTENT_DISPOSITION + ": " + "inline" + ";\n  filename=\"filename.ext\";\n  meaningless=\"dummy\"");
    AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
    assertTrue(attachmentViewInfo.inlineAttachment);
}
Also used : Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) LocalBodyPart(com.fsck.k9.mailstore.LocalBodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) AttachmentViewInfo(com.fsck.k9.mailstore.AttachmentViewInfo) Test(org.junit.Test)

Example 18 with AttachmentViewInfo

use of com.fsck.k9.mailstore.AttachmentViewInfo 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)

Example 19 with AttachmentViewInfo

use of com.fsck.k9.mailstore.AttachmentViewInfo in project k-9 by k9mail.

the class AttachmentInfoExtractorTest method extractInfoForDb__withContentTypeAndEncodedWordName__shouldReturnDecodedName.

@Test
public void extractInfoForDb__withContentTypeAndEncodedWordName__shouldReturnDecodedName() throws Exception {
    Part part = new MimeBodyPart();
    part.addRawHeader(MimeHeader.HEADER_CONTENT_TYPE, MimeHeader.HEADER_CONTENT_TYPE + ": " + TEST_MIME_TYPE + "; name=\"=?ISO-8859-1?Q?Sm=F8rrebr=F8d?=\"");
    AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
    assertEquals("Smørrebrød", attachmentViewInfo.displayName);
}
Also used : Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) LocalBodyPart(com.fsck.k9.mailstore.LocalBodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) AttachmentViewInfo(com.fsck.k9.mailstore.AttachmentViewInfo) Test(org.junit.Test)

Example 20 with AttachmentViewInfo

use of com.fsck.k9.mailstore.AttachmentViewInfo in project k-9 by k9mail.

the class AttachmentInfoExtractorTest method extractInfoForDb__withTextMimeType__shouldReturnTxtExtension.

@Test
public void extractInfoForDb__withTextMimeType__shouldReturnTxtExtension() throws Exception {
    MimeBodyPart part = new MimeBodyPart();
    part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "text/plain");
    AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
    // MimeUtility.getExtensionByMimeType("text/plain"); -> "txt"
    assertEquals("noname.txt", attachmentViewInfo.displayName);
    assertEquals("text/plain", attachmentViewInfo.mimeType);
}
Also used : MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) AttachmentViewInfo(com.fsck.k9.mailstore.AttachmentViewInfo) Test(org.junit.Test)

Aggregations

AttachmentViewInfo (com.fsck.k9.mailstore.AttachmentViewInfo)15 Test (org.junit.Test)13 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)12 Part (com.fsck.k9.mail.Part)7 Uri (android.net.Uri)5 WorkerThread (android.support.annotation.WorkerThread)3 LocalBodyPart (com.fsck.k9.mailstore.LocalBodyPart)3 ArrayList (java.util.ArrayList)3 Body (com.fsck.k9.mail.Body)2 Multipart (com.fsck.k9.mail.Multipart)2 DeferredFileBody (com.fsck.k9.mailstore.DeferredFileBody)2 LocalPart (com.fsck.k9.mailstore.LocalPart)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Nullable (android.support.annotation.Nullable)1 VisibleForTesting (android.support.annotation.VisibleForTesting)1 MenuItem (android.view.MenuItem)1 OnMenuItemClickListener (android.view.MenuItem.OnMenuItemClickListener)1 WebView (android.webkit.WebView)1 HitTestResult (android.webkit.WebView.HitTestResult)1