diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 8e63b90966..40f90fd079 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -708,17 +708,10 @@ class Core { ((GmailMessage) imessage).setLabels(new String[]{label}, set); // Gmail does not push label changes - - List labels = new ArrayList<>(); - if (message.labels != null) - labels.addAll(Arrays.asList(message.labels)); - labels.remove(label); - if (set) - labels.add(label); + message.setLabel(label, set); DB db = DB.getInstance(context); - db.message().setMessageLabels(message.id, - DB.Converters.fromStringArray(labels.toArray(new String[0]))); + db.message().setMessageLabels(message.id, DB.Converters.fromStringArray(message.labels)); } private static void onAdd(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPStore istore, IMAPFolder ifolder, State state) throws MessagingException, IOException { diff --git a/app/src/main/java/eu/faircode/email/EntityMessage.java b/app/src/main/java/eu/faircode/email/EntityMessage.java index 6c80af8851..9ffe19eaee 100644 --- a/app/src/main/java/eu/faircode/email/EntityMessage.java +++ b/app/src/main/java/eu/faircode/email/EntityMessage.java @@ -244,6 +244,16 @@ public class EntityMessage implements Serializable { return "notification." + sender.getAddress().toLowerCase(Locale.ROOT); } + void setLabel(String label, boolean set) { + List list = new ArrayList<>(); + if (labels != null) + list.addAll(Arrays.asList(labels)); + list.remove(label); + if (set) + list.add(label); + labels = list.toArray(new String[0]); + } + static File getFile(Context context, Long id) { File dir = new File(context.getFilesDir(), "messages"); if (!dir.exists())