From 710fd04781a05823c9b08a82e3399f25a0068495 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 17 Apr 2024 20:01:33 +0200 Subject: [PATCH] Expression: fixed text --- .../main/java/eu/faircode/email/EntityRule.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EntityRule.java b/app/src/main/java/eu/faircode/email/EntityRule.java index c700af81cc..6c56fbd540 100644 --- a/app/src/main/java/eu/faircode/email/EntityRule.java +++ b/app/src/main/java/eu/faircode/email/EntityRule.java @@ -204,7 +204,7 @@ public class EntityRule { } if (jcondition.has("expression")) { - Expression expression = getExpression(rule, null, null, null); + Expression expression = getExpression(rule, null, null, null, null); if (expression != null) { if ("header".equals(what) && needsHeaders(expression)) return true; @@ -484,6 +484,7 @@ public class EntityRule { return false; } + // Younger if (jcondition.has("younger")) { int younger = jcondition.getInt("younger"); Calendar y = Calendar.getInstance(); @@ -493,7 +494,7 @@ public class EntityRule { } // Expression - Expression expression = getExpression(this, message, headers, context); + Expression expression = getExpression(this, message, headers, html, context); if (expression != null) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean experiments = prefs.getBoolean("experiments", false); @@ -700,7 +701,7 @@ public class EntityRule { } } - static Expression getExpression(EntityRule rule, EntityMessage message, List
headers, Context context) throws JSONException, ParseException, MessagingException { + static Expression getExpression(EntityRule rule, EntityMessage message, List
headers, String html, Context context) throws JSONException, ParseException, MessagingException { // https://ezylang.github.io/EvalEx/ JSONObject jcondition = new JSONObject(rule.condition); @@ -718,14 +719,15 @@ public class EntityRule { for (Address a : message.from) from.add(MessageHelper.formatAddresses(new Address[]{a})); - Document doc = null; - if (message != null && message.content) + if (html == null && message != null && message.content) try { - doc = JsoupEx.parse(message.getFile(context)); + html = Helper.readText(message.getFile(context)); } catch (IOException ex) { Log.e(ex); } + Document doc = (html == null ? null : JsoupEx.parse(html)); + if (headers == null && message != null && message.headers != null) { ByteArrayInputStream bis = new ByteArrayInputStream(message.headers.getBytes()); headers = Collections.list(new InternetHeaders(bis, true).getAllHeaders()); @@ -850,7 +852,7 @@ public class EntityRule { void validate(Context context) throws JSONException, IllegalArgumentException { try { - Expression expression = getExpression(this, null, null, context); + Expression expression = getExpression(this, null, null, null, context); if (expression != null) { for (String variable : expression.getUsedVariables()) { Log.i("EXPR variable=" + variable);