From da0f52879808c61157cf7c126b9ca2d7feae212c Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 24 Jun 2019 09:07:43 +0200 Subject: [PATCH] Support moving from/to drafts --- app/src/main/java/eu/faircode/email/Core.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index df55382820..a070ceca6e 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -591,7 +591,25 @@ class Core { throw new FolderNotFoundException(); IMAPFolder itarget = (IMAPFolder) istore.getFolder(target.name); - ifolder.copyMessages(new Message[]{imessage}, itarget); + if (EntityFolder.DRAFTS.equals(folder.type) || EntityFolder.DRAFTS.equals(target.type)) { + Log.i(folder.name + " move from " + folder.type + " to " + target.type); + + File file = message.getRawFile(context); + try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) { + imessage.writeTo(os); + } + + Message icopy; + try (InputStream is = new BufferedInputStream(new FileInputStream(file))) { + icopy = new MimeMessage(isession, is); + } + + file.delete(); + + icopy.setFlag(Flags.Flag.DRAFT, EntityFolder.DRAFTS.equals(target.type)); + itarget.appendMessages(new Message[]{icopy}); + } else + ifolder.copyMessages(new Message[]{imessage}, itarget); // Delete source if (!copy) {