From 94597ef61b44246aa38b63072ed9a60c26198d8e Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 29 Jun 2020 08:13:57 +0200 Subject: [PATCH] Fixed wakeup with attachments --- .../java/eu/faircode/email/ServiceUI.java | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ServiceUI.java b/app/src/main/java/eu/faircode/email/ServiceUI.java index e83fa09800..0ed3916096 100644 --- a/app/src/main/java/eu/faircode/email/ServiceUI.java +++ b/app/src/main/java/eu/faircode/email/ServiceUI.java @@ -464,14 +464,44 @@ public class ServiceUI extends IntentService { } } else { if (folder.notify) { + List attachments = db.attachment().getAttachments(id); + // A new message ID is needed for a new (wearable) notification db.message().deleteMessage(id); + message.id = null; message.fts = false; message.id = db.message().insertMessage(message); - if (message.content) - EntityMessage.getFile(this, id) - .renameTo(message.getFile(this)); + + if (message.content) { + File source = EntityMessage.getFile(this, id); + File target = message.getFile(this); + try { + Helper.copy(source, target); + } catch (IOException ex) { + Log.e(ex); + db.message().resetMessageContent(message.id); + } + } + + for (EntityAttachment attachment : attachments) { + File source = attachment.getFile(this); + + attachment.id = null; + attachment.message = message.id; + attachment.progress = null; + attachment.id = db.attachment().insertAttachment(attachment); + + if (attachment.available) { + File target = attachment.getFile(this); + try { + Helper.copy(source, target); + } catch (IOException ex) { + Log.e(ex); + db.attachment().setError(attachment.id, Log.formatThrowable(ex, false)); + } + } + } } db.message().setMessageSnoozed(message.id, null); db.message().setMessageUnsnoozed(message.id, true);