Rewritten identity handling

pull/162/head
M66B 6 years ago
parent a60d06c348
commit 6242348d32

@ -1804,14 +1804,24 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return null; return null;
EntityFolder folder = db.folder().getFolder(message.folder); EntityFolder folder = db.folder().getFolder(message.folder);
if (folder == null)
return null;
boolean outgoing = EntityFolder.isOutgoing(folder.type);
if (message.identity != null) {
Address[] senders = (message.reply == null || message.reply.length == 0 ? message.from : message.reply);
if (senders != null && senders.length > 0) {
EntityIdentity identity = db.identity().getIdentity(message.identity);
if (identity == null)
return null;
boolean outgoing; for (Address sender : senders)
if (message.identity == null || message.from == null || message.from.length == 0) if (MessageHelper.similarAddress(sender, identity.email)) {
outgoing = EntityFolder.isOutgoing(folder.type); outgoing = true;
else { break;
String from = ((InternetAddress) message.from[0]).getAddress(); }
EntityIdentity identity = db.identity().getIdentity(message.identity); }
outgoing = MessageHelper.canonicalAddress(identity.email).equals(MessageHelper.canonicalAddress(from));
} }
return (outgoing ? message.to : message.from); return (outgoing ? message.to : message.from);
@ -1819,6 +1829,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
@Override @Override
protected void onExecuted(Bundle args, Address[] addresses) { protected void onExecuted(Bundle args, Address[] addresses) {
if (addresses == null || addresses.length == 0)
return;
String query = ((InternetAddress) addresses[0]).getAddress(); String query = ((InternetAddress) addresses[0]).getAddress();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast( lbm.sendBroadcast(
@ -2174,8 +2187,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (amessage == null || !amessage.id.equals(message.id)) if (amessage == null || !amessage.id.equals(message.id))
return; return;
String via = (identity == null ? null : MessageHelper.canonicalAddress(identity.email)); Address[] recipients = message.getAllRecipients(identity == null ? null : identity.email);
Address[] recipients = message.getAllRecipients(via);
View anchor = bnvActions.findViewById(R.id.action_reply); View anchor = bnvActions.findViewById(R.id.action_reply);
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, anchor); PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, anchor);

@ -2031,21 +2031,17 @@ class Core {
} }
// Search for matching identity // Search for matching identity
for (Address address : addresses) { List<EntityIdentity> identities = db.identity().getIdentities(folder.account);
String email = ((InternetAddress) address).getAddress(); if (identities != null) {
if (!TextUtils.isEmpty(email)) { for (Address address : addresses)
EntityIdentity ident = db.identity().getIdentity(folder.account, email); for (EntityIdentity identity : identities)
if (ident != null) if (MessageHelper.sameAddress(address, identity.email))
return ident; return identity;
String canonical = MessageHelper.canonicalAddress(email); for (Address address : addresses)
if (canonical.equals(email)) for (EntityIdentity identity : identities)
continue; if (MessageHelper.similarAddress(address, identity.email))
return identity;
ident = db.identity().getIdentity(folder.account, canonical);
if (ident != null)
return ident;
}
} }
return null; return null;
@ -2095,18 +2091,18 @@ class Core {
// Check if from self // Check if from self
if (type == EntityContact.TYPE_FROM && recipients != null && recipients.length > 0) { if (type == EntityContact.TYPE_FROM && recipients != null && recipients.length > 0) {
boolean me = true; boolean me = false;
for (Address reply : recipients) { List<EntityIdentity> identities = db.identity().getIdentities(folder.account);
String email = ((InternetAddress) reply).getAddress(); if (identities != null)
String canonical = MessageHelper.canonicalAddress(email); for (Address recipient : recipients) {
if (!TextUtils.isEmpty(email) && for (EntityIdentity identity : identities)
db.identity().getIdentity(folder.account, email) == null && if (MessageHelper.similarAddress(recipient, identity.email)) {
(canonical.equals(email) || me = true;
db.identity().getIdentity(folder.account, canonical) == null)) { break;
me = false; }
break; if (me)
break;
} }
}
if (me) if (me)
recipients = message.to; recipients = message.to;
} }

@ -40,7 +40,6 @@ import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import javax.mail.Address; import javax.mail.Address;
import javax.mail.internet.InternetAddress;
import static androidx.room.ForeignKey.CASCADE; import static androidx.room.ForeignKey.CASCADE;
import static androidx.room.ForeignKey.SET_NULL; import static androidx.room.ForeignKey.SET_NULL;
@ -164,12 +163,14 @@ public class EntityMessage implements Serializable {
} }
boolean replySelf(String via) { boolean replySelf(String via) {
Address[] replying = (reply == null || reply.length == 0 ? from : reply); Address[] senders = (reply == null || reply.length == 0 ? from : reply);
if (replying == null || replying.length != 1)
return false;
String recipient = MessageHelper.canonicalAddress(((InternetAddress) replying[0]).getAddress()); if (senders != null)
return recipient.equals(via); for (Address sender : senders)
if (MessageHelper.similarAddress(sender, via))
return true;
return false;
} }
Address[] getAllRecipients(String via) { Address[] getAllRecipients(String via) {
@ -182,11 +183,9 @@ public class EntityMessage implements Serializable {
addresses.addAll(Arrays.asList(cc)); addresses.addAll(Arrays.asList(cc));
// Filter self // Filter self
for (Address address : new ArrayList<>(addresses)) { for (Address address : new ArrayList<>(addresses))
String recipient = MessageHelper.canonicalAddress(((InternetAddress) address).getAddress()); if (MessageHelper.similarAddress(address, via))
if (recipient.equals(via))
addresses.remove(address); addresses.remove(address);
}
return addresses.toArray(new Address[0]); return addresses.toArray(new Address[0]);
} }

@ -2021,78 +2021,61 @@ public class FragmentCompose extends FragmentBase {
crumb.put("action", action); crumb.put("action", action);
Log.breadcrumb("compose", crumb); Log.breadcrumb("compose", crumb);
EntityMessage draft; DraftData data = new DraftData();
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
try { try {
db.beginTransaction(); db.beginTransaction();
draft = db.message().getMessage(id); data.identities = db.identity().getComposableIdentities(null);
if (draft == null || draft.ui_hide != 0) { if (data.identities == null || data.identities.size() == 0)
throw new IllegalStateException(getString(R.string.title_no_identities));
data.draft = db.message().getMessage(id);
if (data.draft == null || data.draft.ui_hide != 0) {
// New draft // New draft
if ("edit".equals(action)) if ("edit".equals(action))
throw new MessageRemovedException("Draft for edit was deleted hide=" + (draft != null)); throw new MessageRemovedException("Draft for edit was deleted hide=" + (data.draft != null));
EntityFolder drafts;
EntityMessage ref = db.message().getMessage(reference); EntityMessage ref = db.message().getMessage(reference);
if (ref == null) {
long aid = args.getLong("account", -1);
if (aid < 0)
drafts = db.folder().getPrimaryDrafts();
else {
drafts = db.folder().getFolderByType(aid, EntityFolder.DRAFTS);
if (drafts == null)
drafts = db.folder().getPrimaryDrafts();
}
if (drafts == null)
throw new IllegalArgumentException(context.getString(R.string.title_no_primary_drafts));
} else {
drafts = db.folder().getFolderByType(ref.account, EntityFolder.DRAFTS);
if (drafts == null)
drafts = db.folder().getPrimaryDrafts();
if (drafts == null)
throw new IllegalArgumentException(context.getString(R.string.title_no_primary_drafts));
}
String body = ""; String body = "";
draft = new EntityMessage(); data.draft = new EntityMessage();
draft.account = drafts.account; data.draft.msgid = EntityMessage.generateMessageId();
draft.folder = drafts.id;
draft.msgid = EntityMessage.generateMessageId();
if (ref == null) { if (ref == null) {
draft.thread = draft.msgid; data.draft.thread = data.draft.msgid;
try { try {
String to = args.getString("to"); String to = args.getString("to");
draft.to = (TextUtils.isEmpty(to) ? null : InternetAddress.parse(to)); data.draft.to = (TextUtils.isEmpty(to) ? null : InternetAddress.parse(to));
} catch (AddressException ex) { } catch (AddressException ex) {
Log.w(ex); Log.w(ex);
} }
try { try {
String cc = args.getString("cc"); String cc = args.getString("cc");
draft.cc = (TextUtils.isEmpty(cc) ? null : InternetAddress.parse(cc)); data.draft.cc = (TextUtils.isEmpty(cc) ? null : InternetAddress.parse(cc));
} catch (AddressException ex) { } catch (AddressException ex) {
Log.w(ex); Log.w(ex);
} }
try { try {
String bcc = args.getString("bcc"); String bcc = args.getString("bcc");
draft.bcc = (TextUtils.isEmpty(bcc) ? null : InternetAddress.parse(bcc)); data.draft.bcc = (TextUtils.isEmpty(bcc) ? null : InternetAddress.parse(bcc));
} catch (AddressException ex) { } catch (AddressException ex) {
Log.w(ex); Log.w(ex);
} }
draft.subject = args.getString("subject", ""); data.draft.subject = args.getString("subject", "");
body = args.getString("body", ""); body = args.getString("body", "");
body = body.replaceAll("\\r?\\n", "<br>"); body = body.replaceAll("\\r?\\n", "<br>");
if (answer > 0) { if (answer > 0) {
EntityAnswer a = db.answer().getAnswer(answer); EntityAnswer a = db.answer().getAnswer(answer);
if (a != null) { if (a != null) {
draft.subject = a.name; data.draft.subject = a.name;
body = EntityAnswer.getAnswerText(a, null) + body; body = EntityAnswer.getAnswerText(a, null) + body;
} }
} }
@ -2115,40 +2098,42 @@ public class FragmentCompose extends FragmentBase {
String s = ((InternetAddress) sender[0]).getAddress(); String s = ((InternetAddress) sender[0]).getAddress();
int at = s.indexOf('@'); int at = s.indexOf('@');
if (at > 0) if (at > 0)
draft.extra = s.substring(0, at); data.draft.extra = s.substring(0, at);
} }
draft.references = (ref.references == null ? "" : ref.references + " ") + ref.msgid; data.draft.references = (ref.references == null ? "" : ref.references + " ") + ref.msgid;
draft.inreplyto = ref.msgid; data.draft.inreplyto = ref.msgid;
draft.thread = ref.thread; data.draft.thread = ref.thread;
String via = null; String via = null;
if (ref.identity != null) { if (ref.identity != null) {
EntityIdentity identity = db.identity().getIdentity(ref.identity); EntityIdentity identity = db.identity().getIdentity(ref.identity);
draft.from = new Address[]{new InternetAddress(identity.email, identity.name)}; if (identity != null) {
via = MessageHelper.canonicalAddress(identity.email); data.draft.from = new Address[]{new InternetAddress(identity.email, identity.name)};
via = identity.email;
}
} }
if ("list".equals(action) && ref.list_post != null) if ("list".equals(action) && ref.list_post != null)
draft.to = ref.list_post; data.draft.to = ref.list_post;
else if ("receipt".equals(action) && ref.receipt_to != null) else if ("receipt".equals(action) && ref.receipt_to != null)
draft.to = ref.receipt_to; data.draft.to = ref.receipt_to;
else { else {
// Prevent replying to self // Prevent replying to self
if (ref.replySelf(via)) { if (ref.replySelf(via)) {
draft.to = ref.to; data.draft.to = ref.to;
draft.from = ref.from; data.draft.from = ref.from;
} else } else
draft.to = (ref.reply == null || ref.reply.length == 0 ? ref.from : ref.reply); data.draft.to = (ref.reply == null || ref.reply.length == 0 ? ref.from : ref.reply);
} }
if ("reply_all".equals(action)) if ("reply_all".equals(action))
draft.cc = ref.getAllRecipients(via); data.draft.cc = ref.getAllRecipients(via);
else if ("receipt".equals(action)) else if ("receipt".equals(action))
draft.receipt_request = true; data.draft.receipt_request = true;
} else if ("forward".equals(action) || "editasnew".equals(action)) } else if ("forward".equals(action) || "editasnew".equals(action))
draft.thread = draft.msgid; // new thread data.draft.thread = data.draft.msgid; // new thread
String subject = (ref.subject == null ? "" : ref.subject); String subject = (ref.subject == null ? "" : ref.subject);
if ("reply".equals(action) || "reply_all".equals(action)) { if ("reply".equals(action) || "reply_all".equals(action)) {
@ -2156,23 +2141,23 @@ public class FragmentCompose extends FragmentBase {
String re = context.getString(R.string.title_subject_reply, ""); String re = context.getString(R.string.title_subject_reply, "");
subject = subject.replaceAll("(?i)" + Pattern.quote(re.trim()), "").trim(); subject = subject.replaceAll("(?i)" + Pattern.quote(re.trim()), "").trim();
} }
draft.subject = context.getString(R.string.title_subject_reply, subject); data.draft.subject = context.getString(R.string.title_subject_reply, subject);
} else if ("forward".equals(action)) { } else if ("forward".equals(action)) {
if (prefix_once) { if (prefix_once) {
String fwd = context.getString(R.string.title_subject_forward, ""); String fwd = context.getString(R.string.title_subject_forward, "");
subject = subject.replaceAll("(?i)" + Pattern.quote(fwd.trim()), "").trim(); subject = subject.replaceAll("(?i)" + Pattern.quote(fwd.trim()), "").trim();
} }
draft.subject = context.getString(R.string.title_subject_forward, subject); data.draft.subject = context.getString(R.string.title_subject_forward, subject);
} else if ("editasnew".equals(action)) { } else if ("editasnew".equals(action)) {
draft.subject = ref.subject; data.draft.subject = ref.subject;
if (ref.content) { if (ref.content) {
String html = Helper.readText(ref.getFile(context)); String html = Helper.readText(ref.getFile(context));
body = HtmlHelper.sanitize(context, html, true); body = HtmlHelper.sanitize(context, html, true);
} }
} else if ("list".equals(action)) { } else if ("list".equals(action)) {
draft.subject = ref.subject; data.draft.subject = ref.subject;
} else if ("receipt".equals(action)) { } else if ("receipt".equals(action)) {
draft.subject = context.getString(R.string.title_receipt_subject, subject); data.draft.subject = context.getString(R.string.title_receipt_subject, subject);
Configuration configuration = new Configuration(context.getResources().getConfiguration()); Configuration configuration = new Configuration(context.getResources().getConfiguration());
configuration.setLocale(new Locale("en")); configuration.setLocale(new Locale("en"));
@ -2182,79 +2167,114 @@ public class FragmentCompose extends FragmentBase {
if (!Locale.getDefault().getLanguage().equals("en")) if (!Locale.getDefault().getLanguage().equals("en"))
body += "<p>" + res.getString(R.string.title_receipt_text) + "</p>"; body += "<p>" + res.getString(R.string.title_receipt_text) + "</p>";
} else if ("participation".equals(action)) } else if ("participation".equals(action))
draft.subject = status + ": " + ref.subject; data.draft.subject = status + ": " + ref.subject;
draft.plain_only = ref.plain_only; data.draft.plain_only = ref.plain_only;
if (answer > 0) if (answer > 0)
body = EntityAnswer.getAnswerText(context, answer, draft.to) + body; body = EntityAnswer.getAnswerText(context, answer, data.draft.to) + body;
} }
if (plain_only) if (plain_only)
draft.plain_only = true; data.draft.plain_only = true;
// Select identity matching from address // Select identity matching from address
int icount = 0; EntityIdentity selected = null;
EntityIdentity first = null; long aid = args.getLong("account", -1);
EntityIdentity primary = null;
List<TupleIdentityEx> identities = db.identity().getComposableIdentities(null); if (data.draft.from != null && data.draft.from.length > 0) {
for (Address sender : data.draft.from)
int iindex = -1; for (EntityIdentity identity : data.identities)
do { if (identity.account.equals(aid) &&
String from = null; MessageHelper.sameAddress(sender, identity.email)) {
if (iindex >= 0) selected = identity;
from = MessageHelper.canonicalAddress(((InternetAddress) draft.from[iindex]).getAddress()); break;
for (EntityIdentity identity : identities) { }
String email = MessageHelper.canonicalAddress(identity.email);
if (email.equals(from)) { if (selected == null)
draft.identity = identity.id; for (Address sender : data.draft.from)
draft.from = new InternetAddress[]{new InternetAddress(identity.email, identity.name)}; for (EntityIdentity identity : data.identities)
if (identity.account.equals(aid) &&
MessageHelper.similarAddress(sender, identity.email)) {
selected = identity;
break;
}
if (selected == null)
for (Address sender : data.draft.from)
for (EntityIdentity identity : data.identities)
if (MessageHelper.sameAddress(sender, identity.email)) {
selected = identity;
break;
}
if (selected == null)
for (Address sender : data.draft.from)
for (EntityIdentity identity : data.identities)
if (MessageHelper.similarAddress(sender, identity.email)) {
selected = identity;
break;
}
}
if (selected == null)
for (EntityIdentity identity : data.identities)
if (identity.account.equals(aid) && identity.primary) {
selected = identity;
break;
}
if (selected == null)
for (EntityIdentity identity : data.identities)
if (identity.account.equals(aid)) {
selected = identity;
break; break;
} }
if (identity.account.equals(draft.account)) {
icount++; if (selected == null)
if (identity.primary) for (EntityIdentity identity : data.identities)
primary = identity; if (identity.primary) {
if (first == null) selected = identity;
first = identity; break;
} }
}
if (draft.identity != null)
break;
iindex++; if (selected == null)
} while (iindex < (draft.from == null ? -1 : draft.from.length)); for (EntityIdentity identity : data.identities) {
selected = identity;
// Select identity break;
if (draft.identity == null) {
if (primary != null) {
draft.identity = primary.id;
draft.from = new InternetAddress[]{new InternetAddress(primary.email, primary.name)};
} else if (first != null && icount == 1) {
draft.identity = first.id;
draft.from = new InternetAddress[]{new InternetAddress(first.email, first.name)};
} }
}
draft.sender = MessageHelper.getSortKey(draft.from); if (selected == null)
Uri lookupUri = ContactInfo.getLookupUri(context, draft.from); throw new IllegalArgumentException(context.getString(R.string.title_no_identities));
draft.avatar = (lookupUri == null ? null : lookupUri.toString());
EntityFolder drafts = db.folder().getFolderByType(selected.account, EntityFolder.DRAFTS);
if (drafts == null)
throw new IllegalArgumentException(context.getString(R.string.title_no_primary_drafts));
data.draft.account = drafts.account;
data.draft.folder = drafts.id;
data.draft.identity = selected.id;
data.draft.from = new InternetAddress[]{new InternetAddress(selected.email, selected.name)};
data.draft.sender = MessageHelper.getSortKey(data.draft.from);
Uri lookupUri = ContactInfo.getLookupUri(context, data.draft.from);
data.draft.avatar = (lookupUri == null ? null : lookupUri.toString());
draft.received = new Date().getTime(); data.draft.received = new Date().getTime();
draft.seen = true; data.draft.seen = true;
draft.ui_seen = true; data.draft.ui_seen = true;
draft.id = db.message().insertMessage(draft); data.draft.id = db.message().insertMessage(data.draft);
Helper.writeText(draft.getFile(context), body); Helper.writeText(data.draft.getFile(context), body);
db.message().setMessageContent(draft.id, db.message().setMessageContent(data.draft.id,
true, true,
draft.plain_only, data.draft.plain_only,
HtmlHelper.getPreview(body), HtmlHelper.getPreview(body),
null); null);
if ("participation".equals(action)) { if ("participation".equals(action)) {
EntityAttachment attachment = new EntityAttachment(); EntityAttachment attachment = new EntityAttachment();
attachment.message = draft.id; attachment.message = data.draft.id;
attachment.sequence = 1; attachment.sequence = 1;
attachment.name = "meeting.ics"; attachment.name = "meeting.ics";
attachment.type = "text/calendar"; attachment.type = "text/calendar";
@ -2312,14 +2332,14 @@ public class FragmentCompose extends FragmentBase {
Html.escapeHtml(new Date(ref.received).toString()), Html.escapeHtml(new Date(ref.received).toString()),
Html.escapeHtml(MessageHelper.formatAddresses(ref.from)), Html.escapeHtml(MessageHelper.formatAddresses(ref.from)),
refText); refText);
Helper.writeText(draft.getRefFile(context), refBody); Helper.writeText(data.draft.getRefFile(context), refBody);
} }
if ("new".equals(action)) { if ("new".equals(action)) {
ArrayList<Uri> uris = args.getParcelableArrayList("attachments"); ArrayList<Uri> uris = args.getParcelableArrayList("attachments");
if (uris != null) if (uris != null)
for (Uri uri : uris) for (Uri uri : uris)
addAttachment(context, draft.id, uri, false); addAttachment(context, data.draft.id, uri, false);
} else if (ref != null && } else if (ref != null &&
("reply".equals(action) || "reply_all".equals(action) || ("reply".equals(action) || "reply_all".equals(action) ||
"forward".equals(action) || "editasnew".equals(action))) { "forward".equals(action) || "editasnew".equals(action))) {
@ -2328,8 +2348,8 @@ public class FragmentCompose extends FragmentBase {
for (EntityAttachment attachment : attachments) for (EntityAttachment attachment : attachments)
if (attachment.encryption != null && if (attachment.encryption != null &&
attachment.encryption.equals(EntityAttachment.PGP_MESSAGE)) { attachment.encryption.equals(EntityAttachment.PGP_MESSAGE)) {
draft.encrypt = true; data.draft.encrypt = true;
db.message().setMessageEncrypt(draft.id, true); db.message().setMessageEncrypt(data.draft.id, true);
} else if (attachment.encryption == null && } else if (attachment.encryption == null &&
("forward".equals(action) || "editasnew".equals(action) || ("forward".equals(action) || "editasnew".equals(action) ||
@ -2338,7 +2358,7 @@ public class FragmentCompose extends FragmentBase {
File source = attachment.getFile(context); File source = attachment.getFile(context);
attachment.id = null; attachment.id = null;
attachment.message = draft.id; attachment.message = data.draft.id;
attachment.sequence = ++sequence; attachment.sequence = ++sequence;
attachment.id = db.attachment().insertAttachment(attachment); attachment.id = db.attachment().insertAttachment(attachment);
@ -2352,18 +2372,18 @@ public class FragmentCompose extends FragmentBase {
} }
} }
EntityOperation.queue(context, draft, EntityOperation.ADD); EntityOperation.queue(context, data.draft, EntityOperation.ADD);
} else { } else {
if (!draft.content) { if (!data.draft.content) {
if (draft.uid == null) if (data.draft.uid == null)
throw new IllegalStateException("Draft without uid"); throw new IllegalStateException("Draft without uid");
EntityOperation.queue(context, draft, EntityOperation.BODY); EntityOperation.queue(context, data.draft, EntityOperation.BODY);
} }
List<EntityAttachment> attachments = db.attachment().getAttachments(draft.id); List<EntityAttachment> attachments = db.attachment().getAttachments(data.draft.id);
for (EntityAttachment attachment : attachments) for (EntityAttachment attachment : attachments)
if (!attachment.available) if (!attachment.available)
EntityOperation.queue(context, draft, EntityOperation.ATTACHMENT, attachment.id); EntityOperation.queue(context, data.draft, EntityOperation.ATTACHMENT, attachment.id);
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
@ -2371,18 +2391,11 @@ public class FragmentCompose extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
DraftData data = new DraftData();
data.draft = draft;
data.identities = db.identity().getComposableIdentities(null);
return data; return data;
} }
@Override @Override
protected void onExecuted(Bundle args, final DraftData data) { protected void onExecuted(Bundle args, final DraftData data) {
if (data.identities == null || data.identities.size() == 0)
throw new IllegalStateException(getString(R.string.title_no_identities));
working = data.draft.id; working = data.draft.id;
final String action = getArguments().getString("action"); final String action = getArguments().getString("action");

@ -713,14 +713,30 @@ public class MessageHelper {
return TextUtils.join(", ", formatted); return TextUtils.join(", ", formatted);
} }
static String canonicalAddress(String address) { static boolean sameAddress(Address address1, String email2) {
String[] a = address.split("@"); String email1 = ((InternetAddress) address1).getAddress();
if (a.length > 0) { return email1.equalsIgnoreCase(email2);
String[] extra = a[0].split("\\+"); }
if (extra.length > 0)
a[0] = extra[0]; static boolean similarAddress(Address address1, String email2) {
} String email1 = ((InternetAddress) address1).getAddress();
return TextUtils.join("@", a).toLowerCase();
if (!email1.contains("@") || !email2.contains("@"))
return false;
String[] e1 = email1.split("@");
String[] e2 = email2.split("@");
if (e1.length != 2 || e2.length != 2)
return false;
// Domain
if (!e1[1].equalsIgnoreCase(e2[1]))
return false;
String user1 = (e1[0].contains("+") ? e1[0].split("\\+")[0] : e1[0]);
return user1.equalsIgnoreCase(e2[0]);
} }
static String decodeMime(String text) { static String decodeMime(String text) {

Loading…
Cancel
Save