diff --git a/FAQ.md b/FAQ.md
index 8fa186015b..df9640d0c2 100644
--- a/FAQ.md
+++ b/FAQ.md
@@ -678,12 +678,11 @@ Note that this is independent of receiving messages.
**(34) How are identities matched?**
-Identities are matched on e-mail address in this order:
+Identities are as expected matched by account.
+For incoming messages the *to* and *cc* address will be checked and for outgoing messages the *from* addresses will be checked.
+Archived messages will be considered as incoming messages, but additionally the *from* address will be checked.
-1. *Delivered-To* header address
-1. *To* header address
-1. *Cc* header address
-1. *From* header address
+The matched address will be shown as *via* in the addresses section.
Matched identities can be used to color code messages.
The identity color takes precedence over the account color.
diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java
index 87cd2a7f16..391bee44a7 100644
--- a/app/src/main/java/eu/faircode/email/AdapterMessage.java
+++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java
@@ -851,8 +851,8 @@ public class AdapterMessage extends RecyclerView.Adapter addresses = new ArrayList<>();
- if (delivered != null)
- try {
- addresses.add(new InternetAddress(delivered));
- } catch (AddressException ex) {
- // Local address contains control or whitespace in string ``mailing list someone@example.org''
- Log.w(ex);
+ if (folder.isOutgoing()) {
+ if (froms != null)
+ addresses.addAll(Arrays.asList(froms));
+ } else {
+ if (tos != null)
+ addresses.addAll(Arrays.asList(tos));
+ if (ccs != null)
+ addresses.addAll(Arrays.asList(ccs));
+ if (EntityFolder.ARCHIVE.equals(folder.type)) {
+ if (froms != null)
+ addresses.addAll(Arrays.asList(froms));
}
- if (tos != null)
- addresses.addAll(Arrays.asList(tos));
- if (ccs != null)
- addresses.addAll(Arrays.asList(ccs));
- if (froms != null)
- addresses.addAll(Arrays.asList(froms));
+ }
// Search for matching identity
EntityIdentity identity = null;
@@ -1144,7 +1142,8 @@ class Core {
message.references = TextUtils.join(" ", helper.getReferences());
message.inreplyto = helper.getInReplyTo();
- message.deliveredto = delivered;
+ // 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.from = froms;
message.to = tos;
diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java
index 7d8a7dc07b..a61c214c6e 100644
--- a/app/src/main/java/eu/faircode/email/FragmentCompose.java
+++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java
@@ -1717,28 +1717,19 @@ public class FragmentCompose extends FragmentBase {
draft.inreplyto = ref.msgid;
draft.thread = ref.thread;
- // Special case
- if (BuildConfig.DEBUG) {
- String from = null;
- String to = null;
- String delivered = Helper.canonicalAddress(ref.deliveredto);
- String me = Helper.canonicalAddress(Helper.myAddress().getAddress());
-
- if (ref.from != null && ref.from.length > 0)
- from = Helper.canonicalAddress(((InternetAddress) ref.from[0]).getAddress());
- if (ref.to != null && ref.to.length > 0)
- to = Helper.canonicalAddress(((InternetAddress) ref.to[0]).getAddress());
-
- if (delivered.equals(me) && from != null && from.equals(me)) {
- if (to != null && to.equals(me))
- draft.to = ref.reply;
- else
- draft.to = ref.to;
- draft.from = ref.from;
- } else {
- draft.to = (ref.reply == null || ref.reply.length == 0 ? ref.from : ref.reply);
- draft.from = ref.to;
- }
+ // Prevent replying to self
+ String from = null;
+ String via = null;
+ if (ref.from != null && ref.from.length > 0)
+ from = Helper.canonicalAddress(((InternetAddress) ref.from[0]).getAddress());
+ if (ref.identity != null) {
+ EntityIdentity v = db.identity().getIdentity(ref.identity);
+ via = Helper.canonicalAddress(v.email);
+ }
+
+ if (from != null && from.equals(via)) {
+ draft.to = ref.to;
+ draft.from = ref.from;
} else {
draft.to = (ref.reply == null || ref.reply.length == 0 ? ref.from : ref.reply);
draft.from = ref.to;