mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-01 01:06:11 +00:00
Added Jsoup expression function
This commit is contained in:
parent
8270c9abbf
commit
0aa628dc99
3 changed files with 35 additions and 0 deletions
1
FAQ.md
1
FAQ.md
|
@ -2779,6 +2779,7 @@ The following extra functions are available:
|
||||||
* *onBlocklist()* (returns a boolean indicating if the sender/server is on a DNS blocklist; since version 1.2179)
|
* *onBlocklist()* (returns a boolean indicating if the sender/server is on a DNS blocklist; since version 1.2179)
|
||||||
* *hasMx()* (returns a boolean indicating if the from/reply-to address has an associated MX record; since version 1.2179)
|
* *hasMx()* (returns a boolean indicating if the from/reply-to address has an associated MX record; since version 1.2179)
|
||||||
* *attachments()* (returns an integer indicating number of attachments; since version 1.2179)
|
* *attachments()* (returns an integer indicating number of attachments; since version 1.2179)
|
||||||
|
* *Jsoup()* (returns an array of selected strings; since version 1.2179)
|
||||||
|
|
||||||
Example conditions:
|
Example conditions:
|
||||||
|
|
||||||
|
|
|
@ -788,6 +788,37 @@ public class EntityRule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FunctionParameter(name = "value")
|
||||||
|
public static class JsoupFunction extends AbstractFunction {
|
||||||
|
private final Context context;
|
||||||
|
private final EntityMessage message;
|
||||||
|
|
||||||
|
JsoupFunction(Context context, EntityMessage message) {
|
||||||
|
this.context = context;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EvaluationValue evaluate(
|
||||||
|
Expression expression, Token functionToken, EvaluationValue... parameterValues) {
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
|
||||||
|
if (message != null && message.content && parameterValues.length == 1)
|
||||||
|
try {
|
||||||
|
String query = parameterValues[0].getStringValue();
|
||||||
|
File file = message.getFile(context);
|
||||||
|
Document d = JsoupEx.parse(file);
|
||||||
|
for (Element element : d.select(query))
|
||||||
|
result.add(element.text());
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
Log.e("EXPR", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.i("EXPR jsoup(" + parameterValues[0] + ")=" + TextUtils.join(", ", result));
|
||||||
|
return new EvaluationValue(result, ExpressionConfiguration.defaultConfiguration());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@InfixOperator(precedence = OPERATOR_PRECEDENCE_COMPARISON)
|
@InfixOperator(precedence = OPERATOR_PRECEDENCE_COMPARISON)
|
||||||
public static class ContainsOperator extends AbstractOperator {
|
public static class ContainsOperator extends AbstractOperator {
|
||||||
private final boolean regex;
|
private final boolean regex;
|
||||||
|
@ -871,6 +902,7 @@ public class EntityRule {
|
||||||
BlocklistFunction fBlocklist = new BlocklistFunction(context, message, headers);
|
BlocklistFunction fBlocklist = new BlocklistFunction(context, message, headers);
|
||||||
MxFunction fMx = new MxFunction(context, message);
|
MxFunction fMx = new MxFunction(context, message);
|
||||||
AttachmentsFunction fAttachments = new AttachmentsFunction(context, message);
|
AttachmentsFunction fAttachments = new AttachmentsFunction(context, message);
|
||||||
|
JsoupFunction fJsoup = new JsoupFunction(context, message);
|
||||||
|
|
||||||
ContainsOperator oContains = new ContainsOperator(false);
|
ContainsOperator oContains = new ContainsOperator(false);
|
||||||
ContainsOperator oMatches = new ContainsOperator(true);
|
ContainsOperator oMatches = new ContainsOperator(true);
|
||||||
|
@ -883,6 +915,7 @@ public class EntityRule {
|
||||||
configuration.getFunctionDictionary().addFunction("onBlocklist", fBlocklist);
|
configuration.getFunctionDictionary().addFunction("onBlocklist", fBlocklist);
|
||||||
configuration.getFunctionDictionary().addFunction("hasMx", fMx);
|
configuration.getFunctionDictionary().addFunction("hasMx", fMx);
|
||||||
configuration.getFunctionDictionary().addFunction("attachments", fAttachments);
|
configuration.getFunctionDictionary().addFunction("attachments", fAttachments);
|
||||||
|
configuration.getFunctionDictionary().addFunction("Jsoup", fJsoup);
|
||||||
|
|
||||||
configuration.getOperatorDictionary().addOperator("Contains", oContains);
|
configuration.getOperatorDictionary().addOperator("Contains", oContains);
|
||||||
configuration.getOperatorDictionary().addOperator("Matches", oMatches);
|
configuration.getOperatorDictionary().addOperator("Matches", oMatches);
|
||||||
|
|
|
@ -1520,6 +1520,7 @@ X-Google-Original-From: Somebody <somebody+extra@example.org></code></pre>
|
||||||
<li><em>onBlocklist()</em> (returns a boolean indicating if the sender/server is on a DNS blocklist; since version 1.2179)</li>
|
<li><em>onBlocklist()</em> (returns a boolean indicating if the sender/server is on a DNS blocklist; since version 1.2179)</li>
|
||||||
<li><em>hasMx()</em> (returns a boolean indicating if the from/reply-to address has an associated MX record; since version 1.2179)</li>
|
<li><em>hasMx()</em> (returns a boolean indicating if the from/reply-to address has an associated MX record; since version 1.2179)</li>
|
||||||
<li><em>attachments()</em> (returns an integer indicating number of attachments; since version 1.2179)</li>
|
<li><em>attachments()</em> (returns an integer indicating number of attachments; since version 1.2179)</li>
|
||||||
|
<li><em>Jsoup()</em> (returns an array of selected strings; since version 1.2179)</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>Example conditions:</p>
|
<p>Example conditions:</p>
|
||||||
<p><code>header("X-Mailer") contains "Open-Xchange" && from matches ".*service@.*"</code></p>
|
<p><code>header("X-Mailer") contains "Open-Xchange" && from matches ".*service@.*"</code></p>
|
||||||
|
|
Loading…
Reference in a new issue