Skip to content

Commit

Permalink
feat: [CO-959] Filter out read-receipt notification mails from BulkTe…
Browse files Browse the repository at this point in the history
…st Sieve filter (#509)

* feat: exclude bulk readReceipt notification mails in BulkTest SIEVE filter
  • Loading branch information
aheeva-yuliya authored May 15, 2024
1 parent 53bcd6d commit a0ae2a9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
26 changes: 12 additions & 14 deletions store/src/main/java/com/zimbra/cs/filter/jsieve/BulkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -103,5 +102,4 @@ protected boolean executeBasic(MailAdapter mail, Arguments args, SieveContext ct
}
return false;
}

}
18 changes: 14 additions & 4 deletions store/src/test/java/com/zimbra/cs/filter/BulkTestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String, Object>());
prov.createAccount("test@zimbra.com", "secret", new HashMap<>());
MailboxTestUtil.clearData();
account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
Expand All @@ -51,7 +52,7 @@ public static void init() throws Exception {
}

@Test
void precidence() throws Exception {
void precedence() throws Exception {
List<ItemId> 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);
Expand All @@ -71,6 +72,16 @@ void zimbraOOO() throws Exception {
assertNull(ArrayUtil.getFirstElement(msg.getTags()));
}

@Test
void shouldFilterOutBulkReadReceiptDeliveryReport() throws Exception {
List<ItemId> 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<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mailbox), mailbox,
Expand Down Expand Up @@ -109,7 +120,7 @@ void unsubscribe() throws Exception {
}

@Test
void proofpoint() throws Exception {
void proofPoint() throws Exception {
List<ItemId> 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 " +
Expand All @@ -120,5 +131,4 @@ void proofpoint() throws Exception {
Message msg = mailbox.getMessageById(null, ids.get(0).getId());
assertEquals("bulk", ArrayUtil.getFirstElement(msg.getTags()));
}

}

0 comments on commit a0ae2a9

Please sign in to comment.