Search in sources :

Example 21 with AttachmentViewInfo

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

the class AttachmentInfoExtractorTest method extractInfoForDb__withDispositionInvalidSizeParam__shouldReturnUnknownSize.

@Test
public void extractInfoForDb__withDispositionInvalidSizeParam__shouldReturnUnknownSize() throws Exception {
    MimeBodyPart part = new MimeBodyPart();
    part.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "attachment" + "; size=\"notanint\"");
    AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
    assertEquals(AttachmentViewInfo.UNKNOWN_SIZE, attachmentViewInfo.size);
}
Also used : MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) AttachmentViewInfo(com.fsck.k9.mailstore.AttachmentViewInfo) Test(org.junit.Test)

Example 22 with AttachmentViewInfo

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

the class AttachmentInfoExtractorTest method extractInfoForDb__withDispositionSizeParam__shouldReturnThatSize.

@Test
public void extractInfoForDb__withDispositionSizeParam__shouldReturnThatSize() throws Exception {
    MimeBodyPart part = new MimeBodyPart();
    part.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "attachment" + "; size=\"" + TEST_SIZE + "\"");
    AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
    assertEquals(TEST_SIZE, attachmentViewInfo.size);
}
Also used : MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) AttachmentViewInfo(com.fsck.k9.mailstore.AttachmentViewInfo) Test(org.junit.Test)

Example 23 with AttachmentViewInfo

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

the class AttachmentPresenter method addAttachment.

private void addAttachment(AttachmentViewInfo attachmentViewInfo) {
    if (attachments.containsKey(attachmentViewInfo.internalUri)) {
        throw new IllegalStateException("Received the same attachmentViewInfo twice!");
    }
    int loaderId = getNextFreeLoaderId();
    Attachment attachment = Attachment.createAttachment(attachmentViewInfo.internalUri, loaderId, attachmentViewInfo.mimeType);
    attachment = attachment.deriveWithMetadataLoaded(attachmentViewInfo.mimeType, attachmentViewInfo.displayName, attachmentViewInfo.size);
    addAttachmentAndStartLoader(attachment);
}
Also used : Attachment(com.fsck.k9.activity.misc.Attachment)

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