use of com.zimbra.client.ZFilterRules in project zm-mailbox by Zimbra.
the class TestFilter method saveOutgoingRules.
/**
* Saves the given outgoing filter rules. Then gets them from the server and confirms that
* the element tree matches.
*/
private void saveOutgoingRules(ZMailbox mbox, ZFilterRules rules) throws Exception {
mbox.saveOutgoingFilterRules(rules);
ZFilterRules result = mbox.getOutgoingFilterRules(true);
TestUtil.assertEquals(rules.dump(), result.dump());
}
use of com.zimbra.client.ZFilterRules in project zm-mailbox by Zimbra.
the class TestFilter method testSpam.
/**
* Confirms that spam filtering takes a higher precedence than
* custom user filtering (bug 23886).
*/
public void testSpam() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
String sender = TestUtil.getAddress(USER_NAME);
String[] recipients = new String[] { sender };
String message = TestUtil.getTestMessage(NAME_PREFIX + " testSpam", USER_NAME, USER_NAME, null);
Config config = Provisioning.getInstance().getConfig();
message = config.getAttr(Provisioning.A_zimbraSpamHeader) + ": " + config.getAttr(Provisioning.A_zimbraSpamHeaderValue) + "\r\n" + message;
// Make sure spam message doesn't already exist
assertEquals(0, TestUtil.search(mbox, "in:junk subject:testSpam").size());
// Deliver spam message without matching rule, make sure it gets delivered
// to the junk folder, and delete.
TestUtil.addMessageLmtp(recipients, sender, message);
ZMessage msg = TestUtil.getMessage(mbox, "in:junk subject:testSpam");
mbox.deleteMessage(msg.getId());
// Add matching filter rule: if subject contains "testSpam", file into folder1
ZFilterRules rules = getTestIncomingRules();
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "testSpam"));
actions.add(new ZFileIntoAction(FOLDER1_PATH));
rules.getRules().add(new ZFilterRule("testBug5455", true, false, conditions, actions));
saveIncomingRules(mMbox, rules);
// Set "apply user rules" attribute to TRUE and make sure the message gets filed into folder1
TestUtil.setAccountAttr(USER_NAME, Provisioning.A_zimbraSpamApplyUserFilters, LdapConstants.LDAP_TRUE);
TestUtil.addMessageLmtp(recipients, sender, message);
msg = TestUtil.waitForMessage(mbox, "in:" + FOLDER1_PATH + " subject:testSpam");
mbox.deleteMessage(msg.getId());
// Set "apply user rules" attribute to FALSE and make sure the message gets filed into junk
TestUtil.setAccountAttr(USER_NAME, Provisioning.A_zimbraSpamApplyUserFilters, LdapConstants.LDAP_FALSE);
TestUtil.addMessageLmtp(recipients, sender, message);
TestUtil.waitForMessage(mbox, "in:junk subject:testSpam");
}
use of com.zimbra.client.ZFilterRules in project zm-mailbox by Zimbra.
the class TestFilter method testNotifyActionUseOrigHeaders.
@Test
public void testNotifyActionUseOrigHeaders() throws Exception {
if (mAvailableRFCCompliantNotify) {
fail("Unable to test because 'zimbraSieveNotifyActionRFCCompliant' is set to TRUE");
return;
}
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
conditions.add(new ZFilterCondition.ZTrueCondition());
// add an action to notify user2
// copy headers From,To,Cc,Subject from the original message onto the notification message
actions.add(new ZFilterAction.ZNotifyAction(TestUtil.getAddress(REMOTE_USER_NAME), null, "${BODY}", -1, "From,To,Cc,Subject"));
rules.add(new ZFilterRule("testNotifyActionUseOrigHeaders", true, false, conditions, actions));
saveIncomingRules(mMbox, new ZFilterRules(rules));
String subject = NAME_PREFIX + " testNotifyActionUseOrigHeaders";
String body = "Hi, How r u?";
String msg = new MessageBuilder().withFrom(REMOTE_USER_NAME).withToRecipient(USER_NAME).withCcRecipient(USER_NAME).withSubject(subject).withBody(body).create();
// send msg to user1
TestUtil.addMessageLmtp(new String[] { USER_NAME }, REMOTE_USER_NAME, msg);
// check notification msg from user1 in user2's mailbox
ZMessage zMessage = TestUtil.waitForMessage(TestUtil.getZMailbox(REMOTE_USER_NAME), "in:inbox subject:\"" + subject + "\"");
boolean checkedFrom = false, checkedTo = false, checkedCc = false;
List<ZEmailAddress> msgAddrs = zMessage.getEmailAddresses();
for (ZEmailAddress addr : msgAddrs) {
if ("f".equals(addr.getType())) {
assertEquals(TestUtil.addDomainIfNecessary(REMOTE_USER_NAME), addr.getAddress());
if (!checkedFrom) {
checkedFrom = true;
} else {
fail("multiple From addresses");
}
}
if ("t".equals(addr.getType())) {
assertEquals(TestUtil.addDomainIfNecessary(USER_NAME), addr.getAddress());
if (!checkedTo) {
checkedTo = true;
} else {
fail("multiple To addresses");
}
}
if ("c".equals(addr.getType())) {
assertEquals(TestUtil.addDomainIfNecessary(USER_NAME), addr.getAddress());
if (!checkedCc) {
checkedCc = true;
} else {
fail("multiple Cc addresses");
}
}
}
assertEquals(subject, zMessage.getSubject());
}
use of com.zimbra.client.ZFilterRules in project zm-mailbox by Zimbra.
the class TestFilter method testMarkRead.
@Test
public void testMarkRead() throws Exception {
String folderName = NAME_PREFIX + " testMarkRead";
// if the subject contains "testMarkRead", file into a folder and mark read
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "testMarkRead"));
actions.add(new ZFileIntoAction(folderName));
actions.add(new ZMarkAction(MarkOp.READ));
rules.add(new ZFilterRule("testMarkRead", true, false, conditions, actions));
saveIncomingRules(mMbox, new ZFilterRules(rules));
// Deliver message.
String address = TestUtil.getAddress(USER_NAME);
String subject = NAME_PREFIX + " testMarkRead";
TestUtil.addMessageLmtp(subject, address, address);
// Check folder and unread state.
ZMessage msg = TestUtil.getMessage(mMbox, "in:\"" + folderName + "\" subject:\"" + subject + "\"");
String flags = msg.getFlags();
assertTrue("Unexpected flags: " + flags, flags == null || flags.indexOf(ZMessage.Flag.unread.getFlagChar()) < 0);
}
use of com.zimbra.client.ZFilterRules in project zm-mailbox by Zimbra.
the class TestFilter method testSpecialCharInBody.
/**
* Tests fix for bug 56019.
*/
@Test
public void testSpecialCharInBody() throws Exception {
assertTrue("To run this test copy data/unittest/TestFilter-testSpecialCharInBody.msg to /opt/zimbra/unittest", Files.exists(Paths.get("/opt/zimbra/unittest/TestFilter-testSpecialCharInBody.msg")));
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
conditions.add(new ZBodyCondition(BodyOp.CONTAINS, "André"));
actions.add(new ZMarkAction(MarkOp.FLAGGED));
rules.add(new ZFilterRule("testSpecialCharInBody", true, false, conditions, actions));
ZFilterRules zRules = new ZFilterRules(rules);
saveIncomingRules(mMbox, zRules);
// Add a message and test the flagged state.
String address = TestUtil.getAddress(USER_NAME);
// TestFilter-testSpecialCharInBody.msg's body contains base64 encoded content (containing "André")
String msgContent = new String(ByteUtil.getContent(new File("/opt/zimbra/unittest/TestFilter-testSpecialCharInBody.msg")));
TestUtil.addMessageLmtp(new String[] { address }, address, msgContent);
ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:testSpecialCharInBody");
assertTrue("Unexpected message flag state", msg.isFlagged());
}
Aggregations