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