Search in sources :

Example 1 with LocalPart

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

the class AttachmentController method downloadAttachment.

private void downloadAttachment(LocalPart localPart, final Runnable attachmentDownloadedCallback) {
    String accountUuid = localPart.getAccountUuid();
    Account account = Preferences.getPreferences(context).getAccount(accountUuid);
    LocalMessage message = localPart.getMessage();
    messageViewFragment.showAttachmentLoadingDialog();
    controller.loadAttachment(account, message, attachment.part, new SimpleMessagingListener() {

        @Override
        public void loadAttachmentFinished(Account account, Message message, Part part) {
            messageViewFragment.hideAttachmentLoadingDialogOnMainThread();
            messageViewFragment.runOnMainThread(attachmentDownloadedCallback);
        }

        @Override
        public void loadAttachmentFailed(Account account, Message message, Part part, String reason) {
            messageViewFragment.hideAttachmentLoadingDialogOnMainThread();
        }
    });
}
Also used : Account(com.fsck.k9.Account) LocalMessage(com.fsck.k9.mailstore.LocalMessage) LocalMessage(com.fsck.k9.mailstore.LocalMessage) Message(com.fsck.k9.mail.Message) Part(com.fsck.k9.mail.Part) LocalPart(com.fsck.k9.mailstore.LocalPart) SimpleMessagingListener(com.fsck.k9.controller.SimpleMessagingListener)

Example 2 with LocalPart

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

the class LocalStore method findPartById.

static Part findPartById(Part searchRoot, long partId) {
    if (searchRoot instanceof LocalMessage) {
        LocalMessage localMessage = (LocalMessage) searchRoot;
        if (localMessage.getMessagePartId() == partId) {
            return localMessage;
        }
    }
    Stack<Part> partStack = new Stack<>();
    partStack.add(searchRoot);
    while (!partStack.empty()) {
        Part part = partStack.pop();
        if (part instanceof LocalPart) {
            LocalPart localBodyPart = (LocalPart) part;
            if (localBodyPart.getId() == partId) {
                return part;
            }
        }
        Body body = part.getBody();
        if (body instanceof Multipart) {
            Multipart innerMultipart = (Multipart) body;
            for (BodyPart innerPart : innerMultipart.getBodyParts()) {
                partStack.add(innerPart);
            }
        }
        if (body instanceof Part) {
            partStack.add((Part) body);
        }
    }
    return null;
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) Multipart(com.fsck.k9.mail.Multipart) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) Body(com.fsck.k9.mail.Body) Stack(java.util.Stack)

Example 3 with LocalPart

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

Aggregations

Body (com.fsck.k9.mail.Body)2 Part (com.fsck.k9.mail.Part)2 LocalMessage (com.fsck.k9.mailstore.LocalMessage)2 LocalPart (com.fsck.k9.mailstore.LocalPart)2 Uri (android.net.Uri)1 WorkerThread (android.support.annotation.WorkerThread)1 Account (com.fsck.k9.Account)1 SimpleMessagingListener (com.fsck.k9.controller.SimpleMessagingListener)1 BodyPart (com.fsck.k9.mail.BodyPart)1 Message (com.fsck.k9.mail.Message)1 Multipart (com.fsck.k9.mail.Multipart)1 DeferredFileBody (com.fsck.k9.mailstore.DeferredFileBody)1 Stack (java.util.Stack)1