|
|
@ -100,45 +100,36 @@ public class EntityContact implements Serializable {
|
|
|
|
@NonNull EntityAccount account,
|
|
|
|
@NonNull EntityAccount account,
|
|
|
|
@NonNull EntityFolder folder,
|
|
|
|
@NonNull EntityFolder folder,
|
|
|
|
@NonNull EntityMessage message) {
|
|
|
|
@NonNull EntityMessage message) {
|
|
|
|
if (!EntityFolder.JUNK.equals(folder.type)) {
|
|
|
|
|
|
|
|
int days = (folder.isOutgoing() ? folder.keep_days : folder.sync_days);
|
|
|
|
int days = (folder.isOutgoing() ? folder.keep_days : folder.sync_days);
|
|
|
|
if (days == Integer.MAX_VALUE)
|
|
|
|
if (days == Integer.MAX_VALUE)
|
|
|
|
days = EntityFolder.DEFAULT_KEEP;
|
|
|
|
days = EntityFolder.DEFAULT_KEEP;
|
|
|
|
if (message.received < account.created - days * 24 * 3600 * 1000L)
|
|
|
|
if (message.received < account.created - days * 24 * 3600 * 1000L)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (EntityFolder.DRAFTS.equals(folder.type) ||
|
|
|
|
if (EntityFolder.DRAFTS.equals(folder.type) ||
|
|
|
|
EntityFolder.ARCHIVE.equals(folder.type) ||
|
|
|
|
EntityFolder.ARCHIVE.equals(folder.type) ||
|
|
|
|
EntityFolder.TRASH.equals(folder.type))
|
|
|
|
EntityFolder.TRASH.equals(folder.type) ||
|
|
|
|
|
|
|
|
EntityFolder.JUNK.equals(folder.type))
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
boolean suggest_sent = prefs.getBoolean("suggest_sent", true);
|
|
|
|
boolean suggest_sent = prefs.getBoolean("suggest_sent", true);
|
|
|
|
boolean suggest_received = prefs.getBoolean("suggest_received", false);
|
|
|
|
boolean suggest_received = prefs.getBoolean("suggest_received", false);
|
|
|
|
boolean auto_junk = prefs.getBoolean("auto_junk", false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Shortcut
|
|
|
|
// Shortcut
|
|
|
|
if (!suggest_sent && !suggest_received &&
|
|
|
|
if (!suggest_sent && !suggest_received)
|
|
|
|
!(EntityFolder.JUNK.equals(folder.type) && auto_junk))
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
int type;
|
|
|
|
int type = (folder.isOutgoing() ? TYPE_TO : TYPE_FROM);
|
|
|
|
if (EntityFolder.JUNK.equals(folder.type))
|
|
|
|
|
|
|
|
type = TYPE_JUNK;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
type = (folder.isOutgoing() ? TYPE_TO : TYPE_FROM);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if from self
|
|
|
|
// Check if from self
|
|
|
|
if (type == TYPE_FROM || type == TYPE_JUNK) {
|
|
|
|
if (type == TYPE_FROM) {
|
|
|
|
if (message.from != null) {
|
|
|
|
if (message.from != null) {
|
|
|
|
List<EntityIdentity> identities = Core.getIdentities(folder.account, context);
|
|
|
|
List<EntityIdentity> identities = Core.getIdentities(folder.account, context);
|
|
|
|
if (identities != null) {
|
|
|
|
if (identities != null) {
|
|
|
|
for (Address sender : message.from) {
|
|
|
|
for (Address sender : message.from) {
|
|
|
|
for (EntityIdentity identity : identities)
|
|
|
|
for (EntityIdentity identity : identities)
|
|
|
|
if (identity.similarAddress(sender)) {
|
|
|
|
if (identity.similarAddress(sender)) {
|
|
|
|
if (type == TYPE_JUNK)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
type = TYPE_TO;
|
|
|
|
type = TYPE_TO;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -153,8 +144,6 @@ public class EntityContact implements Serializable {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
if (type == TYPE_FROM && !suggest_received)
|
|
|
|
if (type == TYPE_FROM && !suggest_received)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
if (type == TYPE_JUNK && !auto_junk)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Address> addresses = new ArrayList<>();
|
|
|
|
List<Address> addresses = new ArrayList<>();
|
|
|
|
if (type == TYPE_FROM) {
|
|
|
|
if (type == TYPE_FROM) {
|
|
|
@ -168,19 +157,6 @@ public class EntityContact implements Serializable {
|
|
|
|
addresses.addAll(Arrays.asList(message.to));
|
|
|
|
addresses.addAll(Arrays.asList(message.to));
|
|
|
|
if (message.cc != null)
|
|
|
|
if (message.cc != null)
|
|
|
|
addresses.addAll(Arrays.asList(message.cc));
|
|
|
|
addresses.addAll(Arrays.asList(message.cc));
|
|
|
|
} else if (type == TYPE_JUNK) {
|
|
|
|
|
|
|
|
if (message.from != null) {
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
|
|
|
for (Address from : message.from) {
|
|
|
|
|
|
|
|
String email = ((InternetAddress) from).getAddress();
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(email))
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
EntityContact nojunk = db.contact().getContact(message.account, TYPE_NO_JUNK, email);
|
|
|
|
|
|
|
|
if (nojunk != null)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
addresses.addAll(Arrays.asList(message.from));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
update(context, folder.account, addresses.toArray(new Address[0]), type, message.received);
|
|
|
|
update(context, folder.account, addresses.toArray(new Address[0]), type, message.received);
|
|
|
|