From 4c201287156a53154aec9d5bfe465a7615e92feb Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 13 Dec 2020 15:57:12 +0100 Subject: [PATCH] Match delivered-to as last --- FAQ.md | 1 + app/src/main/java/eu/faircode/email/Core.java | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/FAQ.md b/FAQ.md index 1aa9c35550..e98c302640 100644 --- a/FAQ.md +++ b/FAQ.md @@ -1318,6 +1318,7 @@ Note that this is independent of receiving messages. Identities are as expected matched by account. For incoming messages the *to*, *cc*, *bcc*, *from* and *(X-)delivered/envelope/original-to* addresses will be checked (in this order) and for outgoing messages (drafts, outbox and sent) only the *from* addresses will be checked. +Equal addresses have precedence over partially matching addresses, except for *delivered-to* addresses. The matched address will be shown as *via* in the addresses section of received messages (between the message header and message text). diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index a0502f976b..5cbd7b5869 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -3113,14 +3113,16 @@ class Core { addresses.addAll(Arrays.asList(message.bcc)); if (message.from != null) addresses.addAll(Arrays.asList(message.from)); - if (message.deliveredto != null) - try { - addresses.add(new InternetAddress(message.deliveredto)); - } catch (AddressException ex) { - Log.w(ex); - } } + InternetAddress deliveredto = null; + if (message.deliveredto != null) + try { + deliveredto = new InternetAddress(message.deliveredto); + } catch (AddressException ex) { + Log.w(ex); + } + // Search for matching identity List identities = db.identity().getSynchronizingIdentities(folder.account); if (identities != null) { @@ -3133,6 +3135,11 @@ class Core { for (EntityIdentity identity : identities) if (identity.similarAddress(address)) return identity; + + if (deliveredto != null) + for (EntityIdentity identity : identities) + if (identity.sameAddress(deliveredto) || identity.similarAddress(deliveredto)) + return identity; } return null;