Added regex to attachments expression

pull/215/head
M66B 7 months ago
parent d3c8bbf73b
commit 68e46b0043

@ -2791,7 +2791,7 @@ The following extra functions are available:
* *blocklist()* (version 1.2176-1.2178; deprecated, use *onBlocklist()* instead)
* *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)
* *attachments()* (returns an integer indicating number of attachments; since version 1.2179)
* *attachments(regex)* (returns an integer indicating number of attachments; since version 1.2179; optional regex since version 1.2194)
* *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)
* *knownContact()* (returns a boolean indicating that the from/reply-to address is in the Android address book or in the local contacts database)

@ -312,6 +312,7 @@ public class ExpressionHelper {
}
}
@FunctionParameter(name = "value")
public static class AttachmentsFunction extends AbstractFunction {
private final Context context;
private final EntityMessage message;
@ -325,9 +326,19 @@ public class ExpressionHelper {
public EvaluationValue evaluate(
Expression expression, Token functionToken, EvaluationValue... parameterValues) {
int result = 0;
String regex = null;
if (message != null) {
DB db = DB.getInstance(context);
if (parameterValues.length == 1) {
regex = parameterValues[0].getStringValue();
Pattern p = Pattern.compile(regex);
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
if (attachments != null)
for (EntityAttachment attachment : attachments)
if (attachment.name != null && p.matcher(attachment.name).matches())
result++;
} else
result = db.attachment().countAttachments(message.id);
}

Loading…
Cancel
Save