From bc197f4cf477663f523b7ad755fcd794202ebab5 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 25 Jan 2023 18:55:42 +0100 Subject: [PATCH] Special extra --- .../eu/faircode/email/AdapterMessage.java | 13 ++++++++-- .../java/eu/faircode/email/MessageHelper.java | 25 +++++++++++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 50332f2adf..930fc6709b 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -7981,8 +7981,17 @@ public class AdapterMessage extends RecyclerView.Adapter p = MessageHelper.getExtra(email, extra); + + if (p.first != null) + try { + ((InternetAddress) addresses[0]).setPersonal(p.first); + } catch (Throwable ex) { + Log.e(ex); + } + + if (p.second != null) + ((InternetAddress) addresses[0]).setAddress(p.second); } PagedList getCurrentList() { diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index 13d5d391ed..0cfe9b03a6 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -32,6 +32,7 @@ import android.text.SpannableStringBuilder; import android.text.TextUtils; import android.text.style.ForegroundColorSpan; import android.util.Base64; +import android.util.Pair; import androidx.annotation.NonNull; import androidx.core.net.MailTo; @@ -773,11 +774,16 @@ public class MessageHelper { email != null && message.extra != null) { String username = UriHelper.getEmailUser(identity.email); if (!message.extra.equals(username)) { - email = addExtra(email, message.extra); + Pair extra = getExtra(email, message.extra); - if (!identity.sender_extra_name) + if (extra.first != null) + name = extra.first; + else if (!identity.sender_extra_name) name = null; + if (extra.second != null) + email = extra.second; + Log.i("extra=\"" + name + "\" <" + email + ">"); } } @@ -788,10 +794,19 @@ public class MessageHelper { return new InternetAddress(email, name, StandardCharsets.UTF_8.name()); } - static String addExtra(String email, String extra) { + static Pair getExtra(String email, String extra) { + String name = null; + int comma = extra.indexOf(','); + if (comma >= 0) { + name = extra.substring(0, comma).trim(); + extra = extra.substring(comma + 1).trim(); + if (TextUtils.isEmpty(extra)) + return new Pair<>(name, null); + } + int at = email.indexOf('@'); if (at < 0) - return email; + return new Pair<>(name, email); if (extra.length() > 1 && extra.startsWith("+")) email = email.substring(0, at) + extra + email.substring(at); @@ -800,7 +815,7 @@ public class MessageHelper { else email = extra + email.substring(at); - return email; + return new Pair<>(name, email); } private static void addAddress(String email, Message.RecipientType type, MimeMessage imessage, EntityIdentity identity) throws MessagingException {