(Context context, EntityMessage message, EntityFolder junk, boolean block_domain)
| 1690 | } |
| 1691 | |
| 1692 | @NonNull |
| 1693 | static List<EntityRule> blockSender(Context context, EntityMessage message, EntityFolder junk, boolean block_domain) throws JSONException { |
| 1694 | List<EntityRule> rules = new ArrayList<>(); |
| 1695 | |
| 1696 | if (message.from == null) |
| 1697 | return rules; |
| 1698 | |
| 1699 | List<String> domains = new ArrayList<>(); |
| 1700 | for (Address from : message.from) { |
| 1701 | String sender = ((InternetAddress) from).getAddress(); |
| 1702 | String name = MessageHelper.formatAddresses(new Address[]{from}); |
| 1703 | |
| 1704 | if (TextUtils.isEmpty(sender)) |
| 1705 | continue; |
| 1706 | |
| 1707 | boolean regex = false; |
| 1708 | if (block_domain) { |
| 1709 | String domain = UriHelper.getEmailDomain(sender); |
| 1710 | if (domain != null) |
| 1711 | domain = domain.trim(); |
| 1712 | if (!TextUtils.isEmpty(domain) && !domains.contains(domain)) { |
| 1713 | String parent = UriHelper.getParentDomain(context, domain); |
| 1714 | if (parent != null) |
| 1715 | domain = parent; |
| 1716 | domains.add(domain); |
| 1717 | regex = true; |
| 1718 | sender = ".*@.*" + Pattern.quote(domain) + ".*"; |
| 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | JSONObject jsender = new JSONObject(); |
| 1723 | jsender.put("value", sender); |
| 1724 | jsender.put("regex", regex); |
| 1725 | |
| 1726 | JSONObject jcondition = new JSONObject(); |
| 1727 | jcondition.put("sender", jsender); |
| 1728 | |
| 1729 | JSONObject jaction = new JSONObject(); |
| 1730 | jaction.put("type", TYPE_MOVE); |
| 1731 | jaction.put("target", junk.id); |
| 1732 | jaction.put("seen", true); |
| 1733 | |
| 1734 | EntityRule rule = new EntityRule(); |
| 1735 | rule.folder = message.folder; |
| 1736 | rule.name = context.getString(R.string.title_block, name); |
| 1737 | rule.order = 1000; |
| 1738 | rule.enabled = true; |
| 1739 | rule.stop = true; |
| 1740 | rule.condition = jcondition.toString(); |
| 1741 | rule.action = jaction.toString(); |
| 1742 | |
| 1743 | rules.add(rule); |
| 1744 | } |
| 1745 | |
| 1746 | return rules; |
| 1747 | } |
| 1748 | |
| 1749 | boolean isBlockingSender(EntityMessage message, EntityFolder junk) throws JSONException { |
no test coverage detected