From 91e909e78a71d0f0bef5a795b66bc8e7ce24c22b Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 30 Jan 2020 13:02:08 +0100 Subject: [PATCH] Sanitize email addresses from address book --- .../main/java/eu/faircode/email/FragmentCompose.java | 4 ++-- .../main/java/eu/faircode/email/MessageHelper.java | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 7bea6bca19..25328529e5 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -673,7 +673,7 @@ public class FragmentCompose extends FragmentBase { int colName = cursor.getColumnIndex("name"); int colEmail = cursor.getColumnIndex("email"); String name = cursor.getString(colName); - String email = cursor.getString(colEmail); + String email = MessageHelper.sanitizeEmail(cursor.getString(colEmail)); StringBuilder sb = new StringBuilder(); if (name == null) sb.append(email); @@ -1586,7 +1586,7 @@ public class FragmentCompose extends FragmentBase { if (cursor != null && cursor.moveToFirst()) { int colEmail = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS); int colName = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); - String email = cursor.getString(colEmail); + String email = MessageHelper.sanitizeEmail(cursor.getString(colEmail)); String name = cursor.getString(colName); try { diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index 5695863945..0f0ea5b3aa 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -1702,6 +1702,17 @@ public class MessageHelper { return sb.toString(); } + static String sanitizeEmail(String email) { + if (email.contains("<") && email.contains(">")) + try { + InternetAddress address = new InternetAddress(email); + return address.getAddress(); + } catch (AddressException ignored) { + } + + return email; + } + static boolean equalEmail(Address a1, Address a2) { String email1 = ((InternetAddress) a1).getAddress(); String email2 = ((InternetAddress) a2).getAddress();