From abfa20cb84af1394b04ee361bd726cde8c246262 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 25 Jan 2019 07:48:07 +0000 Subject: [PATCH] Check cross account move conditions --- .../eu/faircode/email/FragmentMessages.java | 17 ++++++++++++++++- .../eu/faircode/email/ServiceSynchronize.java | 8 ++++++++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 7c10ff407e..42498ac68a 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -2084,6 +2084,18 @@ public class FragmentMessages extends FragmentBase { EntityMessage message = db.message().getMessage(target.id); if (message != null) { Log.i("Move id=" + target.id + " target=" + target.folder.name); + + // Cross account move: check if message downloaded + if (!target.folder.account.equals(message.account)) { + if (!message.content) + throw new IllegalArgumentException(getString(R.string.title_no_accross)); + + List attachments = db.attachment().getAttachments(message.id); + for (EntityAttachment attachment : attachments) + if (!attachment.available) + throw new IllegalArgumentException(getString(R.string.title_no_accross)); + } + EntityOperation.queue(context, db, message, EntityOperation.MOVE, target.folder.id); } } @@ -2097,7 +2109,10 @@ public class FragmentMessages extends FragmentBase { @Override protected void onException(Bundle args, Throwable ex) { - Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex); + if (ex instanceof IllegalArgumentException) + Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show(); + else + Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex); } }.execute(FragmentMessages.this, args, "messages:move"); } diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index ceaab311bf..7172b89a56 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -1675,6 +1675,14 @@ public class ServiceSynchronize extends LifecycleService { } private void doAdd(EntityFolder folder, Session isession, IMAPFolder ifolder, EntityMessage message, JSONArray jargs, DB db) throws MessagingException, JSONException, IOException { + if (!message.content) + throw new IllegalArgumentException("Message body missing"); + + List attachments = db.attachment().getAttachments(message.id); + for (EntityAttachment attachment : attachments) + if (!attachment.available) + throw new IllegalArgumentException("Attachment missing"); + // Append message MimeMessage imessage = MessageHelper.from(this, message, isession); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9f5750e8b8..06f54d1ac6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -306,6 +306,7 @@ An outdated app sent a file path instead of a file stream Contact picker not available No internet connection + Moving across accounts requires all message content to be downloaded Raw message saved Attachment saved Attachments saved