Search in sources :

Example 1 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 2 with AttachmentViewInfo

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

the class AttachmentPresenter method addInternalAttachment.

private void addInternalAttachment(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, true, true);
    attachment = attachment.deriveWithMetadataLoaded(attachmentViewInfo.mimeType, attachmentViewInfo.displayName, attachmentViewInfo.size);
    addAttachmentAndStartLoader(attachment);
}
Also used : Attachment(com.fsck.k9.activity.misc.Attachment) InlineAttachment(com.fsck.k9.activity.misc.InlineAttachment)

Example 3 with AttachmentViewInfo

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

the class AttachmentPresenter method addInlineAttachment.

private void addInlineAttachment(AttachmentViewInfo attachmentViewInfo) {
    if (inlineAttachments.containsKey(attachmentViewInfo.internalUri)) {
        throw new IllegalStateException("Received the same attachmentViewInfo twice!");
    }
    int loaderId = getNextFreeLoaderId();
    Attachment attachment = Attachment.createAttachment(attachmentViewInfo.internalUri, loaderId, attachmentViewInfo.mimeType, true, true);
    attachment = attachment.deriveWithMetadataLoaded(attachmentViewInfo.mimeType, attachmentViewInfo.displayName, attachmentViewInfo.size);
    inlineAttachments.put(attachment.uri, new InlineAttachment(attachmentViewInfo.part.getContentId(), attachment));
    Bundle bundle = new Bundle();
    bundle.putParcelable(LOADER_ARG_ATTACHMENT, attachment.uri);
    loaderManager.initLoader(attachment.loaderId, bundle, mInlineAttachmentContentLoaderCallback);
}
Also used : Bundle(android.os.Bundle) Attachment(com.fsck.k9.activity.misc.Attachment) InlineAttachment(com.fsck.k9.activity.misc.InlineAttachment) InlineAttachment(com.fsck.k9.activity.misc.InlineAttachment)

Example 4 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(androidx.annotation.WorkerThread)

Example 5 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)

Aggregations

Test (org.junit.Test)18 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)17 AttachmentViewInfo (com.fsck.k9.mailstore.AttachmentViewInfo)17 RobolectricTest (com.fsck.k9.RobolectricTest)14 Part (com.fsck.k9.mail.Part)9 Uri (android.net.Uri)5 LocalBodyPart (com.fsck.k9.mailstore.LocalBodyPart)5 BodyPart (com.fsck.k9.mail.BodyPart)4 K9RobolectricTest (com.fsck.k9.K9RobolectricTest)3 Attachment (com.fsck.k9.activity.misc.Attachment)3 Message (com.fsck.k9.mail.Message)3 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)3 ArrayList (java.util.ArrayList)3 WorkerThread (androidx.annotation.WorkerThread)2 InlineAttachment (com.fsck.k9.activity.misc.InlineAttachment)2 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