From a0ae2a97ccce9c99e399fcedb6a0c7dff8ac4e5c Mon Sep 17 00:00:00 2001 From: Yuliya Aheeva <88840377+aheeva-yuliya@users.noreply.github.com> Date: Wed, 15 May 2024 10:51:03 +0300 Subject: [PATCH] feat: [CO-959] Filter out read-receipt notification mails from BulkTest Sieve filter (#509) * feat: exclude bulk readReceipt notification mails in BulkTest SIEVE filter --- .../com/zimbra/cs/filter/jsieve/BulkTest.java | 26 +++++++++---------- .../com/zimbra/cs/filter/BulkTestTest.java | 18 ++++++++++--- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/store/src/main/java/com/zimbra/cs/filter/jsieve/BulkTest.java b/store/src/main/java/com/zimbra/cs/filter/jsieve/BulkTest.java index e623996c1ce..3739ed8c5c3 100644 --- a/store/src/main/java/com/zimbra/cs/filter/jsieve/BulkTest.java +++ b/store/src/main/java/com/zimbra/cs/filter/jsieve/BulkTest.java @@ -25,7 +25,7 @@ import com.zimbra.cs.util.AccountUtil; /** - * SIEVE test whether or not the message is a bulk mail (legitimate mass marketing mail). + * SIEVE test whether the message is a bulk mail (legitimate mass marketing mail). * * @author ysasaki */ @@ -37,6 +37,7 @@ public final class BulkTest extends AbstractTest { private static final String X_PROOFPOINT_SPAM_DETAILS = "X-PROOFPOINT-SPAM-DETAILS"; private static final String AUTO_SUBMITTED = "Auto-Submitted"; private static final String ZIMBRA_OOO_AUTO_REPLY = "auto-replied (zimbra; vacation)"; + public static final String AUTO_REPLIED_ZIMBRA_READ_RECEIPT = "auto-replied (zimbra; read-receipt)"; @Override protected boolean executeBasic(MailAdapter mail, Arguments args, SieveContext ctx) throws SieveException { @@ -68,20 +69,18 @@ protected boolean executeBasic(MailAdapter mail, Arguments args, SieveContext ct ZimbraLog.filter.error("Failed to lookup my addresses", e); } } else if (PRECEDENCE.equals(name)) { // test "Precedence: bulk" + boolean shouldInclude = true; for (String precedence : adapter.getHeader(PRECEDENCE)) { - if ("bulk".equalsIgnoreCase(precedence)) { - boolean zimbraOOONotif = false; - for (String autoSubmitted : mail.getHeader(AUTO_SUBMITTED)) { - if (ZIMBRA_OOO_AUTO_REPLY.equals(autoSubmitted)) { - zimbraOOONotif = true; - break; - } - } - if (!zimbraOOONotif) { - return true; - } - } + if ("bulk".equalsIgnoreCase(precedence) && mail.getHeader(AUTO_SUBMITTED).stream() + .anyMatch(autoSubmitted -> + ZIMBRA_OOO_AUTO_REPLY.equals(autoSubmitted) + || AUTO_REPLIED_ZIMBRA_READ_RECEIPT.equals(autoSubmitted) + )) { + shouldInclude = false; + break; + } } + return shouldInclude; } else if (name.contains("CAMPAIGN")) { // test *CAMPAIGN* return true; } else if (name.equals(X_PROOFPOINT_SPAM_DETAILS)) { // test Proofpoint bulkscore > 50 @@ -103,5 +102,4 @@ protected boolean executeBasic(MailAdapter mail, Arguments args, SieveContext ct } return false; } - } diff --git a/store/src/test/java/com/zimbra/cs/filter/BulkTestTest.java b/store/src/test/java/com/zimbra/cs/filter/BulkTestTest.java index 3b1e966b088..361818b47ad 100644 --- a/store/src/test/java/com/zimbra/cs/filter/BulkTestTest.java +++ b/store/src/test/java/com/zimbra/cs/filter/BulkTestTest.java @@ -13,6 +13,7 @@ import com.zimbra.common.util.ArrayUtil; +import static com.zimbra.cs.filter.jsieve.BulkTest.AUTO_REPLIED_ZIMBRA_READ_RECEIPT; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; @@ -42,7 +43,7 @@ public final class BulkTestTest { public static void init() throws Exception { MailboxTestUtil.initServer(); Provisioning prov = Provisioning.getInstance(); - prov.createAccount("test@zimbra.com", "secret", new HashMap()); + prov.createAccount("test@zimbra.com", "secret", new HashMap<>()); MailboxTestUtil.clearData(); account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID); RuleManager.clearCachedRules(account); @@ -51,7 +52,7 @@ public static void init() throws Exception { } @Test - void precidence() throws Exception { + void precedence() throws Exception { List ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mailbox), mailbox, new ParsedMessage("From: sender@zimbra.com\nPrecedence: bulk\nSubject: bulk".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true); @@ -71,6 +72,16 @@ void zimbraOOO() throws Exception { assertNull(ArrayUtil.getFirstElement(msg.getTags())); } + @Test + void shouldFilterOutBulkReadReceiptDeliveryReport() throws Exception { + List ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mailbox), mailbox, + new ParsedMessage(("From: sender@zimbra.com\nPrecedence: bulk\nAuto-Submitted:" + AUTO_REPLIED_ZIMBRA_READ_RECEIPT + "\nSubject: bulk").getBytes(), false), + 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true); + assertEquals(1, ids.size()); + Message msg = mailbox.getMessageById(null, ids.get(0).getId()); + assertNull(ArrayUtil.getFirstElement(msg.getTags())); + } + @Test void abuse() throws Exception { List ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mailbox), mailbox, @@ -109,7 +120,7 @@ void unsubscribe() throws Exception { } @Test - void proofpoint() throws Exception { + void proofPoint() throws Exception { List ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mailbox), mailbox, new ParsedMessage(("To: list@zimbra.com\nX-Proofpoint-Spam-Details: rule=tag_notspam policy=tag " + "score=0 spamscore=0 ipscore=0 suspectscore=49 phishscore=0 bulkscore=100 adultscore=0 " + @@ -120,5 +131,4 @@ void proofpoint() throws Exception { Message msg = mailbox.getMessageById(null, ids.get(0).getId()); assertEquals("bulk", ArrayUtil.getFirstElement(msg.getTags())); } - }