Search in sources :

Example 1 with DeferredFileBody

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

the class DeferredFileBodyTest method setUp.

@Before
public void setUp() throws Exception {
    FileFactory fileFactory = new FileFactory() {

        @Override
        public File createFile() throws IOException {
            assertNull("only a single file should be created", createdFile);
            createdFile = File.createTempFile("test", "tmp");
            createdFile.deleteOnExit();
            return createdFile;
        }
    };
    deferredFileBody = new DeferredFileBody(TEST_THRESHOLD, fileFactory, TEST_ENCODING);
}
Also used : FileFactory(com.fsck.k9.mailstore.util.FileFactory) Before(org.junit.Before)

Example 2 with DeferredFileBody

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

the class AttachmentInfoExtractor method extractAttachmentInfo.

@WorkerThread
public AttachmentViewInfo extractAttachmentInfo(Part part) throws MessagingException {
    Uri uri;
    long size;
    boolean isContentAvailable;
    if (part instanceof LocalPart) {
        LocalPart localPart = (LocalPart) part;
        String accountUuid = localPart.getAccountUuid();
        long messagePartId = localPart.getId();
        size = localPart.getSize();
        isContentAvailable = part.getBody() != null;
        uri = AttachmentProvider.getAttachmentUri(accountUuid, messagePartId);
    } else if (part instanceof LocalMessage) {
        LocalMessage localMessage = (LocalMessage) part;
        String accountUuid = localMessage.getAccount().getUuid();
        long messagePartId = localMessage.getMessagePartId();
        size = localMessage.getSize();
        isContentAvailable = part.getBody() != null;
        uri = AttachmentProvider.getAttachmentUri(accountUuid, messagePartId);
    } else {
        Body body = part.getBody();
        if (body instanceof DeferredFileBody) {
            DeferredFileBody decryptedTempFileBody = (DeferredFileBody) body;
            size = decryptedTempFileBody.getSize();
            uri = getDecryptedFileProviderUri(decryptedTempFileBody, part.getMimeType());
            isContentAvailable = true;
        } else {
            throw new IllegalArgumentException("Unsupported part type provided");
        }
    }
    return extractAttachmentInfo(part, uri, size, isContentAvailable);
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) LocalPart(com.fsck.k9.mailstore.LocalPart) Uri(android.net.Uri) Body(com.fsck.k9.mail.Body) DeferredFileBody(com.fsck.k9.mailstore.DeferredFileBody) DeferredFileBody(com.fsck.k9.mailstore.DeferredFileBody) WorkerThread(android.support.annotation.WorkerThread)

Example 3 with DeferredFileBody

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

Aggregations

Uri (android.net.Uri)2 DeferredFileBody (com.fsck.k9.mailstore.DeferredFileBody)2 Nullable (android.support.annotation.Nullable)1 WorkerThread (android.support.annotation.WorkerThread)1 Body (com.fsck.k9.mail.Body)1 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)1 AttachmentViewInfo (com.fsck.k9.mailstore.AttachmentViewInfo)1 LocalMessage (com.fsck.k9.mailstore.LocalMessage)1 LocalPart (com.fsck.k9.mailstore.LocalPart)1 FileFactory (com.fsck.k9.mailstore.util.FileFactory)1 Before (org.junit.Before)1 Test (org.junit.Test)1