| 49 | import javax.mail.internet.InternetAddress; |
| 50 | |
| 51 | public class MessageClassifier { |
| 52 | private static boolean loaded = false; |
| 53 | private static boolean dirty = false; |
| 54 | private static final Map<Long, List<String>> accountMsgIds = new HashMap<>(); |
| 55 | private static final Map<Long, Map<String, Integer>> classMessages = new HashMap<>(); |
| 56 | private static final Map<Long, Map<Integer, Map<String, Frequency>>> wordClassFrequency = new HashMap<>(); |
| 57 | private static final Map<String, Integer> wordIndex = new LinkedHashMap<>(); |
| 58 | |
| 59 | private static final int VERSION = 4; |
| 60 | private static final int MAX_WORDS = 1000; |
| 61 | |
| 62 | static synchronized void classify(EntityMessage message, EntityFolder folder, boolean added, Context context) { |
| 63 | try { |
| 64 | if (!isEnabled(context)) |
| 65 | return; |
| 66 | |
| 67 | if (!folder.auto_classify_source) |
| 68 | return; |
| 69 | |
| 70 | if (message.ui_hide) |
| 71 | return; |
| 72 | |
| 73 | long start = new Date().getTime(); |
| 74 | |
| 75 | // Build text to classify |
| 76 | List<String> texts = getTexts(message, context); |
| 77 | if (texts.size() == 0) |
| 78 | return; |
| 79 | |
| 80 | // Load data if needed |
| 81 | load(context); |
| 82 | |
| 83 | // Initialize account if needed |
| 84 | if (!accountMsgIds.containsKey(folder.account)) |
| 85 | accountMsgIds.put(folder.account, new ArrayList<>()); |
| 86 | if (!classMessages.containsKey(folder.account)) |
| 87 | classMessages.put(folder.account, new HashMap<>()); |
| 88 | if (!wordClassFrequency.containsKey(folder.account)) |
| 89 | wordClassFrequency.put(folder.account, new HashMap<>()); |
| 90 | |
| 91 | // Classify texts |
| 92 | String classified = classify(message, folder.name, texts, added, context); |
| 93 | |
| 94 | boolean notJunk = message.isNotJunk(context); |
| 95 | |
| 96 | long elapsed = new Date().getTime() - start; |
| 97 | EntityLog.log(context, EntityLog.Type.Classification, message, |
| 98 | "Classifier" + |
| 99 | " folder=" + folder.account + ":" + folder.name + ":" + folder.type + |
| 100 | " added=" + added + |
| 101 | " message=" + message.id + "/" + !TextUtils.isEmpty(message.msgid) + |
| 102 | " keyword=" + message.hasKeyword(MessageHelper.FLAG_CLASSIFIED) + |
| 103 | " filtered=" + message.hasKeyword(MessageHelper.FLAG_FILTERED) + |
| 104 | " notJunk=" + notJunk + |
| 105 | "@" + new Date(message.received) + |
| 106 | ":" + message.subject + |
| 107 | " class=" + classified + |
| 108 | " re=" + message.auto_classified + |
nothing calls this directly
no outgoing calls
no test coverage detected