mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-01 09:16:00 +00:00
Added expression function size()
This commit is contained in:
parent
efff870d97
commit
ad53d3d1ea
3 changed files with 23 additions and 0 deletions
1
FAQ.md
1
FAQ.md
|
@ -2780,6 +2780,7 @@ The following extra functions are available:
|
||||||
* *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)
|
* *Jsoup()* (returns an array of selected strings; since version 1.2179)
|
||||||
|
* *Size(array)* (returns the number of items in an array; since version 1.2179)
|
||||||
|
|
||||||
Example conditions:
|
Example conditions:
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,7 @@ public class ExpressionHelper {
|
||||||
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);
|
JsoupFunction fJsoup = new JsoupFunction(context, message);
|
||||||
|
SizeFunction fSize = new SizeFunction();
|
||||||
|
|
||||||
ContainsOperator oContains = new ContainsOperator(false);
|
ContainsOperator oContains = new ContainsOperator(false);
|
||||||
ContainsOperator oMatches = new ContainsOperator(true);
|
ContainsOperator oMatches = new ContainsOperator(true);
|
||||||
|
@ -107,6 +108,7 @@ public class ExpressionHelper {
|
||||||
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.getFunctionDictionary().addFunction("Jsoup", fJsoup);
|
||||||
|
configuration.getFunctionDictionary().addFunction("Size", fSize);
|
||||||
|
|
||||||
configuration.getOperatorDictionary().addOperator("Contains", oContains);
|
configuration.getOperatorDictionary().addOperator("Contains", oContains);
|
||||||
configuration.getOperatorDictionary().addOperator("Matches", oMatches);
|
configuration.getOperatorDictionary().addOperator("Matches", oMatches);
|
||||||
|
@ -343,6 +345,25 @@ public class ExpressionHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FunctionParameter(name = "value")
|
||||||
|
public static class SizeFunction extends AbstractFunction {
|
||||||
|
SizeFunction() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EvaluationValue evaluate(
|
||||||
|
Expression expression, Token functionToken, EvaluationValue... parameterValues) {
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
if (parameterValues.length == 1 &&
|
||||||
|
parameterValues[0].getDataType() == EvaluationValue.DataType.ARRAY)
|
||||||
|
result = parameterValues[0].getArrayValue().size();
|
||||||
|
|
||||||
|
Log.i("EXPR size()=" + result);
|
||||||
|
return expression.convertValue(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@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;
|
||||||
|
|
|
@ -1521,6 +1521,7 @@ X-Google-Original-From: Somebody <somebody+extra@example.org></code></pre>
|
||||||
<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>
|
<li><em>Jsoup()</em> (returns an array of selected strings; since version 1.2179)</li>
|
||||||
|
<li><em>Size(array)</em> (returns the number of items in an array; 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