diff --git a/FAQ.md b/FAQ.md index a5e425ea7e..69270188d2 100644 --- a/FAQ.md +++ b/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) * *attachments()* (returns an integer indicating number of attachments; 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: diff --git a/app/src/main/java/eu/faircode/email/ExpressionHelper.java b/app/src/main/java/eu/faircode/email/ExpressionHelper.java index 60614c75ed..754cccec41 100644 --- a/app/src/main/java/eu/faircode/email/ExpressionHelper.java +++ b/app/src/main/java/eu/faircode/email/ExpressionHelper.java @@ -94,6 +94,7 @@ public class ExpressionHelper { MxFunction fMx = new MxFunction(context, message); AttachmentsFunction fAttachments = new AttachmentsFunction(context, message); JsoupFunction fJsoup = new JsoupFunction(context, message); + SizeFunction fSize = new SizeFunction(); ContainsOperator oContains = new ContainsOperator(false); ContainsOperator oMatches = new ContainsOperator(true); @@ -107,6 +108,7 @@ public class ExpressionHelper { configuration.getFunctionDictionary().addFunction("hasMx", fMx); configuration.getFunctionDictionary().addFunction("attachments", fAttachments); configuration.getFunctionDictionary().addFunction("Jsoup", fJsoup); + configuration.getFunctionDictionary().addFunction("Size", fSize); configuration.getOperatorDictionary().addOperator("Contains", oContains); 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) public static class ContainsOperator extends AbstractOperator { private final boolean regex; diff --git a/index.html b/index.html index bdceee734c..7586d3ea29 100644 --- a/index.html +++ b/index.html @@ -1521,6 +1521,7 @@ X-Google-Original-From: Somebody <somebody+extra@example.org>
  • 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)
  • 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:

    header("X-Mailer") contains "Open-Xchange" && from matches ".*service@.*"