1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-22 07:42:52 +00:00

Added regex to attachments expression

This commit is contained in:
M66B 2024-06-02 12:12:36 +02:00
parent d3c8bbf73b
commit 68e46b0043
2 changed files with 13 additions and 2 deletions

2
FAQ.md
View file

@ -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)

View file

@ -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,10 +326,20 @@ 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);
result = db.attachment().countAttachments(message.id);
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);
}
Log.i("EXPR attachments()=" + result);