From 302f34ec4439a0b478415b3eb1ad1cec9626dd97 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 1 Jul 2021 08:00:04 +0200 Subject: [PATCH] Refactoring keywords --- .../eu/faircode/email/AdapterMessage.java | 27 +----------- app/src/main/java/eu/faircode/email/Core.java | 4 +- .../java/eu/faircode/email/MessageHelper.java | 41 ++++++++++++++++++- 3 files changed, 43 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index e1cb33cbe3..8b0873a143 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -311,30 +311,6 @@ public class AdapterMessage extends RecyclerView.Adapter IMAP_KEYWORDS_BLACKLIST = Collections.unmodifiableList(Arrays.asList( - MessageHelper.FLAG_FORWARDED.toLowerCase(Locale.ROOT), - "$MDNSent".toLowerCase(Locale.ROOT), // https://tools.ietf.org/html/rfc3503 - "$SubmitPending".toLowerCase(Locale.ROOT), - "$Submitted".toLowerCase(Locale.ROOT), - "$Junk".toLowerCase(Locale.ROOT), - "$NotJunk".toLowerCase(Locale.ROOT), - "Junk".toLowerCase(Locale.ROOT), - "NonJunk".toLowerCase(Locale.ROOT), - "$recent".toLowerCase(Locale.ROOT), - "DTAG_document".toLowerCase(Locale.ROOT), - "DTAG_image".toLowerCase(Locale.ROOT), - "$X-Me-Annot-1".toLowerCase(Locale.ROOT), - "$X-Me-Annot-2".toLowerCase(Locale.ROOT), - "\\Unseen".toLowerCase(Locale.ROOT), // Mail.ru - "$sent".toLowerCase(Locale.ROOT), // Kmail - "$attachment".toLowerCase(Locale.ROOT), // Kmail - "$signed".toLowerCase(Locale.ROOT), // Kmail - "$encrypted".toLowerCase(Locale.ROOT), // Kmail - "$Classified".toLowerCase(Locale.ROOT), - "$HasNoAttachment".toLowerCase(Locale.ROOT) - )); - public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener, @@ -5332,8 +5308,7 @@ public class AdapterMessage extends RecyclerView.Adapter 0) keywords.append(" "); diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 71e4febcb5..0eab25378c 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -1272,7 +1272,7 @@ class Core { // Mark not spam if (EntityFolder.JUNK.equals(folder.type) && ifolder.getPermanentFlags().contains(Flags.Flag.USER)) { - Flags notJunk = new Flags("$NotJunk"); + Flags notJunk = new Flags(MessageHelper.FLAG_NOT_JUNK); imessage.setFlags(notJunk, true); } } @@ -3414,7 +3414,7 @@ class Core { !EntityFolder.TRASH.equals(folder.type) && !EntityFolder.JUNK.equals(folder.type) && message.blocklist != null && message.blocklist && - !Arrays.asList(message.keywords).contains("$NotJunk")) { + !Arrays.asList(message.keywords).contains(MessageHelper.FLAG_NOT_JUNK)) { boolean use_blocklist = prefs.getBoolean("use_blocklist", false); if (use_blocklist) { EntityLog.log(context, "Block list" + diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index b26cde257e..6b04dcfd21 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -121,7 +121,6 @@ public class MessageHelper { static final int SMALL_MESSAGE_SIZE = 192 * 1024; // bytes static final int DEFAULT_DOWNLOAD_SIZE = 4 * 1024 * 1024; // bytes static final String HEADER_CORRELATION_ID = "X-Correlation-ID"; - static final String FLAG_FORWARDED = "$Forwarded"; private static final int MAX_HEADER_LENGTH = 998; private static final int MAX_MESSAGE_SIZE = 10 * 1024 * 1024; // bytes @@ -135,6 +134,34 @@ public class MessageHelper { StandardCharsets.UTF_16LE )); + static final String FLAG_FORWARDED = "$Forwarded"; + static final String FLAG_NOT_JUNK = "$NotJunk"; + + // https://www.iana.org/assignments/imap-jmap-keywords/imap-jmap-keywords.xhtml + // Not black listed: Gmail $Phishing + private static final List FLAG_BLACKLIST = Collections.unmodifiableList(Arrays.asList( + MessageHelper.FLAG_FORWARDED, + MessageHelper.FLAG_NOT_JUNK, + "$MDNSent", // https://tools.ietf.org/html/rfc3503 + "$SubmitPending", + "$Submitted", + "$Junk", + "Junk", + "NonJunk", + "$recent", + "DTAG_document", + "DTAG_image", + "$X-Me-Annot-1", + "$X-Me-Annot-2", + "\\Unseen", // Mail.ru + "$sent", // Kmail + "$attachment", // Kmail + "$signed", // Kmail + "$encrypted", // Kmail + "$HasNoAttachment", + "$Classified" // FairEmail + )); + // https://tools.ietf.org/html/rfc4021 static void setSystemProperties(Context context) { @@ -915,6 +942,18 @@ public class MessageHelper { return keywords.toArray(new String[0]); } + static boolean showKeyword(String keyword) { + if (BuildConfig.DEBUG) + return true; + + int len = FLAG_BLACKLIST.size(); + for (int i = 0; i < len; i++) + if (FLAG_BLACKLIST.get(i).equalsIgnoreCase(keyword)) + return false; + + return true; + } + String getMessageID() throws MessagingException { ensureEnvelope();