Sanitize email addresses from address book

pull/172/head
M66B 5 years ago
parent 4504d69aaa
commit 91e909e78a

@ -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 {

@ -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();

Loading…
Cancel
Save