Store importance as flag

pull/194/merge
M66B 3 years ago
parent a6691caff4
commit 87ef625c56

@ -5263,7 +5263,24 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
importance = null;
DB db = DB.getInstance(context);
db.message().setMessageImportance(id, importance);
try {
db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
db.message().setMessageImportance(message.id, importance);
EntityOperation.queue(context, message, EntityOperation.KEYWORD,
MessageHelper.FLAG_LOW_IMPORTANCE, EntityMessage.PRIORITIY_LOW.equals(importance));
EntityOperation.queue(context, message, EntityOperation.KEYWORD,
MessageHelper.FLAG_HIGH_IMPORTANCE, EntityMessage.PRIORITIY_HIGH.equals(importance));
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return null;
}

@ -3745,6 +3745,13 @@ class Core {
message.deliveredto = helper.getDeliveredTo();
message.thread = helper.getThreadId(context, account.id, folder.id, uid);
message.priority = helper.getPriority();
for (String keyword : keywords)
if (MessageHelper.FLAG_LOW_IMPORTANCE.equals(keyword))
message.importance = EntityMessage.PRIORITIY_LOW;
else if (MessageHelper.FLAG_HIGH_IMPORTANCE.equals(keyword))
message.importance = EntityMessage.PRIORITIY_HIGH;
message.auto_submitted = helper.getAutoSubmitted();
message.receipt_request = helper.getReceiptRequested();
message.receipt_to = helper.getReceiptTo();

@ -136,8 +136,11 @@ public class EntityOperation {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean auto_important = prefs.getBoolean("auto_important", false);
if (auto_important)
db.message().setMessageImportance(message.id, flagged ? 2 : null);
if (auto_important) {
db.message().setMessageImportance(message.id, flagged ? EntityMessage.PRIORITIY_HIGH : null);
queue(context, message, KEYWORD, MessageHelper.FLAG_LOW_IMPORTANCE, false);
queue(context, message, KEYWORD, MessageHelper.FLAG_HIGH_IMPORTANCE, true);
}
return;
@ -228,8 +231,11 @@ public class EntityOperation {
db.message().setMessageUiSeen(similar.id, true);
if (autounflag)
db.message().setMessageUiFlagged(similar.id, false, null);
if (reset_importance)
if (reset_importance) {
db.message().setMessageImportance(similar.id, null);
queue(context, similar, KEYWORD, MessageHelper.FLAG_LOW_IMPORTANCE, false);
queue(context, similar, KEYWORD, MessageHelper.FLAG_HIGH_IMPORTANCE, false);
}
}
if (source.account.equals(target.account)) {

@ -918,6 +918,11 @@ public class EntityRule {
DB db = DB.getInstance(context);
db.message().setMessageImportance(message.id, importance);
EntityOperation.queue(context, message, EntityOperation.KEYWORD,
MessageHelper.FLAG_LOW_IMPORTANCE, EntityMessage.PRIORITIY_LOW.equals(importance));
EntityOperation.queue(context, message, EntityOperation.KEYWORD,
MessageHelper.FLAG_HIGH_IMPORTANCE, EntityMessage.PRIORITIY_HIGH.equals(importance));
message.importance = importance;
return true;

@ -3639,8 +3639,14 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
List<EntityMessage> messages = db.message().getMessagesByThread(
message.account, message.thread, threading ? null : id, message.folder);
for (EntityMessage threaded : messages)
for (EntityMessage threaded : messages) {
db.message().setMessageImportance(threaded.id, importance);
EntityOperation.queue(context, threaded, EntityOperation.KEYWORD,
MessageHelper.FLAG_LOW_IMPORTANCE, EntityMessage.PRIORITIY_LOW.equals(importance));
EntityOperation.queue(context, threaded, EntityOperation.KEYWORD,
MessageHelper.FLAG_HIGH_IMPORTANCE, EntityMessage.PRIORITIY_HIGH.equals(importance));
}
}
db.setTransactionSuccessful();

@ -27,6 +27,7 @@ import android.net.Uri;
import android.system.ErrnoException;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.net.MailTo;
import androidx.documentfile.provider.DocumentFile;
@ -167,15 +168,19 @@ public class MessageHelper {
static final String FLAG_NOT_DELIVERED = "$NotDelivered";
static final String FLAG_DISPLAYED = "$Displayed";
static final String FLAG_NOT_DISPLAYED = "$NotDisplayed";
static final String FLAG_LOW_IMPORTANCE = "$LowImportance";
static final String FLAG_HIGH_IMPORTANCE = "$HighImportance";
// 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_JUNK,
MessageHelper.FLAG_NOT_JUNK,
MessageHelper.FLAG_CLASSIFIED, // FairEmail
MessageHelper.FLAG_FILTERED, // FairEmail
FLAG_FORWARDED,
FLAG_JUNK,
FLAG_NOT_JUNK,
FLAG_CLASSIFIED, // FairEmail
FLAG_FILTERED, // FairEmail
FLAG_LOW_IMPORTANCE, // FairEmail
FLAG_HIGH_IMPORTANCE, // FairEmail
"$MDNSent", // https://tools.ietf.org/html/rfc3503
"$SubmitPending",
"$Submitted",
@ -1133,6 +1138,7 @@ public class MessageHelper {
return flags.toString();
}
@NonNull
String[] getKeywords() throws MessagingException {
List<String> keywords = Arrays.asList(imessage.getFlags().getUserFlags());
Collections.sort(keywords);

Loading…
Cancel
Save