Search in sources :

Example 6 with AttachmentViewInfo

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

the class AttachmentInfoExtractorTest method extractInfoForDb__withDispositionAttach__shouldReturnNamedAttachment.

@Test
public void extractInfoForDb__withDispositionAttach__shouldReturnNamedAttachment() throws Exception {
    MimeBodyPart part = new MimeBodyPart();
    part.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "attachment" + "; filename=\"filename.ext\"; meaningless=\"dummy\"");
    AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
    assertEquals(Uri.EMPTY, attachmentViewInfo.internalUri);
    assertEquals("filename.ext", attachmentViewInfo.displayName);
    assertFalse(attachmentViewInfo.inlineAttachment);
}
Also used : MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) AttachmentViewInfo(com.fsck.k9.mailstore.AttachmentViewInfo) Test(org.junit.Test)

Example 7 with AttachmentViewInfo

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

the class AttachmentInfoExtractor method extractAttachmentInfoForView.

@WorkerThread
public List<AttachmentViewInfo> extractAttachmentInfoForView(List<Part> attachmentParts) throws MessagingException {
    List<AttachmentViewInfo> attachments = new ArrayList<>();
    for (Part part : attachmentParts) {
        AttachmentViewInfo attachmentViewInfo = extractAttachmentInfo(part);
        attachments.add(attachmentViewInfo);
    }
    return attachments;
}
Also used : Part(com.fsck.k9.mail.Part) LocalPart(com.fsck.k9.mailstore.LocalPart) ArrayList(java.util.ArrayList) AttachmentViewInfo(com.fsck.k9.mailstore.AttachmentViewInfo) WorkerThread(android.support.annotation.WorkerThread)

Example 8 with AttachmentViewInfo

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

the class MessageViewInfoExtractor method extractMessageForView.

@WorkerThread
public MessageViewInfo extractMessageForView(Message message, @Nullable MessageCryptoAnnotations annotations) throws MessagingException {
    Part rootPart;
    CryptoResultAnnotation cryptoResultAnnotation;
    List<Part> extraParts;
    CryptoMessageParts cryptoMessageParts = MessageCryptoSplitter.split(message, annotations);
    if (cryptoMessageParts != null) {
        rootPart = cryptoMessageParts.contentPart;
        cryptoResultAnnotation = cryptoMessageParts.contentCryptoAnnotation;
        extraParts = cryptoMessageParts.extraParts;
    } else {
        if (annotations != null && !annotations.isEmpty()) {
            Timber.e("Got message annotations but no crypto root part!");
        }
        rootPart = message;
        cryptoResultAnnotation = null;
        extraParts = null;
    }
    List<AttachmentViewInfo> attachmentInfos = new ArrayList<>();
    ViewableExtractedText viewable = extractViewableAndAttachments(Collections.singletonList(rootPart), attachmentInfos);
    List<AttachmentViewInfo> extraAttachmentInfos = new ArrayList<>();
    String extraViewableText = null;
    if (extraParts != null) {
        ViewableExtractedText extraViewable = extractViewableAndAttachments(extraParts, extraAttachmentInfos);
        extraViewableText = extraViewable.text;
    }
    AttachmentResolver attachmentResolver = AttachmentResolver.createFromPart(rootPart);
    boolean isMessageIncomplete = !message.isSet(Flag.X_DOWNLOADED_FULL) || MessageExtractor.hasMissingParts(message);
    return MessageViewInfo.createWithExtractedContent(message, isMessageIncomplete, rootPart, viewable.html, attachmentInfos, cryptoResultAnnotation, attachmentResolver, extraViewableText, extraAttachmentInfos);
}
Also used : CryptoMessageParts(com.fsck.k9.ui.crypto.MessageCryptoSplitter.CryptoMessageParts) Part(com.fsck.k9.mail.Part) ArrayList(java.util.ArrayList) WorkerThread(android.support.annotation.WorkerThread)

Example 9 with AttachmentViewInfo

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

the class LocalFolder method leafPartToContentValues.

private File leafPartToContentValues(ContentValues cv, Part part, Body body) throws MessagingException, IOException {
    AttachmentViewInfo attachment = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
    cv.put("display_name", attachment.displayName);
    String encoding = getTransferEncoding(part);
    if (!(body instanceof SizeAware)) {
        throw new IllegalStateException("Body needs to implement SizeAware");
    }
    SizeAware sizeAwareBody = (SizeAware) body;
    long fileSize = sizeAwareBody.getSize();
    File file = null;
    int dataLocation;
    if (fileSize > MAX_BODY_SIZE_FOR_DATABASE) {
        dataLocation = DataLocation.ON_DISK;
        file = writeBodyToDiskIfNecessary(part);
        long size = decodeAndCountBytes(file, encoding, fileSize);
        cv.put("decoded_body_size", size);
    } else {
        dataLocation = DataLocation.IN_DATABASE;
        byte[] bodyData = getBodyBytes(body);
        cv.put("data", bodyData);
        long size = decodeAndCountBytes(bodyData, encoding, bodyData.length);
        cv.put("decoded_body_size", size);
    }
    cv.put("data_location", dataLocation);
    cv.put("encoding", encoding);
    cv.put("content_id", part.getContentId());
    return file;
}
Also used : SizeAware(com.fsck.k9.mail.internet.SizeAware) File(java.io.File)

Example 10 with AttachmentViewInfo

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

the class MessageContainerView method renderAttachments.

public void renderAttachments(MessageViewInfo messageViewInfo) {
    if (messageViewInfo.attachments != null) {
        for (AttachmentViewInfo attachment : messageViewInfo.attachments) {
            attachments.put(attachment.internalUri, attachment);
            if (attachment.inlineAttachment) {
                continue;
            }
            AttachmentView view = (AttachmentView) mInflater.inflate(R.layout.message_view_attachment, mAttachments, false);
            view.setCallback(attachmentCallback);
            view.setAttachment(attachment);
            attachmentViewMap.put(attachment, view);
            mAttachments.addView(view);
        }
    }
    if (messageViewInfo.extraAttachments != null) {
        for (AttachmentViewInfo attachment : messageViewInfo.extraAttachments) {
            attachments.put(attachment.internalUri, attachment);
            if (attachment.inlineAttachment) {
                continue;
            }
            LockedAttachmentView view = (LockedAttachmentView) mInflater.inflate(R.layout.message_view_attachment_locked, mAttachments, false);
            view.setCallback(attachmentCallback);
            view.setAttachment(attachment);
            // attachments.put(attachment, view);
            mAttachments.addView(view);
        }
    }
}
Also used : AttachmentViewInfo(com.fsck.k9.mailstore.AttachmentViewInfo)

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