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

Commit 4f4e1386 authored by Thomas E. Horner's avatar Thomas E. Horner Committed by cketti
Browse files

Forward as Attachment

parent d0c8cc3b
Loading
Loading
Loading
Loading
+28 −8
Original line number Diff line number Diff line
package com.fsck.k9.activity;


import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -121,6 +122,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
    public static final String ACTION_REPLY = "com.fsck.k9.intent.action.REPLY";
    public static final String ACTION_REPLY_ALL = "com.fsck.k9.intent.action.REPLY_ALL";
    public static final String ACTION_FORWARD = "com.fsck.k9.intent.action.FORWARD";
    public static final String ACTION_FORWARD_AS_ATTACHMENT = "com.fsck.k9.intent.action.FORWARD_AS_ATTACHMENT";
    public static final String ACTION_EDIT_DRAFT = "com.fsck.k9.intent.action.EDIT_DRAFT";
    private static final String ACTION_AUTOCRYPT_PEER = "org.autocrypt.PEER_ACTION";

@@ -355,6 +357,8 @@ public class MessageCompose extends K9Activity implements OnClickListener,
                this.action = Action.REPLY_ALL;
            } else if (ACTION_FORWARD.equals(action)) {
                this.action = Action.FORWARD;
            } else if (ACTION_FORWARD_AS_ATTACHMENT.equals(action)) {
                this.action = Action.FORWARD_AS_ATTACHMENT;
            } else if (ACTION_EDIT_DRAFT.equals(action)) {
                this.action = Action.EDIT_DRAFT;
            } else {
@@ -388,7 +392,8 @@ public class MessageCompose extends K9Activity implements OnClickListener,

        if (!relatedMessageProcessed) {
            if (action == Action.REPLY || action == Action.REPLY_ALL ||
                    action == Action.FORWARD || action == Action.EDIT_DRAFT) {
                    action == Action.FORWARD || action == Action.FORWARD_AS_ATTACHMENT ||
                    action == Action.EDIT_DRAFT) {
                messageLoaderHelper = new MessageLoaderHelper(this, getLoaderManager(), getFragmentManager(),
                        messageLoaderCallbacks);
                internalMessageHandler.sendEmptyMessage(MSG_PROGRESS_ON);
@@ -418,7 +423,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
            recipientMvpView.requestFocusOnToField();
        }

        if (action == Action.FORWARD) {
        if (action == Action.FORWARD || action == Action.FORWARD_AS_ATTACHMENT) {
            relatedMessageReference = relatedMessageReference.withModifiedFlag(Flag.FORWARDED);
        }

@@ -1193,7 +1198,11 @@ public class MessageCompose extends K9Activity implements OnClickListener,
                    break;
                }
                case FORWARD: {
                    processMessageToForward(messageViewInfo);
                    processMessageToForward(messageViewInfo, false);
                    break;
                }
                case FORWARD_AS_ATTACHMENT: {
                    processMessageToForward(messageViewInfo, true);
                    break;
                }
                case EDIT_DRAFT: {
@@ -1205,12 +1214,12 @@ public class MessageCompose extends K9Activity implements OnClickListener,
                    break;
                }
            }
        } catch (MessagingException me) {
        } catch (MessagingException | IOException e) {
            /*
             * Let the user continue composing their message even if we have a problem processing
             * the source message. Log it as an error, though.
             */
            Timber.e(me, "Error while processing source message: ");
            Timber.e(e, "Error while processing source message: ");
        } finally {
            relatedMessageProcessed = true;
            changesMadeSinceLastSave = false;
@@ -1268,7 +1277,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,

    }

    private void processMessageToForward(MessageViewInfo messageViewInfo) throws MessagingException {
    private void processMessageToForward(MessageViewInfo messageViewInfo, boolean asAttachment) throws IOException, MessagingException {
        Message message = messageViewInfo.message;

        String subject = message.getSubject();
@@ -1290,9 +1299,13 @@ public class MessageCompose extends K9Activity implements OnClickListener,
        }

        // Quote the message and setup the UI.
        if (asAttachment) {
            attachmentPresenter.processMessageToForwardAsAttachment(messageViewInfo);
        } else {
            quotedMessagePresenter.processMessageToForward(messageViewInfo);
            attachmentPresenter.processMessageToForward(messageViewInfo);
        }
    }

    private void processDraftMessage(MessageViewInfo messageViewInfo) {
        Message message = messageViewInfo.message;
@@ -1772,6 +1785,12 @@ public class MessageCompose extends K9Activity implements OnClickListener,
            Toast.makeText(MessageCompose.this,
                    getString(R.string.message_compose_attachments_skipped_toast), Toast.LENGTH_LONG).show();
        }

        @Override
        public void showMissingAttachmentsPartialMessageForwardWarning() {
            Toast.makeText(MessageCompose.this,
                    getString(R.string.message_compose_attachments_forward_toast), Toast.LENGTH_LONG).show();
        }
    };

    private Handler internalMessageHandler = new Handler() {
@@ -1809,6 +1828,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
        REPLY(R.string.compose_title_reply),
        REPLY_ALL(R.string.compose_title_reply_all),
        FORWARD(R.string.compose_title_forward),
        FORWARD_AS_ATTACHMENT(R.string.compose_title_forward_as_attachment),
        EDIT_DRAFT(R.string.compose_title_compose);

        private final int titleResource;
+14 −0
Original line number Diff line number Diff line
@@ -895,6 +895,10 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
                mMessageViewFragment.onForward();
                return true;
            }
            case R.id.forward_as_attachment: {
                mMessageViewFragment.onForwardAsAttachment();
                return true;
            }
            case R.id.share: {
                mMessageViewFragment.onSendAlternate();
                return true;
@@ -1245,6 +1249,16 @@ public class MessageList extends K9Activity implements MessageListFragmentListen
        MessageActions.actionForward(this, messageReference, decryptionResultForReply);
    }

    @Override
    public void onForwardAsAttachment(MessageReference messageReference) {
        onForwardAsAttachment(messageReference, null);
    }

    @Override
    public void onForwardAsAttachment(MessageReference messageReference, Parcelable decryptionResultForReply) {
        MessageActions.actionForwardAsAttachment(this, messageReference, decryptionResultForReply);
    }

    @Override
    public void onReply(MessageReference messageReference) {
        onReply(messageReference, null);
+33 −1
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;

@@ -21,6 +24,7 @@ import com.fsck.k9.activity.loader.AttachmentContentLoader;
import com.fsck.k9.activity.loader.AttachmentInfoLoader;
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.MessageViewInfo;

@@ -160,6 +164,10 @@ 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) {
@@ -170,8 +178,10 @@ public class AttachmentPresenter {
                allPartsAvailable = false;
                continue;
            }
            if (loadNonInlineAttachments) {
                addAttachment(attachmentViewInfo);
            }
        }

        return allPartsAvailable;
    }
@@ -183,6 +193,27 @@ public class AttachmentPresenter {
        }
    }

    public void processMessageToForwardAsAttachment(MessageViewInfo messageViewInfo) throws IOException, MessagingException {
        boolean isMissingParts = !allPartsAvailable(messageViewInfo, false);
        if (isMissingParts) {
            attachmentMvpView.showMissingAttachmentsPartialMessageForwardWarning();
        } else {
            File tempFile = File.createTempFile("pre", ".tmp");
            tempFile.deleteOnExit();
            FileOutputStream fileOutputStream = new FileOutputStream(tempFile);
            messageViewInfo.message.writeTo(fileOutputStream);
            fileOutputStream.close();

            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);
        }
    }

    private void addAttachmentAndStartLoader(Attachment attachment) {
        attachments.put(attachment.uri, attachment);
        listener.onAttachmentAdded();
@@ -383,6 +414,7 @@ public class AttachmentPresenter {
        void performSaveAfterChecks();

        void showMissingAttachmentsPartialMessageWarning();
        void showMissingAttachmentsPartialMessageForwardWarning();
    }

    public interface AttachmentsChangedListener {
+11 −0
Original line number Diff line number Diff line
@@ -71,6 +71,17 @@ public class MessageActions {
        context.startActivity(i);
    }

    /**
     * Compose a new message as a forward of the given message.
     */
    public static void actionForwardAsAttachment(Context context, MessageReference messageReference, Parcelable decryptionResult) {
        Intent i = new Intent(context, MessageCompose.class);
        i.putExtra(MessageCompose.EXTRA_MESSAGE_REFERENCE, messageReference.toIdentityString());
        i.putExtra(MessageCompose.EXTRA_MESSAGE_DECRYPTION_RESULT, decryptionResult);
        i.setAction(MessageCompose.ACTION_FORWARD_AS_ATTACHMENT);
        context.startActivity(i);
    }

    /**
     * Continue composition of the given message. This action modifies the way this Activity
     * handles certain actions.
+9 −0
Original line number Diff line number Diff line
@@ -788,6 +788,10 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
        fragmentListener.onForward(messageReference);
    }

    public void onForwardAsAttachment(MessageReference messageReference) {
        fragmentListener.onForwardAsAttachment(messageReference);
    }

    private void onResendMessage(MessageReference messageReference) {
        fragmentListener.onResendMessage(messageReference);
    }
@@ -1116,6 +1120,10 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
                onForward(getMessageAtPosition(adapterPosition));
                break;
            }
            case R.id.forward_as_attachment: {
                onForwardAsAttachment(getMessageAtPosition(adapterPosition));
                break;
            }
            case R.id.send_again: {
                onResendMessage(getMessageAtPosition(adapterPosition));
                selectedCount = 0;
@@ -2376,6 +2384,7 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
        void showMoreFromSameSender(String senderAddress);
        void onResendMessage(MessageReference message);
        void onForward(MessageReference message);
        void onForwardAsAttachment(MessageReference message);
        void onReply(MessageReference message);
        void onReplyAll(MessageReference message);
        void openMessage(MessageReference messageReference);
Loading