mirror of https://github.com/M66B/FairEmail.git
Improved local contact handling
This commit is contained in:
parent
e6e0a00767
commit
79da181f36
|
@ -1826,13 +1826,12 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
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) {
|
||||
if (message.from != null && message.from.length > 0) {
|
||||
EntityIdentity identity = db.identity().getIdentity(message.identity);
|
||||
if (identity == null)
|
||||
return null;
|
||||
|
||||
for (Address sender : senders)
|
||||
for (Address sender : message.from)
|
||||
if (identity.similarAddress(sender)) {
|
||||
outgoing = true;
|
||||
break;
|
||||
|
|
|
@ -1788,7 +1788,7 @@ class Core {
|
|||
}
|
||||
}
|
||||
|
||||
static EntityMessage _synchronizeMessage(
|
||||
private static EntityMessage _synchronizeMessage(
|
||||
Context context,
|
||||
EntityAccount account, EntityFolder folder,
|
||||
long uid, MimeMessage imessage,
|
||||
|
@ -2148,7 +2148,7 @@ class Core {
|
|||
}
|
||||
|
||||
private static void updateContactInfo(Context context, final EntityFolder folder, final EntityMessage message) {
|
||||
final DB db = DB.getInstance(context);
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
if (EntityFolder.DRAFTS.equals(folder.type) ||
|
||||
EntityFolder.ARCHIVE.equals(folder.type) ||
|
||||
|
@ -2156,7 +2156,25 @@ class Core {
|
|||
EntityFolder.JUNK.equals(folder.type))
|
||||
return;
|
||||
|
||||
final int type = (folder.isOutgoing() ? EntityContact.TYPE_TO : EntityContact.TYPE_FROM);
|
||||
int type = (folder.isOutgoing() ? EntityContact.TYPE_TO : EntityContact.TYPE_FROM);
|
||||
|
||||
// Check if from self
|
||||
if (type == EntityContact.TYPE_FROM) {
|
||||
if (message.from != null) {
|
||||
List<EntityIdentity> identities = db.identity().getSynchronizingIdentities(folder.account);
|
||||
if (identities != null) {
|
||||
for (Address sender : message.from) {
|
||||
for (EntityIdentity identity : identities)
|
||||
if (identity.similarAddress(sender)) {
|
||||
type = EntityContact.TYPE_TO;
|
||||
break;
|
||||
}
|
||||
if (type == EntityContact.TYPE_TO)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean suggest_sent = prefs.getBoolean("suggest_sent", false);
|
||||
|
@ -2167,36 +2185,28 @@ class Core {
|
|||
if (type == EntityContact.TYPE_FROM && !suggest_received)
|
||||
return;
|
||||
|
||||
Address[] recipients = (type == EntityContact.TYPE_TO
|
||||
? message.to
|
||||
: (message.reply != null ? message.reply : message.from));
|
||||
|
||||
// Check if from self
|
||||
if (type == EntityContact.TYPE_FROM && recipients != null && recipients.length > 0) {
|
||||
boolean me = false;
|
||||
List<EntityIdentity> identities = db.identity().getSynchronizingIdentities(folder.account);
|
||||
if (identities != null)
|
||||
for (Address recipient : recipients) {
|
||||
for (EntityIdentity identity : identities)
|
||||
if (identity.similarAddress(recipient)) {
|
||||
me = true;
|
||||
break;
|
||||
}
|
||||
if (me)
|
||||
break;
|
||||
}
|
||||
if (me)
|
||||
recipients = message.to;
|
||||
List<Address> addresses = new ArrayList<>();
|
||||
if (type == EntityContact.TYPE_FROM) {
|
||||
if (message.reply == null || message.reply.length == 0) {
|
||||
if (message.from != null)
|
||||
addresses.addAll(Arrays.asList(message.from));
|
||||
} else
|
||||
addresses.addAll(Arrays.asList(message.reply));
|
||||
} else if (type == EntityContact.TYPE_TO) {
|
||||
if (message.to != null)
|
||||
addresses.addAll(Arrays.asList(message.to));
|
||||
if (message.cc != null)
|
||||
addresses.addAll(Arrays.asList(message.cc));
|
||||
}
|
||||
|
||||
if (recipients != null) {
|
||||
for (Address recipient : recipients) {
|
||||
final String email = ((InternetAddress) recipient).getAddress();
|
||||
final String name = ((InternetAddress) recipient).getPersonal();
|
||||
final Uri avatar = ContactInfo.getLookupUri(context, new Address[]{recipient});
|
||||
db.runInTransaction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Address address : addresses) {
|
||||
final String email = ((InternetAddress) address).getAddress();
|
||||
final String name = ((InternetAddress) address).getPersonal();
|
||||
final Uri avatar = ContactInfo.getLookupUri(context, new Address[]{address});
|
||||
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
EntityContact contact = db.contact().getContact(folder.account, type, email);
|
||||
if (contact == null) {
|
||||
contact = new EntityContact();
|
||||
|
@ -2220,8 +2230,10 @@ class Core {
|
|||
db.contact().updateContact(contact);
|
||||
Log.i("Updated contact=" + contact + " type=" + type);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,14 +163,11 @@ public class EntityMessage implements Serializable {
|
|||
}
|
||||
|
||||
boolean replySelf(List<TupleIdentityEx> identities) {
|
||||
if (identities != null) {
|
||||
Address[] senders = (reply == null || reply.length == 0 ? from : reply);
|
||||
if (senders != null)
|
||||
for (Address sender : senders)
|
||||
if (identities != null && from != null)
|
||||
for (Address sender : from)
|
||||
for (TupleIdentityEx identity : identities)
|
||||
if (identity.similarAddress(sender))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue