diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 8d586de616..4845c70ae9 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -648,6 +648,9 @@ public class AdapterMessage extends RecyclerView.Adapter() { @Override protected void onPreExecute(Bundle args) { - Address[] addresses = (Address[]) args.getSerializable("addresses"); + //Address[] addresses = (Address[]) args.getSerializable("addresses"); ivAvatar.setVisibility(View.GONE); - tvFrom.setText(MessageHelper.formatAddresses(addresses, !compact, false)); + //tvFrom.setText(MessageHelper.formatAddresses(addresses, !compact, false)); } @Override @@ -883,7 +884,7 @@ public class AdapterMessage extends RecyclerView.Adapter result = new ArrayList<>(); try { - JSONArray jaddresses = new JSONArray(json); + JSONArray jroot = new JSONArray(json); + JSONArray jaddresses = new JSONArray(); + for (int i = 0; i < jroot.length(); i++) { + Object item = jroot.get(i); + if (jroot.get(i) instanceof JSONArray) + for (int j = 0; j < ((JSONArray) item).length(); j++) + jaddresses.put(((JSONArray) item).get(j)); + else + jaddresses.put(item); + } for (int i = 0; i < jaddresses.length(); i++) { JSONObject jaddress = (JSONObject) jaddresses.get(i); if (jaddress.has("personal")) diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index b3a2774979..279d244b0b 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -42,6 +42,7 @@ public interface DaoMessage { ", account.name AS accountName, IFNULL(identity.color, account.color) AS accountColor, account.notify AS accountNotify" + ", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType, folder.read_only AS folderReadOnly" + ", identity.name AS identityName, identity.email AS identityEmail, identity.synchronize AS identitySynchronize" + + ", '[' || group_concat(message.`from`, ',') || ']' AS senders" + ", COUNT(message.id) AS count" + ", SUM(1 - message.ui_seen) AS unseen" + ", SUM(1 - message.ui_flagged) AS unflagged" + @@ -53,7 +54,7 @@ public interface DaoMessage { " OR (NOT :found AND :type IS NULL AND folder.unified)" + " OR (NOT :found AND folder.type = :type))" + " THEN message.received ELSE 0 END) AS dummy" + - " FROM message" + + " FROM (SELECT * FROM message ORDER BY received DESC) AS message" + " JOIN account ON account.id = message.account" + " LEFT JOIN identity ON identity.id = message.identity" + " JOIN folder ON folder.id = message.folder" + @@ -91,6 +92,7 @@ public interface DaoMessage { ", account.name AS accountName, IFNULL(identity.color, account.color) AS accountColor, account.notify AS accountNotify" + ", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType, folder.read_only AS folderReadOnly" + ", identity.name AS identityName, identity.email AS identityEmail, identity.synchronize AS identitySynchronize" + + ", '[' || group_concat(message.`from`, ',') || ']' AS senders" + ", COUNT(message.id) AS count" + ", SUM(1 - message.ui_seen) AS unseen" + ", SUM(1 - message.ui_flagged) AS unflagged" + @@ -98,7 +100,7 @@ public interface DaoMessage { ", COUNT(DISTINCT CASE WHEN message.msgid IS NULL THEN message.id ELSE message.msgid END) AS visible" + ", SUM(message.size) AS totalSize" + ", MAX(CASE WHEN folder.id = :folder THEN message.received ELSE 0 END) AS dummy" + - " FROM message" + + " FROM (SELECT * FROM message ORDER BY received DESC) AS message" + " JOIN account ON account.id = message.account" + " LEFT JOIN identity ON identity.id = message.identity" + " JOIN folder ON folder.id = message.folder" + @@ -132,6 +134,7 @@ public interface DaoMessage { ", account.name AS accountName, IFNULL(identity.color, account.color) AS accountColor, account.notify AS accountNotify" + ", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType, folder.read_only AS folderReadOnly" + ", identity.name AS identityName, identity.email AS identityEmail, identity.synchronize AS identitySynchronize" + + ", message.`from` AS senders" + ", 1 AS count" + ", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" + ", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" + @@ -230,6 +233,7 @@ public interface DaoMessage { ", account.name AS accountName, identity.color AS accountColor, account.notify AS accountNotify" + ", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType, folder.read_only AS folderReadOnly" + ", identity.name AS identityName, identity.email AS identityEmail, identity.synchronize AS identitySynchronize" + + ", message.`from` AS senders" + ", 1 AS count" + ", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" + ", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" + @@ -247,6 +251,7 @@ public interface DaoMessage { ", account.name AS accountName, IFNULL(identity.color, account.color) AS accountColor, account.notify AS accountNotify" + ", folder.name AS folderName, folder.display AS folderDisplay, folder.type AS folderType, folder.read_only AS folderReadOnly" + ", identity.name AS identityName, identity.email AS identityEmail, identity.synchronize AS identitySynchronize" + + ", message.`from` AS senders" + ", 1 AS count" + ", 1 AS unseen" + ", 0 AS unflagged" + diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index 6393f8b4b2..9599d1b2b2 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -599,17 +599,26 @@ public class MessageHelper { return ""; List formatted = new ArrayList<>(); - for (Address address : addresses) - if (address instanceof InternetAddress) { - InternetAddress a = (InternetAddress) address; - String personal = a.getPersonal(); + for (int i = 0; i < addresses.length; i++) { + boolean duplicate = false; + for (int j = 0; j < i; j++) + if (addresses[i].equals(addresses[j])) { + duplicate = true; + break; + } + if (duplicate) + continue; + + if (addresses[i] instanceof InternetAddress) { + InternetAddress address = (InternetAddress) addresses[i]; + String personal = address.getPersonal(); if (TextUtils.isEmpty(personal)) - formatted.add(a.getAddress()); + formatted.add(address.getAddress()); else { if (compose) { boolean quote = false; - for (int i = 0; i < personal.length(); i++) - if ("()<>,;:\\\"[]@".indexOf(personal.charAt(i)) >= 0) { + for (int c = 0; c < personal.length(); c++) + if ("()<>,;:\\\"[]@".indexOf(personal.charAt(c)) >= 0) { quote = true; break; } @@ -618,12 +627,13 @@ public class MessageHelper { } if (full) - formatted.add(personal + " <" + a.getAddress() + ">"); + formatted.add(personal + " <" + address.getAddress() + ">"); else formatted.add(personal); } } else - formatted.add(address.toString()); + formatted.add(addresses[i].toString()); + } return TextUtils.join(", ", formatted); } diff --git a/app/src/main/java/eu/faircode/email/TupleMessageEx.java b/app/src/main/java/eu/faircode/email/TupleMessageEx.java index 2826bf95e7..d9929e84df 100644 --- a/app/src/main/java/eu/faircode/email/TupleMessageEx.java +++ b/app/src/main/java/eu/faircode/email/TupleMessageEx.java @@ -23,6 +23,8 @@ import androidx.room.Ignore; import java.util.Objects; +import javax.mail.Address; + public class TupleMessageEx extends EntityMessage { public String accountName; public Integer accountColor; @@ -34,6 +36,7 @@ public class TupleMessageEx extends EntityMessage { public String identityName; public String identityEmail; public Boolean identitySynchronize; + public Address[] senders; public int count; public int unseen; public int unflagged;