(Context context, EntityMessage message, List<Header> headers, String html)
| 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 | } |
no test coverage detected