mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-04 02:28:18 +00:00
Extended identity search
This commit is contained in:
parent
3a8256de10
commit
7f7825fc77
1 changed files with 33 additions and 14 deletions
|
@ -1870,24 +1870,43 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
}
|
||||
|
||||
if (message == null) {
|
||||
Address[] tos = (EntityFolder.SENT.equals(folder.type) ? helper.getFrom() : helper.getTo());
|
||||
EntityIdentity identity = null;
|
||||
if (tos != null && tos.length > 0) {
|
||||
String to = ((InternetAddress) tos[0]).getAddress();
|
||||
// Build list of addresses
|
||||
Address[] recipients = helper.getTo();
|
||||
Address[] senders = helper.getFrom();
|
||||
if (recipients == null)
|
||||
recipients = new Address[0];
|
||||
if (senders == null)
|
||||
senders = new Address[0];
|
||||
Address[] all = Arrays.copyOf(recipients, recipients.length + senders.length);
|
||||
System.arraycopy(senders, 0, all, recipients.length, senders.length);
|
||||
|
||||
List<String> emails = new ArrayList<>();
|
||||
for (Address address : all) {
|
||||
String to = ((InternetAddress) address).getAddress();
|
||||
if (!TextUtils.isEmpty(to)) {
|
||||
to = to.toLowerCase();
|
||||
identity = db.identity().getIdentity(folder.account, to);
|
||||
|
||||
if (identity == null)
|
||||
identity = db.identity().getIdentity(folder.account, Helper.canonicalAddress(to));
|
||||
|
||||
if (identity == null && !EntityFolder.SENT.equals(folder.type)) {
|
||||
to = helper.getDeliveredTo();
|
||||
if (!TextUtils.isEmpty(to))
|
||||
identity = db.identity().getIdentity(folder.account, to);
|
||||
}
|
||||
emails.add(to);
|
||||
String canonical = Helper.canonicalAddress(to);
|
||||
if (!to.equals(canonical))
|
||||
emails.add(canonical);
|
||||
}
|
||||
}
|
||||
String delivered = helper.getDeliveredTo();
|
||||
if (!TextUtils.isEmpty(delivered)) {
|
||||
delivered = delivered.toLowerCase();
|
||||
emails.add(delivered);
|
||||
String canonical = Helper.canonicalAddress(delivered);
|
||||
if (!delivered.equals(canonical))
|
||||
emails.add(canonical);
|
||||
}
|
||||
|
||||
// Search for identity
|
||||
EntityIdentity identity = null;
|
||||
for (String email : emails) {
|
||||
identity = db.identity().getIdentity(folder.account, email);
|
||||
if (identity != null)
|
||||
break;
|
||||
}
|
||||
|
||||
message = new EntityMessage();
|
||||
message.account = folder.account;
|
||||
|
|
Loading…
Add table
Reference in a new issue