From 0aaf2e948fb7afe059f54a3c927c4ade77c96fd3 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 6 Aug 2018 20:03:06 +0000 Subject: [PATCH] Move by APPEND/DELETE if no MOVE capability --- .../eu/faircode/email/AdapterAccount.java | 8 ------ app/src/main/java/eu/faircode/email/DB.java | 11 +------- .../java/eu/faircode/email/EntityAccount.java | 2 -- .../eu/faircode/email/FragmentMessage.java | 19 ++----------- .../eu/faircode/email/ServiceSynchronize.java | 28 +++++++++++-------- app/src/main/res/layout/item_account.xml | 12 +------- 6 files changed, 22 insertions(+), 58 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterAccount.java b/app/src/main/java/eu/faircode/email/AdapterAccount.java index 03420328ae..e1bd1138fe 100644 --- a/app/src/main/java/eu/faircode/email/AdapterAccount.java +++ b/app/src/main/java/eu/faircode/email/AdapterAccount.java @@ -21,13 +21,11 @@ package eu.faircode.email; import android.content.Context; import android.content.Intent; -import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.v4.content.LocalBroadcastManager; import android.support.v7.util.DiffUtil; import android.support.v7.util.ListUpdateCallback; import android.support.v7.widget.RecyclerView; -import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -44,7 +42,6 @@ import java.util.Locale; public class AdapterAccount extends RecyclerView.Adapter { private Context context; - private boolean debug; private List all = new ArrayList<>(); private List filtered = new ArrayList<>(); @@ -56,7 +53,6 @@ public class AdapterAccount extends RecyclerView.Adapter() { @Override public void onChanged(@Nullable final TupleMessageEx message) { - if (message == null || (message.ui_hide && !debug)) { + if (message == null || message.ui_hide) { // Message gone (moved, deleted) if (FragmentMessage.this.isVisible()) getFragmentManager().popBackStack(); @@ -266,7 +263,7 @@ public class FragmentMessage extends FragmentEx { db.folder().liveFolders(message.account).removeObservers(FragmentMessage.this); db.folder().liveFolders(message.account).observe(FragmentMessage.this, new Observer>() { @Override - public void onChanged(@Nullable List folders) { + public void onChanged(@Nullable final List folders) { boolean hasTrash = false; boolean hasJunk = false; boolean hasArchive = false; @@ -287,19 +284,9 @@ public class FragmentMessage extends FragmentEx { bottom_navigation.getMenu().findItem(R.id.action_trash).setVisible(hasTrash); bottom_navigation.getMenu().findItem(R.id.action_spam).setVisible(!outbox && hasJunk); - bottom_navigation.getMenu().findItem(R.id.action_move).setVisible(false); + bottom_navigation.getMenu().findItem(R.id.action_move).setVisible(!outbox && (!inbox || hasUser)); bottom_navigation.getMenu().findItem(R.id.action_archive).setVisible(!outbox && hasArchive); bottom_navigation.setVisibility(View.VISIBLE); - - final boolean fHasUser = hasUser; - db.account().liveAccount(message.id).removeObservers(FragmentMessage.this); - db.account().liveAccount(message.account).observe(FragmentMessage.this, new Observer() { - @Override - public void onChanged(@Nullable EntityAccount account) { - boolean move = Arrays.asList(account.capabilities).contains("MOVE"); - bottom_navigation.getMenu().findItem(R.id.action_move).setVisible(!outbox && (!inbox || fHasUser) && move); - } - }); } }); } diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 74aa8a0fb1..0fcec9cf0b 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -336,15 +336,6 @@ public class ServiceSynchronize extends LifecycleService { try { DB db = DB.getInstance(ServiceSynchronize.this); - List capabilities = new ArrayList<>(); - if (fstore.hasCapability("IDLE")) - capabilities.add("IDLE"); - if (fstore.hasCapability("MOVE")) - capabilities.add("MOVE"); - account.capabilities = capabilities.toArray(new String[0]); - db.account().updateAccount(account); - Log.i(Helper.TAG, "capabilities=" + TextUtils.join(",", capabilities)); - synchronizeFolders(account, fstore); for (final EntityFolder folder : db.folder().getFolders(account.id, true)) { @@ -739,7 +730,22 @@ public class ServiceSynchronize extends LifecycleService { throw new MessageRemovedException(); Folder itarget = istore.getFolder(target.name); - ifolder.moveMessages(new Message[]{imessage}, itarget); + if (istore.hasCapability("MOVE")) + ifolder.moveMessages(new Message[]{imessage}, itarget); + else { + Log.i(Helper.TAG, "MOVE by APPEND/DELETE"); + EntityMessage msg = message.getMessage(op.message); + + // Execute append + Properties props = MessageHelper.getSessionProperties(); + Session isession = Session.getInstance(props, null); + MimeMessage icopy = MessageHelper.from(msg, isession); + itarget.appendMessages(new Message[]{icopy}); + + // Execute delete + imessage.setFlag(Flags.Flag.DELETED, true); + ifolder.expunge(); + } message.deleteMessage(op.message); @@ -872,7 +878,7 @@ public class ServiceSynchronize extends LifecycleService { } catch (NullPointerException ex) { Log.w(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); - // There is probably no use in repeating + // There is no use in repeating operation.deleteOperation(op.id); reportError(null, folder.name, ex); } diff --git a/app/src/main/res/layout/item_account.xml b/app/src/main/res/layout/item_account.xml index 2848a4d7b1..ce603f4e68 100644 --- a/app/src/main/res/layout/item_account.xml +++ b/app/src/main/res/layout/item_account.xml @@ -61,16 +61,6 @@ app:layout_constraintStart_toEndOf="@id/tvHost" app:layout_constraintTop_toBottomOf="@id/ivSync" /> - - + app:layout_constraintTop_toBottomOf="@id/tvHost" /> \ No newline at end of file