mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-29 13:24:52 +02:00
Added rule recipient condition
This commit is contained in:
@@ -26,8 +26,11 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.mail.Address;
|
||||
@@ -83,6 +86,7 @@ public class EntityRule {
|
||||
try {
|
||||
JSONObject jcondition = new JSONObject(condition);
|
||||
|
||||
// Sender
|
||||
JSONObject jsender = jcondition.optJSONObject("sender");
|
||||
if (jsender != null) {
|
||||
String value = jsender.getString("value");
|
||||
@@ -104,6 +108,31 @@ public class EntityRule {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Recipient
|
||||
JSONObject jrecipient = jcondition.optJSONObject("recipient");
|
||||
if (jrecipient != null) {
|
||||
String value = jrecipient.getString("value");
|
||||
boolean regex = jrecipient.getBoolean("regex");
|
||||
|
||||
boolean matches = false;
|
||||
List<Address> recipients = new ArrayList<>();
|
||||
if (message.to != null)
|
||||
recipients.addAll(Arrays.asList(message.to));
|
||||
if (message.cc != null)
|
||||
recipients.addAll(Arrays.asList(message.cc));
|
||||
for (Address recipient : recipients) {
|
||||
InternetAddress ia = (InternetAddress) recipient;
|
||||
String personal = ia.getPersonal();
|
||||
String formatted = ((personal == null ? "" : personal + " ") + "<" + ia.getAddress() + ">");
|
||||
if (matches(context, value, formatted, regex)) {
|
||||
matches = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!matches)
|
||||
return false;
|
||||
}
|
||||
|
||||
JSONObject jsubject = jcondition.optJSONObject("subject");
|
||||
if (jsubject != null) {
|
||||
String value = jsubject.getString("value");
|
||||
@@ -133,7 +162,7 @@ public class EntityRule {
|
||||
}
|
||||
|
||||
// Safeguard
|
||||
if (jsender == null && jsubject == null && jheader == null)
|
||||
if (jsender == null && jrecipient == null && jsubject == null && jheader == null)
|
||||
return false;
|
||||
} catch (JSONException ex) {
|
||||
Log.e(ex);
|
||||
|
||||
Reference in New Issue
Block a user