1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-02-23 14:41:08 +00:00

Added keywords to header condition

This commit is contained in:
M66B 2021-11-10 16:01:19 +01:00
parent 8a8e27b757
commit e4d754b5cc
2 changed files with 55 additions and 17 deletions

17
FAQ.md
View file

@ -2363,6 +2363,23 @@ Some common header conditions (regex):
* *.*Auto-Submitted:.** [RFC3834](https://tools.ietf.org/html/rfc3834) * *.*Auto-Submitted:.** [RFC3834](https://tools.ietf.org/html/rfc3834)
* *.*Content-Type: multipart/report.** [RFC3462](https://tools.ietf.org/html/rfc3462) * *.*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. 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. The POP3 protocol does not support setting keywords and moving or copying messages.

View file

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