MCPcopy Create free account
hub / github.com/M66B/FairEmail / matches

Method matches

app/src/main/java/eu/faircode/email/EntityRule.java:244–527  ·  view source on GitHub ↗
(Context context, EntityMessage message, List<Header> headers, String html)

Source from the content-addressed store, hash-verified

242 }
243
244 boolean matches(Context context, EntityMessage message, List<Header> headers, String html) throws MessagingException {
245 try {
246 JSONObject jcondition = new JSONObject(condition);
247
248 // general
249 int age = 0;
250 if (this.daily) {
251 JSONObject jgeneral = jcondition.optJSONObject("general");
252 if (jgeneral != null) {
253 age = jgeneral.optInt("age");
254 if (age > 0) {
255 Calendar cal = Calendar.getInstance();
256 cal.setTimeInMillis(message.received);
257 cal.add(Calendar.DAY_OF_MONTH, age);
258 if (cal.getTimeInMillis() > new Date().getTime())
259 return false;
260 }
261 }
262 }
263
264 // Sender
265 JSONObject jsender = jcondition.optJSONObject("sender");
266 if (jsender != null) {
267 boolean not = jsender.optBoolean("not");
268 String value = jsender.getString("value");
269 boolean regex = jsender.getBoolean("regex");
270 boolean known = jsender.optBoolean("known");
271
272 boolean matches = false;
273 List<Address> senders = new ArrayList<>();
274 if (message.from != null)
275 senders.addAll(Arrays.asList(message.from));
276 if (message.reply != null)
277 senders.addAll(Arrays.asList(message.reply));
278 for (Address sender : senders) {
279 InternetAddress ia = (InternetAddress) sender;
280 String email = ia.getAddress();
281 String personal = ia.getPersonal();
282
283 if (known) {
284 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
285 boolean suggest_sent = prefs.getBoolean("suggest_sent", true);
286 if (suggest_sent) {
287 DB db = DB.getInstance(context);
288 EntityContact contact =
289 db.contact().getContact(message.account, EntityContact.TYPE_TO, email);
290 if (contact != null) {
291 Log.i(email + " is local contact");
292 matches = true;
293 break;
294 }
295 }
296
297 if (!TextUtils.isEmpty(message.avatar)) {
298 Log.i(email + " is Android contact");
299 matches = true;
300 break;
301 }

Callers 7

onExecuteMethod · 0.95
onExecuteMethod · 0.95
ruleMethod · 0.95
runMethod · 0.45
validateMethod · 0.45
onActionNotesMethod · 0.45
isBlockingSenderMethod · 0.45

Calls 15

getInstanceMethod · 0.95
getAddressMethod · 0.95
getPersonalMethod · 0.95
contactMethod · 0.95
iMethod · 0.95
attachmentMethod · 0.95
matchKeywordsMethod · 0.95
readTextMethod · 0.95
eMethod · 0.95
parseMethod · 0.95
removeQuotesMethod · 0.95
getRelativeCalendarMethod · 0.95

Tested by

no test coverage detected