Added keywords to header condition

pull/194/merge
M66B 3 years ago
parent 8a8e27b757
commit e4d754b5cc

@ -2363,6 +2363,23 @@ Some common header conditions (regex):
* *.*Auto-Submitted:.** [RFC3834](https://tools.ietf.org/html/rfc3834)
* *.*Content-Type: multipart/report.** [RFC3462](https://tools.ietf.org/html/rfc3462)
You can match IMAP flags (keywords) via a header condition too (from version 1.1777), like this:
```
$<keyword>$
```
You can use these special values too, representing common system flags:
```
$$seen$
$$answered$
$$flagged$
$$deleted$
```
Note that *regex* should be disable and that there should be no white space.
In the three-dots *more* message menu there is an item to create a rule for a received message with the most common conditions filled in.
The POP3 protocol does not support setting keywords and moving or copying messages.

@ -239,25 +239,46 @@ public class EntityRule {
String value = jheader.getString("value");
boolean regex = jheader.getBoolean("regex");
boolean matches = false;
Enumeration<Header> headers;
if (imessage != null)
headers = imessage.getAllHeaders();
else if (message.headers != null) {
ByteArrayInputStream bis = new ByteArrayInputStream(message.headers.getBytes());
headers = new InternetHeaders(bis).getAllHeaders();
} else
throw new IllegalArgumentException(context.getString(R.string.title_rule_no_headers));
while (headers.hasMoreElements()) {
Header header = headers.nextElement();
String formatted = header.getName() + ": " + header.getValue();
if (matches(context, message, value, formatted, regex)) {
matches = true;
break;
if (!regex &&
value != null &&
value.startsWith("$") &&
value.endsWith("$")) {
String keyword = value.substring(1, value.length() - 1);
List<String> keywords = new ArrayList<>();
if (message.ui_seen)
keywords.add("$seen");
if (message.ui_answered)
keywords.add("$answered");
if (message.ui_flagged)
keywords.add("$flagged");
if (message.ui_deleted)
keywords.add("$deleted");
keywords.addAll(Arrays.asList(message.keywords));
if (!keywords.contains(keyword))
return false;
} else {
boolean matches = false;
Enumeration<Header> headers;
if (imessage != null)
headers = imessage.getAllHeaders();
else if (message.headers != null) {
ByteArrayInputStream bis = new ByteArrayInputStream(message.headers.getBytes());
headers = new InternetHeaders(bis).getAllHeaders();
} else
throw new IllegalArgumentException(context.getString(R.string.title_rule_no_headers));
while (headers.hasMoreElements()) {
Header header = headers.nextElement();
String formatted = header.getName() + ": " + header.getValue();
if (matches(context, message, value, formatted, regex)) {
matches = true;
break;
}
}
if (!matches)
return false;
}
if (!matches)
return false;
}
// Date

Loading…
Cancel
Save