Refactoring keywords

This commit is contained in:
M66B 2021-07-01 08:00:04 +02:00
parent 2d8f188cf1
commit 302f34ec44
3 changed files with 43 additions and 29 deletions

View File

@ -311,30 +311,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private static final int MAX_QUOTE_LEVEL = 3;
private static final int MAX_TRANSLATABLE_TEXT_SIZE = 50 * 1024;
// https://www.iana.org/assignments/imap-jmap-keywords/imap-jmap-keywords.xhtml
private static final List<String> 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<AdapterMessage.ViewHold
private SpannableStringBuilder getKeywords(TupleMessageEx message) {
SpannableStringBuilder keywords = new SpannableStringBuilder();
for (int i = 0; i < message.keywords.length; i++) {
String k = message.keywords[i].toLowerCase(Locale.ROOT);
if (!IMAP_KEYWORDS_BLACKLIST.contains(k)) {
if (MessageHelper.showKeyword(message.keywords[i])) {
if (keywords.length() > 0)
keywords.append(" ");

View File

@ -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" +

View File

@ -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<String> 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();