Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1da373ad authored by cketti's avatar cketti
Browse files

Load message for "forward as attachment" in background

parent 4f4e1386
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -434,6 +434,17 @@
        
        </provider>

        <provider
            android:name=".provider.RawMessageProvider"
            android:authorities="${applicationId}.rawmessageprovider"
            android:exported="false">

            <meta-data
                android:name="de.cketti.safecontentresolver.ALLOW_INTERNAL_ACCESS"
                android:value="true" />

        </provider>

        <provider
            android:name=".provider.MessageProvider"
            android:authorities="${applicationId}.messageprovider"
+7 −2
Original line number Diff line number Diff line
@@ -398,8 +398,13 @@ public class MessageCompose extends K9Activity implements OnClickListener,
                        messageLoaderCallbacks);
                internalMessageHandler.sendEmptyMessage(MSG_PROGRESS_ON);

                if (action == Action.FORWARD_AS_ATTACHMENT) {
                    messageLoaderHelper.asyncStartOrResumeLoadingMessageMetadata(relatedMessageReference);
                } else {
                    Parcelable cachedDecryptionResult = intent.getParcelableExtra(EXTRA_MESSAGE_DECRYPTION_RESULT);
                messageLoaderHelper.asyncStartOrResumeLoadingMessage(relatedMessageReference, cachedDecryptionResult);
                    messageLoaderHelper.asyncStartOrResumeLoadingMessage(
                            relatedMessageReference, cachedDecryptionResult);
                }
            }

            if (action != Action.EDIT_DRAFT) {
+22 −3
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ public class MessageLoaderHelper {


    // transient state
    private boolean onlyLoadMetadata;
    private MessageReference messageReference;
    private Account account;

@@ -110,6 +111,7 @@ public class MessageLoaderHelper {

    @UiThread
    public void asyncStartOrResumeLoadingMessage(MessageReference messageReference, Parcelable cachedDecryptionResult) {
        onlyLoadMetadata = false;
        this.messageReference = messageReference;
        this.account = Preferences.getPreferences(context).getAccount(messageReference.getAccountUuid());

@@ -124,6 +126,15 @@ public class MessageLoaderHelper {
        startOrResumeLocalMessageLoader();
    }

    @UiThread
    public void asyncStartOrResumeLoadingMessageMetadata(MessageReference messageReference) {
        onlyLoadMetadata = true;
        this.messageReference = messageReference;
        this.account = Preferences.getPreferences(context).getAccount(messageReference.getAccountUuid());

        startOrResumeLocalMessageLoader();
    }

    @UiThread
    public void asyncReloadMessage() {
        startOrResumeLocalMessageLoader();
@@ -206,13 +217,20 @@ public class MessageLoaderHelper {

        callback.onMessageDataLoadFinished(localMessage);

        boolean messageIncomplete =
                !localMessage.isSet(Flag.X_DOWNLOADED_FULL) && !localMessage.isSet(Flag.X_DOWNLOADED_PARTIAL);
        boolean downloadedCompletely = localMessage.isSet(Flag.X_DOWNLOADED_FULL);
        boolean downloadedPartially = localMessage.isSet(Flag.X_DOWNLOADED_PARTIAL);
        boolean messageIncomplete = !downloadedCompletely && !downloadedPartially;
        if (messageIncomplete) {
            startDownloadingMessageBody(false);
            return;
        }

        if (onlyLoadMetadata) {
            MessageViewInfo messageViewInfo = MessageViewInfo.createForMetadataOnly(localMessage, !downloadedCompletely);
            onDecodeMessageFinished(messageViewInfo);
            return;
        }

        if (K9.isOpenPgpProviderConfigured()) {
            startOrResumeCryptoOperation();
            return;
@@ -239,7 +257,8 @@ public class MessageLoaderHelper {
                throw new IllegalStateException("loader id must be message loader id");
            }

            return new LocalMessageLoader(context, MessagingController.getInstance(context), account, messageReference);
            MessagingController messagingController = MessagingController.getInstance(context);
            return new LocalMessageLoader(context, messagingController, account, messageReference, onlyLoadMetadata);
        }

        @Override
+9 −23
Original line number Diff line number Diff line
package com.fsck.k9.activity.compose;


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
@@ -19,6 +17,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;

import com.fsck.k9.activity.MessageReference;
import com.fsck.k9.activity.compose.ComposeCryptoStatus.AttachErrorState;
import com.fsck.k9.activity.loader.AttachmentContentLoader;
import com.fsck.k9.activity.loader.AttachmentInfoLoader;
@@ -26,7 +25,9 @@ import com.fsck.k9.activity.misc.Attachment;
import com.fsck.k9.activity.misc.Attachment.LoadingState;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mailstore.AttachmentViewInfo;
import com.fsck.k9.mailstore.LocalMessage;
import com.fsck.k9.mailstore.MessageViewInfo;
import com.fsck.k9.provider.RawMessageProvider;


public class AttachmentPresenter {
@@ -164,10 +165,6 @@ public class AttachmentPresenter {
    }

    public boolean loadNonInlineAttachments(MessageViewInfo messageViewInfo) {
        return allPartsAvailable(messageViewInfo, true);
    }

    private boolean allPartsAvailable(MessageViewInfo messageViewInfo, boolean loadNonInlineAttachments) {
        boolean allPartsAvailable = true;

        for (AttachmentViewInfo attachmentViewInfo : messageViewInfo.attachments) {
@@ -178,10 +175,8 @@ public class AttachmentPresenter {
                allPartsAvailable = false;
                continue;
            }
            if (loadNonInlineAttachments) {
            addAttachment(attachmentViewInfo);
        }
        }

        return allPartsAvailable;
    }
@@ -194,23 +189,14 @@ public class AttachmentPresenter {
    }

    public void processMessageToForwardAsAttachment(MessageViewInfo messageViewInfo) throws IOException, MessagingException {
        boolean isMissingParts = !allPartsAvailable(messageViewInfo, false);
        if (isMissingParts) {
        if (messageViewInfo.isMessageIncomplete) {
            attachmentMvpView.showMissingAttachmentsPartialMessageForwardWarning();
        } else {
            File tempFile = File.createTempFile("pre", ".tmp");
            tempFile.deleteOnExit();
            FileOutputStream fileOutputStream = new FileOutputStream(tempFile);
            messageViewInfo.message.writeTo(fileOutputStream);
            fileOutputStream.close();
            LocalMessage localMessage = (LocalMessage) messageViewInfo.message;
            MessageReference messageReference = localMessage.makeMessageReference();
            Uri rawMessageUri = RawMessageProvider.getRawMessageUri(messageReference);

            int loaderId = getNextFreeLoaderId();
            Attachment attachment = Attachment.createAttachment(null, loaderId, "message/rfc822")
                    .deriveWithMetadataLoaded("message/rfc822", messageViewInfo.message.getSubject(), tempFile.length())
                    .deriveWithLoadComplete(tempFile.getAbsolutePath());

            attachments.put(attachment.uri, attachment);
            attachmentMvpView.addAttachmentView(attachment);
            addAttachment(rawMessageUri, "message/rfc822");
        }
    }

+18 −0
Original line number Diff line number Diff line
@@ -2351,6 +2351,24 @@ public class MessagingController {
        return message;
    }

    public LocalMessage loadMessageMetadata(Account account, String folderName, String uid) throws MessagingException {
        LocalStore localStore = account.getLocalStore();
        LocalFolder localFolder = localStore.getFolder(folderName);
        localFolder.open(Folder.OPEN_MODE_RW);

        LocalMessage message = localFolder.getMessage(uid);
        if (message == null || message.getDatabaseId() == 0) {
            throw new IllegalArgumentException("Message not found: folder=" + folderName + ", uid=" + uid);
        }

        FetchProfile fp = new FetchProfile();
        fp.add(FetchProfile.Item.ENVELOPE);
        localFolder.fetch(Collections.singletonList(message), fp, null);
        localFolder.close();

        return message;
    }

    private void markMessageAsReadOnView(Account account, LocalMessage message)
            throws MessagingException {

Loading