use of com.zimbra.client.ZFilterCondition.ZHeaderCondition in project zm-mailbox by Zimbra.
the class TestFilter method testHeaderMatches.
/**
* Tests matching a header against a wildcard expression. See bug 21701.
*/
@Test
public void testHeaderMatches() throws Exception {
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
// If subject matches the first for characters + *, mark as flagged.
String pattern = NAME_PREFIX.substring(0, 4) + "*";
conditions.add(new ZHeaderCondition("subject", HeaderOp.MATCHES, pattern));
actions.add(new ZMarkAction(MarkOp.FLAGGED));
rules.add(new ZFilterRule("testHeaderMatches", true, false, conditions, actions));
ZFilterRules zRules = new ZFilterRules(rules);
saveIncomingRules(mMbox, zRules);
// Add a message and confirm it is flagged
String address = TestUtil.getAddress(USER_NAME);
String subject = NAME_PREFIX + " testHeaderMatches";
TestUtil.addMessageLmtp(subject, address, address);
ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:testHeaderMatches");
assertTrue("Message was not flagged", msg.isFlagged());
}
use of com.zimbra.client.ZFilterCondition.ZHeaderCondition in project zm-mailbox by Zimbra.
the class TestFilter method testManyAsterisks.
/**
* Make sure we disallow more than four asterisks in a :matches condition (bug 35983).
*/
@Test
public void testManyAsterisks() throws Exception {
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
ZFilterCondition condition = new ZHeaderCondition("from", HeaderOp.MATCHES, "*****address@yahoo.com");
ZFilterAction action = new ZKeepAction();
conditions.add(condition);
actions.add(action);
rules.add(new ZFilterRule("test many asterisks", true, false, conditions, actions));
ZFilterRules zRules = new ZFilterRules(rules);
try {
mMbox.saveIncomingFilterRules(zRules);
fail("Saving filter rules with quotes should not have succeeded");
} catch (SoapFaultException e) {
assertTrue("Unexpected exception: " + e, e.getMessage().contains("four asterisks"));
}
}
use of com.zimbra.client.ZFilterCondition.ZHeaderCondition in project zm-mailbox by Zimbra.
the class TestFilter method testToOrCc.
public void testToOrCc() throws Exception {
// Create filter rules
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
conditions.add(new ZHeaderCondition("to,cc", HeaderOp.CONTAINS, "checkthis.com"));
actions.add(new ZTagAction(mTag1.getName()));
rules.add(new ZFilterRule("testToOrCc", true, false, conditions, actions));
saveIncomingRules(mMbox, new ZFilterRules(rules));
// Deliver message 1 and make sure that tag 1 was applied
String subject = NAME_PREFIX + " testToOrCc 1";
String content = new MessageBuilder().withSubject(subject).withToRecipient(USER_NAME).withCcRecipient("cc@checkthis.com").create();
TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, content);
ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
Set<String> tagIds = new HashSet<String>();
assertNotNull(msg.getTagIds());
tagIds.addAll(Arrays.asList(msg.getTagIds().split(",")));
assertEquals(1, tagIds.size());
assertTrue(tagIds.contains(mTag1.getId()));
// Deliver message 2 and make sure that tag 1 was applied
subject = NAME_PREFIX + " testToOrCc 2";
content = new MessageBuilder().withSubject(subject).withToRecipient("to@checkthis.com").withCcRecipient(USER_NAME).create();
TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, content);
msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
tagIds = new HashSet<String>();
assertNotNull(msg.getTagIds());
tagIds.addAll(Arrays.asList(msg.getTagIds().split(",")));
assertEquals(1, tagIds.size());
assertTrue(tagIds.contains(mTag1.getId()));
}
use of com.zimbra.client.ZFilterCondition.ZHeaderCondition in project zm-mailbox by Zimbra.
the class TestFilter method testCaseSensitiveComparison.
public void testCaseSensitiveComparison() throws Exception {
// Create case sensitive header and body filter rules
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, true, "CHECK THIS"));
conditions.add(new ZBodyCondition(BodyOp.CONTAINS, true, "CHECK THIS"));
actions.add(new ZTagAction(mTag1.getName()));
rules.add(new ZFilterRule("testCaseSensitiveComparison", true, false, conditions, actions));
saveIncomingRules(mMbox, new ZFilterRules(rules));
// Deliver message having lower case subject substring and make sure that tag1 was not applied
String subject = NAME_PREFIX + " testCaseSensitiveComparison1 check this";
TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
assertTrue("message should not have been tagged", msg.getTagIds() == null || msg.getTagIds().isEmpty());
// Deliver message having upper case subject substring and make sure that tag1 was applied
subject = NAME_PREFIX + " testCaseSensitiveComparison2 CHECK THIS";
TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
assertNotNull("message should have been tagged", msg.getTagIds());
Set<String> tagIds = new HashSet<String>();
tagIds.addAll(Arrays.asList(msg.getTagIds().split(",")));
assertTrue("message should have been tagged with tag1", tagIds.contains(mTag1.getId()));
// Deliver message having lower case body content substring and make sure that tag1 was not applied
subject = NAME_PREFIX + " testCaseSensitiveComparison3";
String content = new MessageBuilder().withSubject(subject).withToRecipient(USER_NAME).withBody("Hi check this").create();
TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, content);
msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
assertTrue("message should not have been tagged", msg.getTagIds() == null || msg.getTagIds().isEmpty());
// Deliver message having upper case body content substring and make sure that tag1 was applied
subject = NAME_PREFIX + " testCaseSensitiveComparison4";
content = new MessageBuilder().withSubject(subject).withToRecipient(USER_NAME).withBody("Hi CHECK THIS").create();
TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, content);
msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
assertNotNull("message should have been tagged", msg.getTagIds());
tagIds = new HashSet<String>();
tagIds.addAll(Arrays.asList(msg.getTagIds().split(",")));
assertTrue("message should have been tagged with tag1", tagIds.contains(mTag1.getId()));
}
use of com.zimbra.client.ZFilterCondition.ZHeaderCondition 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");
}
Aggregations