mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-05 08:33:37 +02:00
Added message priority
This commit is contained in:
@@ -254,6 +254,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
private TextView tvSize;
|
||||
private TextView tvTime;
|
||||
private ImageView ivType;
|
||||
private ImageView ivPriority;
|
||||
private ImageView ibAuth;
|
||||
private ImageView ibSnoozed;
|
||||
private ImageView ivBrowsed;
|
||||
@@ -365,6 +366,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
tvSize = itemView.findViewById(R.id.tvSize);
|
||||
tvTime = itemView.findViewById(R.id.tvTime);
|
||||
ivType = itemView.findViewById(R.id.ivType);
|
||||
ivPriority = itemView.findViewById(R.id.ivPriority);
|
||||
ibAuth = itemView.findViewById(R.id.ibAuth);
|
||||
ibSnoozed = itemView.findViewById(R.id.ibSnoozed);
|
||||
ivBrowsed = itemView.findViewById(R.id.ivBrowsed);
|
||||
@@ -611,6 +613,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
tvSize.setText(null);
|
||||
tvTime.setText(null);
|
||||
ivType.setVisibility(View.GONE);
|
||||
ivPriority.setVisibility(View.GONE);
|
||||
ibAuth.setVisibility(View.GONE);
|
||||
ibSnoozed.setVisibility(View.GONE);
|
||||
ivBrowsed.setVisibility(View.GONE);
|
||||
@@ -677,6 +680,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
tvSize.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
|
||||
tvTime.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
|
||||
ivType.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
|
||||
ivPriority.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
|
||||
ibAuth.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
|
||||
ibSnoozed.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
|
||||
ivBrowsed.setAlpha(dim ? Helper.LOW_LIGHT : 1.0f);
|
||||
@@ -763,6 +767,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
(viewType == ViewType.THREAD && EntityFolder.SENT.equals(message.folderType))
|
||||
? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
ivPriority.setVisibility(EntityMessage.PRIORITIY_HIGH.equals(message.priority) ? View.VISIBLE : View.GONE);
|
||||
ibAuth.setVisibility(authentication && !authenticated ? View.VISIBLE : View.GONE);
|
||||
ibSnoozed.setVisibility(message.ui_snoozed == null ? View.GONE : View.VISIBLE);
|
||||
ivBrowsed.setVisibility(message.ui_browsed ? View.VISIBLE : View.GONE);
|
||||
|
||||
@@ -1424,6 +1424,7 @@ class Core {
|
||||
message.inreplyto = helper.getInReplyTo();
|
||||
message.deliveredto = helper.getDeliveredTo();
|
||||
message.thread = helper.getThreadId(context, account.id, 0);
|
||||
message.priority = helper.getPriority();
|
||||
message.receipt_request = helper.getReceiptRequested();
|
||||
message.receipt_to = helper.getReceiptTo();
|
||||
message.dkim = MessageHelper.getAuthentication("dkim", authentication);
|
||||
@@ -2042,6 +2043,7 @@ class Core {
|
||||
// Local address contains control or whitespace in string ``mailing list someone@example.org''
|
||||
message.deliveredto = helper.getDeliveredTo();
|
||||
message.thread = helper.getThreadId(context, account.id, uid);
|
||||
message.priority = helper.getPriority();
|
||||
message.receipt_request = helper.getReceiptRequested();
|
||||
message.receipt_to = helper.getReceiptTo();
|
||||
message.dkim = MessageHelper.getAuthentication("dkim", authentication);
|
||||
|
||||
@@ -58,7 +58,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
|
||||
// https://developer.android.com/topic/libraries/architecture/room.html
|
||||
|
||||
@Database(
|
||||
version = 104,
|
||||
version = 105,
|
||||
entities = {
|
||||
EntityIdentity.class,
|
||||
EntityAccount.class,
|
||||
@@ -1034,6 +1034,13 @@ public abstract class DB extends RoomDatabase {
|
||||
db.execSQL("UPDATE `message` SET ui_hide = 1 WHERE ui_hide <> 0");
|
||||
}
|
||||
})
|
||||
.addMigrations(new Migration(104, 105) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("ALTER TABLE `message` ADD COLUMN `priority` INTEGER");
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -364,6 +364,9 @@ public interface DaoMessage {
|
||||
@Query("UPDATE message SET msgid = :msgid WHERE id = :id")
|
||||
int setMessageMsgId(long id, String msgid);
|
||||
|
||||
@Query("UPDATE message SET priority = :priority WHERE id = :id")
|
||||
int setMessagePriority(long id, Integer priority);
|
||||
|
||||
@Query("UPDATE message SET notifying = :notifying WHERE id = :id")
|
||||
int setMessageNotifying(long id, int notifying);
|
||||
|
||||
|
||||
@@ -78,6 +78,10 @@ import static androidx.room.ForeignKey.SET_NULL;
|
||||
public class EntityMessage implements Serializable {
|
||||
static final String TABLE_NAME = "message";
|
||||
|
||||
static final Integer PRIORITIY_LOW = 0;
|
||||
static final Integer PRIORITIY_NORMAL = 1;
|
||||
static final Integer PRIORITIY_HIGH = 2;
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
public Long id;
|
||||
@NonNull
|
||||
@@ -94,6 +98,7 @@ public class EntityMessage implements Serializable {
|
||||
public String deliveredto;
|
||||
public String inreplyto;
|
||||
public String thread; // compose = null
|
||||
public Integer priority;
|
||||
public Boolean receipt_request;
|
||||
public Address[] receipt_to;
|
||||
public Boolean dkim;
|
||||
|
||||
@@ -3435,6 +3435,7 @@ public class FragmentCompose extends FragmentBase {
|
||||
final CheckBox cbEncrypt = dview.findViewById(R.id.cbEncrypt);
|
||||
final TextView tvSendAt = dview.findViewById(R.id.tvSendAt);
|
||||
final ImageButton ibSendAt = dview.findViewById(R.id.ibSendAt);
|
||||
final Spinner spPriority = dview.findViewById(R.id.spPriority);
|
||||
final TextView tvRemindSubject = dview.findViewById(R.id.tvRemindSubject);
|
||||
final TextView tvRemindAttachment = dview.findViewById(R.id.tvRemindAttachment);
|
||||
final CheckBox cbNotAgain = dview.findViewById(R.id.cbNotAgain);
|
||||
@@ -3443,6 +3444,8 @@ public class FragmentCompose extends FragmentBase {
|
||||
tvTo.setText(null);
|
||||
tvVia.setText(null);
|
||||
tvSendAt.setText(null);
|
||||
spPriority.setTag(1);
|
||||
spPriority.setSelection(1);
|
||||
tvRemindSubject.setVisibility(remind_subject ? View.VISIBLE : View.GONE);
|
||||
tvRemindAttachment.setVisibility(remind_attachment ? View.VISIBLE : View.GONE);
|
||||
cbNotAgain.setChecked(!send_dialog);
|
||||
@@ -3487,6 +3490,10 @@ public class FragmentCompose extends FragmentBase {
|
||||
DateFormat D = new SimpleDateFormat("E");
|
||||
tvSendAt.setText(D.format(draft.ui_snoozed) + " " + DTF.format(draft.ui_snoozed));
|
||||
}
|
||||
|
||||
int priority = (draft.priority == null ? 1 : draft.priority);
|
||||
spPriority.setTag(priority);
|
||||
spPriority.setSelection(priority);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3558,6 +3565,47 @@ public class FragmentCompose extends FragmentBase {
|
||||
}
|
||||
});
|
||||
|
||||
spPriority.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
int last = (int) spPriority.getTag();
|
||||
if (last != position) {
|
||||
spPriority.setTag(position);
|
||||
setPriority(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
spPriority.setTag(1);
|
||||
setPriority(1);
|
||||
}
|
||||
|
||||
private void setPriority(int priority) {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", id);
|
||||
args.putInt("priority", priority);
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
int priority = args.getInt("priority");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
db.message().setMessagePriority(id, priority);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Helper.unexpectedError(getFragmentManager(), ex);
|
||||
}
|
||||
}.execute(FragmentDialogSend.this, args, "compose:priority");
|
||||
}
|
||||
});
|
||||
|
||||
return new AlertDialog.Builder(getContext())
|
||||
.setView(dview)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
|
||||
@@ -119,6 +119,20 @@ public class MessageHelper {
|
||||
DB db = DB.getInstance(context);
|
||||
MimeMessageEx imessage = new MimeMessageEx(isession, message.msgid);
|
||||
|
||||
if (EntityMessage.PRIORITIY_LOW.equals(message.priority)) {
|
||||
// Low
|
||||
imessage.addHeader("Importance", "Low");
|
||||
imessage.addHeader("Priority", "Non-Urgent");
|
||||
imessage.addHeader("X-Priority", "5"); // Lowest
|
||||
imessage.addHeader("X-MSMail-Priority", "Low");
|
||||
} else if (EntityMessage.PRIORITIY_HIGH.equals(message.priority)) {
|
||||
// High
|
||||
imessage.addHeader("Importance", "High");
|
||||
imessage.addHeader("Priority", "Urgent");
|
||||
imessage.addHeader("X-Priority", "1"); // Highest
|
||||
imessage.addHeader("X-MSMail-Priority", "High");
|
||||
}
|
||||
|
||||
if (message.references != null)
|
||||
imessage.addHeader("References", message.references);
|
||||
if (message.inreplyto != null)
|
||||
@@ -456,6 +470,43 @@ public class MessageHelper {
|
||||
return (TextUtils.isEmpty(msgid) ? Long.toString(uid) : msgid);
|
||||
}
|
||||
|
||||
Integer getPriority() throws MessagingException {
|
||||
Integer priority = null;
|
||||
|
||||
// https://docs.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxcmail/2bb19f1b-b35e-4966-b1cb-1afd044e83ab
|
||||
String header = imessage.getHeader("Importance", null);
|
||||
if (header == null)
|
||||
header = imessage.getHeader("Priority", null);
|
||||
if (header == null)
|
||||
header = imessage.getHeader("X-Priority", null);
|
||||
if (header == null)
|
||||
header = imessage.getHeader("X-MSMail-Priority", null);
|
||||
|
||||
if ("high".equalsIgnoreCase(header) || "urgent".equalsIgnoreCase(header))
|
||||
priority = EntityMessage.PRIORITIY_HIGH;
|
||||
else if ("normal".equalsIgnoreCase(header) || "medium".equalsIgnoreCase(header))
|
||||
priority = EntityMessage.PRIORITIY_NORMAL;
|
||||
else if ("low".equalsIgnoreCase(header) || "non-urgent".equalsIgnoreCase(header))
|
||||
priority = EntityMessage.PRIORITIY_LOW;
|
||||
else if (header != null)
|
||||
try {
|
||||
priority = Integer.parseInt(header);
|
||||
if (priority < 3)
|
||||
priority = EntityMessage.PRIORITIY_HIGH;
|
||||
else if (priority > 3)
|
||||
priority = EntityMessage.PRIORITIY_LOW;
|
||||
else
|
||||
priority = EntityMessage.PRIORITIY_NORMAL;
|
||||
} catch (NumberFormatException ex) {
|
||||
Log.e("priority=" + header);
|
||||
}
|
||||
|
||||
if (EntityMessage.PRIORITIY_NORMAL.equals(priority))
|
||||
priority = null;
|
||||
|
||||
return priority;
|
||||
}
|
||||
|
||||
boolean getReceiptRequested() throws MessagingException {
|
||||
return (imessage.getHeader("Return-Receipt-To") != null ||
|
||||
imessage.getHeader("Disposition-Notification-To") != null);
|
||||
|
||||
Reference in New Issue
Block a user