Added message copy

pull/152/head
M66B 6 years ago
parent 3d29e414a4
commit ec16e3b65c

@ -30,7 +30,7 @@ For authorizing:
* ~~Synchronize on demand (manual)~~
* ~~Semi-automatic encryption~~
* Add message copy
* ~~Copy message~~
Anything on this list is in random order and *might* be added in the near future.
@ -188,6 +188,7 @@ The low priority status bar notification shows the number of pending operations,
* *add*: add message to remote folder
* *move*: move message to another remote folder
* *copy*: copy message to another remote folder
* *delete*: delete message from remote folder
* *send*: send message
* *seen*: mark message as read/unread in remote folder

@ -1803,6 +1803,89 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
private void onMenuCopy(final ActionData data) {
Bundle args = new Bundle();
args.putLong("id", data.message.id);
new SimpleTask<List<EntityFolder>>() {
@Override
protected List<EntityFolder> onExecute(Context context, Bundle args) {
DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(args.getLong("id"));
if (message == null)
return null;
List<EntityFolder> folders = db.folder().getFolders(message.account);
if (folders == null)
return null;
EntityFolder.sort(context, folders);
return folders;
}
@Override
protected void onExecuted(final Bundle args, List<EntityFolder> folders) {
if (folders == null)
return;
View anchor = bnvActions.findViewById(R.id.action_more);
PopupMenu popupMenu = new PopupMenu(context, anchor);
int order = 0;
for (EntityFolder folder : folders)
popupMenu.getMenu().add(Menu.NONE, folder.id.intValue(), order++, folder.getDisplayName(context));
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem target) {
args.putLong("target", target.getItemId());
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
long target = args.getLong("target");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
EntityOperation.queue(context, db, message, EntityOperation.COPY, target);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, owner, ex);
}
}.execute(context, owner, args, "message:copy");
return true;
}
});
popupMenu.show();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, owner, ex);
}
}.execute(context, owner, args, "message:copy:list");
}
private void onMenuDelete(final ActionData data) {
Bundle args = new Bundle();
args.putLong("id", data.message.id);
@ -2165,6 +2248,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
popupMenu.getMenu().findItem(R.id.menu_unseen).setEnabled(data.message.uid != null);
popupMenu.getMenu().findItem(R.id.menu_copy).setEnabled(data.message.uid != null);
popupMenu.getMenu().findItem(R.id.menu_delete).setVisible(debug);
popupMenu.getMenu().findItem(R.id.menu_junk).setEnabled(data.message.uid != null);
@ -2200,6 +2284,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
case R.id.menu_snooze:
onMenuSnooze(data);
return true;
case R.id.menu_copy:
onMenuCopy(data);
return true;
case R.id.menu_delete:
// For emergencies
onMenuDelete(data);

@ -160,7 +160,11 @@ class Core {
break;
case EntityOperation.MOVE:
onMove(context, jargs, folder, message, isession, (IMAPStore) istore, (IMAPFolder) ifolder);
onMove(context, jargs, false, folder, message, isession, (IMAPStore) istore, (IMAPFolder) ifolder);
break;
case EntityOperation.COPY:
onMove(context, jargs, true, folder, message, isession, (IMAPStore) istore, (IMAPFolder) ifolder);
break;
case EntityOperation.DELETE:
@ -444,7 +448,7 @@ class Core {
}
}
private static void onMove(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, Session isession, IMAPStore istore, IMAPFolder ifolder) throws JSONException, MessagingException, IOException {
private static void onMove(Context context, JSONArray jargs, boolean copy, EntityFolder folder, EntityMessage message, Session isession, IMAPStore istore, IMAPFolder ifolder) throws JSONException, MessagingException, IOException {
// Move message
DB db = DB.getInstance(context);
@ -452,9 +456,6 @@ class Core {
if (imessage == null)
throw new MessageRemovedException();
// Get parameters
boolean autoread = jargs.getBoolean(1);
// Get target folder
long id = jargs.getLong(0);
EntityFolder target = db.folder().getFolder(id);
@ -462,8 +463,10 @@ class Core {
throw new FolderNotFoundException();
IMAPFolder itarget = (IMAPFolder) istore.getFolder(target.name);
boolean autoread = (jargs.length() > 1 && jargs.getBoolean(1));
boolean canMove = istore.hasCapability("MOVE");
if (canMove &&
if (!copy && canMove &&
!EntityFolder.DRAFTS.equals(folder.type) &&
!EntityFolder.DRAFTS.equals(target.type)) {
// Autoread
@ -474,8 +477,9 @@ class Core {
// Move message to
ifolder.moveMessages(new Message[]{imessage}, itarget);
} else {
Log.w(folder.name + " MOVE by DELETE/APPEND" +
" cap=" + canMove + " from=" + folder.type + " to=" + target.type);
if (!copy)
Log.w(folder.name + " MOVE by DELETE/APPEND" +
" cap=" + canMove + " from=" + folder.type + " to=" + target.type);
// Serialize source message
ByteArrayOutputStream bos = new ByteArrayOutputStream();
@ -486,7 +490,7 @@ class Core {
Message icopy = new MimeMessage(isession, bis);
// Make sure the message has a message ID
if (message.msgid == null) {
if (copy || message.msgid == null) {
String msgid = EntityMessage.generateMessageId();
Log.i(target.name + " generated message id=" + msgid);
icopy.setHeader("Message-ID", msgid);
@ -540,8 +544,10 @@ class Core {
}
// Delete source
imessage.setFlag(Flags.Flag.DELETED, true);
ifolder.expunge();
if (!copy) {
imessage.setFlag(Flags.Flag.DELETED, true);
ifolder.expunge();
}
} catch (Throwable ex) {
if (itarget.isOpen())
itarget.close();

@ -70,6 +70,7 @@ public class EntityOperation {
static final String ADD = "add";
static final String MOVE = "move";
static final String COPY = "copy";
static final String DELETE = "delete";
static final String SEND = "send";
static final String SEEN = "seen";

@ -12,6 +12,10 @@
android:id="@+id/menu_snooze"
android:title="@string/title_snooze" />
<item
android:id="@+id/menu_copy"
android:title="@string/title_copy" />
<item
android:id="@+id/menu_delete"
android:title="@string/title_delete" />

@ -329,6 +329,7 @@
<string name="title_show_html">Show original</string>
<string name="title_trash">Trash</string>
<string name="title_copy">Copy &#8230;</string>
<string name="title_delete">Delete</string>
<string name="title_more">More</string>
<string name="title_spam">Spam</string>

Loading…
Cancel
Save