From 458997e4fa73adf7858070730e55eb02b73fc002 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 28 Jul 2024 09:47:51 +0200 Subject: [PATCH] Prevent NPE --- app/src/main/java/eu/faircode/email/Core.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index d1c84a11cf..07b773f25f 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -1815,21 +1815,24 @@ class Core { IMAPFolder itrash = (IMAPFolder) istore.getFolder(trash.name); Message[] imessages = ifolder.getMessagesByUID(Helper.toLongArray(uids)); - for (Message imessage : imessages) - if (imessage instanceof GmailMessage) - try { - String[] labels = ((GmailMessage) imessage).getLabels(); - for (String label : labels) - if (!folders.containsKey(label)) { - EntityFolder f = db.folder().getFolderByName(account.id, label); - if (f != null) - folders.put(f.name, f.id); - } - } catch (Throwable ex) { - Log.e(ex); - } + List imove = new ArrayList<>(); + if (imessages != null) + for (Message imessage : imessages) + if (imessage instanceof GmailMessage) + try { + imove.add(imessage); + String[] labels = ((GmailMessage) imessage).getLabels(); + for (String label : labels) + if (!folders.containsKey(label)) { + EntityFolder f = db.folder().getFolderByName(account.id, label); + if (f != null) + folders.put(f.name, f.id); + } + } catch (Throwable ex) { + Log.e(ex); + } - ifolder.moveMessages(imessages, itrash); + ifolder.moveMessages(imove.toArray(new Message[0]), itrash); itrash.open(READ_WRITE); try {