mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-28 02:37:16 +00:00
Use email addresses for message classifier
This commit is contained in:
parent
9a03f28945
commit
0d8535815a
1 changed files with 37 additions and 0 deletions
|
@ -21,6 +21,7 @@ package eu.faircode.email;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
|
@ -33,6 +34,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.BreakIterator;
|
import java.text.BreakIterator;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -40,6 +42,9 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.mail.Address;
|
||||||
|
import javax.mail.internet.InternetAddress;
|
||||||
|
|
||||||
public class MessageClassifier {
|
public class MessageClassifier {
|
||||||
private static boolean loaded = false;
|
private static boolean loaded = false;
|
||||||
private static boolean dirty = false;
|
private static boolean dirty = false;
|
||||||
|
@ -73,9 +78,38 @@ public class MessageClassifier {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
List<Address> addresses = new ArrayList<>();
|
||||||
|
if (message.from != null)
|
||||||
|
addresses.addAll(Arrays.asList(message.from));
|
||||||
|
if (message.to != null)
|
||||||
|
addresses.addAll(Arrays.asList(message.to));
|
||||||
|
if (message.cc != null)
|
||||||
|
addresses.addAll(Arrays.asList(message.cc));
|
||||||
|
if (message.bcc != null)
|
||||||
|
addresses.addAll(Arrays.asList(message.bcc));
|
||||||
|
if (message.reply != null)
|
||||||
|
addresses.addAll(Arrays.asList(message.reply));
|
||||||
|
|
||||||
|
for (Address address : addresses) {
|
||||||
|
String email = ((InternetAddress) address).getAddress();
|
||||||
|
String name = ((InternetAddress) address).getAddress();
|
||||||
|
if (!TextUtils.isEmpty(email)) {
|
||||||
|
sb.append(email).append('\n');
|
||||||
|
int at = email.indexOf('@');
|
||||||
|
String domain = (at < 0 ? null : email.substring(at + 1));
|
||||||
|
if (!TextUtils.isEmpty(domain))
|
||||||
|
sb.append(domain).append('\n');
|
||||||
|
}
|
||||||
|
if (!TextUtils.isEmpty(name))
|
||||||
|
sb.append(name).append('\n');
|
||||||
|
}
|
||||||
|
|
||||||
if (message.subject != null)
|
if (message.subject != null)
|
||||||
sb.append(message.subject).append('\n');
|
sb.append(message.subject).append('\n');
|
||||||
|
|
||||||
sb.append(HtmlHelper.getFullText(file));
|
sb.append(HtmlHelper.getFullText(file));
|
||||||
|
|
||||||
if (sb.length() == 0)
|
if (sb.length() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -219,6 +253,9 @@ public class MessageClassifier {
|
||||||
chances.add(c);
|
chances.add(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (BuildConfig.DEBUG)
|
||||||
|
Log.i("Classifier words=" + TextUtils.join(", ", words));
|
||||||
|
|
||||||
if (chances.size() <= 1 || maxMatchedWords < MIN_MATCHED_WORDS)
|
if (chances.size() <= 1 || maxMatchedWords < MIN_MATCHED_WORDS)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue