mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-29 05:15:13 +02:00
Added received time to expression
This commit is contained in:
@@ -155,10 +155,6 @@ public class EntityRule {
|
||||
private static final int MAX_NOTES_LENGTH = 512; // characters
|
||||
private static final int URL_TIMEOUT = 15 * 1000; // milliseconds
|
||||
|
||||
private static final List<String> EXPR_VARIABLES = Collections.unmodifiableList(Arrays.asList(
|
||||
"to", "from", "subject", "text", "hasAttachments"
|
||||
));
|
||||
|
||||
static boolean needsHeaders(EntityMessage message, List<EntityRule> rules) {
|
||||
return needsHeaders(rules);
|
||||
}
|
||||
@@ -691,16 +687,8 @@ public class EntityRule {
|
||||
void validate(Context context) throws JSONException, IllegalArgumentException {
|
||||
try {
|
||||
Expression expression = ExpressionHelper.getExpression(this, null, null, null, context);
|
||||
if (expression != null) {
|
||||
for (String variable : expression.getUsedVariables()) {
|
||||
Log.i("EXPR variable=" + variable);
|
||||
if (!EXPR_VARIABLES.contains(variable))
|
||||
throw new IllegalArgumentException("Unknown variable '" + variable + "'");
|
||||
}
|
||||
Log.i("EXPR validating");
|
||||
expression.validate();
|
||||
Log.i("EXPR validated");
|
||||
}
|
||||
if (expression != null)
|
||||
ExpressionHelper.check(expression);
|
||||
} catch (ParseException | MessagingException ex) {
|
||||
Log.w("EXPR", ex);
|
||||
String message = ex.getMessage();
|
||||
|
||||
@@ -60,6 +60,21 @@ import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.InternetHeaders;
|
||||
|
||||
public class ExpressionHelper {
|
||||
private static final List<String> EXPR_VARIABLES = Collections.unmodifiableList(Arrays.asList(
|
||||
"received", "to", "from", "subject", "text", "hasAttachments"
|
||||
));
|
||||
|
||||
static void check(Expression expression) throws ParseException {
|
||||
for (String variable : expression.getUsedVariables()) {
|
||||
Log.i("EXPR variable=" + variable);
|
||||
if (!EXPR_VARIABLES.contains(variable))
|
||||
throw new IllegalArgumentException("Unknown variable '" + variable + "'");
|
||||
}
|
||||
Log.i("EXPR validating");
|
||||
expression.validate();
|
||||
Log.i("EXPR validated");
|
||||
}
|
||||
|
||||
static Expression getExpression(EntityRule rule, EntityMessage message, List<Header> headers, String html, Context context) throws JSONException, ParseException, MessagingException {
|
||||
// https://ezylang.github.io/EvalEx/
|
||||
|
||||
@@ -120,6 +135,7 @@ public class ExpressionHelper {
|
||||
configuration.getOperatorDictionary().addOperator("Matches", oMatches);
|
||||
|
||||
Expression expression = new Expression(eval, configuration)
|
||||
.with("received", message == null ? null : message.received)
|
||||
.with("to", to)
|
||||
.with("from", from)
|
||||
.with("subject", message == null ? null : message.subject)
|
||||
|
||||
Reference in New Issue
Block a user