Refactoring

pull/194/merge
M66B 3 years ago
parent 9279435e06
commit 86c26e895b

@ -1019,6 +1019,7 @@ public class EntityRule {
if (message.from == null) if (message.from == null)
return rules; return rules;
List<String> domains = new ArrayList<>();
for (Address from : message.from) { for (Address from : message.from) {
String sender = ((InternetAddress) from).getAddress(); String sender = ((InternetAddress) from).getAddress();
String name = MessageHelper.formatAddresses(new Address[]{from}); String name = MessageHelper.formatAddresses(new Address[]{from});
@ -1029,10 +1030,11 @@ public class EntityRule {
boolean regex = false; boolean regex = false;
if (block_domain) { if (block_domain) {
int at = sender.indexOf('@'); String domain = UriHelper.getEmailDomain(sender);
if (at > 0) { if (!TextUtils.isEmpty(domain) && !domains.contains(domain)) {
domains.add(domain);
regex = true; regex = true;
sender = ".*@.*" + Pattern.quote(sender.substring(at + 1)) + ".*"; sender = ".*@.*" + Pattern.quote(domain) + ".*";
} }
} }

@ -323,22 +323,21 @@ public class FragmentDialogJunk extends FragmentDialogBase {
} }
}); });
List<String> regex = new ArrayList<>();
regex.addAll(COMMON_DOMAINS);
regex.addAll(EmailProvider.getDomainNames(context));
boolean common = false; boolean common = false;
List<String> domains = new ArrayList<>(); List<String> domains = new ArrayList<>();
if (froms != null) if (froms != null)
for (Address from : froms) { for (Address from : froms) {
String email = ((InternetAddress) from).getAddress(); String email = ((InternetAddress) from).getAddress();
int at = (email == null ? -1 : email.indexOf('@')); String domain = UriHelper.getEmailDomain(email);
String domain = (at < 0 ? null : email.substring(at + 1).toLowerCase(Locale.ROOT)); if (TextUtils.isEmpty(domain) || domains.contains(domain))
if (TextUtils.isEmpty(domain))
continue; continue;
domains.add(domain); domains.add(domain);
List<String> regex = new ArrayList<>();
regex.addAll(COMMON_DOMAINS);
regex.addAll(EmailProvider.getDomainNames(context));
for (String r : regex) for (String r : regex)
if (domain.matches(r)) { if (domain.matches(r)) {
common = true; common = true;

Loading…
Cancel
Save