use of com.zimbra.client.ZFilterRules 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.ZFilterRules in project zm-mailbox by Zimbra.
the class TestFilter method testMimeHeader.
public void testMimeHeader() throws Exception {
// Create a text/plain message with a text/html attachment.
String subject = NAME_PREFIX + " testMimeHeader";
String attachmentData = "<html><body>I'm so attached to you.</body></html>";
String content = new MessageBuilder().withSubject(subject).withToRecipient(USER_NAME).withAttachment(attachmentData, "attachment.html", "text/html").create();
// Create filter rules.
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
conditions.add(new ZMimeHeaderCondition("Content-Type", HeaderOp.CONTAINS, "text/plain"));
actions.add(new ZTagAction(mTag1.getName()));
rules.add(new ZFilterRule("testMarkRead 1", true, false, conditions, actions));
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZMimeHeaderCondition("Content-Type", HeaderOp.CONTAINS, "text/html"));
actions.add(new ZTagAction(mTag2.getName()));
rules.add(new ZFilterRule("testMarkRead 2", true, false, conditions, actions));
saveIncomingRules(mMbox, new ZFilterRules(rules));
// Deliver message and make sure that tag 2 was applied, but not tag 1.
TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, content);
ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
Set<String> tagIds = new HashSet<String>();
tagIds.addAll(Arrays.asList(msg.getTagIds().split(",")));
assertEquals(2, tagIds.size());
assertTrue(tagIds.contains(mTag1.getId()));
assertTrue(tagIds.contains(mTag2.getId()));
}
use of com.zimbra.client.ZFilterRules in project zm-mailbox by Zimbra.
the class TestFilter method testNotifyWithDiscard.
@Test
public void testNotifyWithDiscard() 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
actions.add(new ZFilterAction.ZNotifyAction(TestUtil.getAddress(REMOTE_USER_NAME), "${SUBJECT}", "From: ${FROM}, Message: ${BODY}"));
// add discard action
actions.add(new ZDiscardAction());
rules.add(new ZFilterRule("testNotifyWithDiscard", true, false, conditions, actions));
saveIncomingRules(mMbox, new ZFilterRules(rules));
String subject = NAME_PREFIX + " testNotifyWithDiscard";
String body = "Hi, How r u?";
String msg = new MessageBuilder().withFrom(REMOTE_USER_NAME).withSubject(subject).withBody(body).create();
// send msg to user1
TestUtil.addMessageLmtp(new String[] { USER_NAME }, REMOTE_USER_NAME, msg);
// check msg not filed into user1's mailbox
List<ZMessage> msgs = TestUtil.search(mMbox, "in:inbox subject:\"" + subject + "\"");
assertTrue("original message should not have been filed", msgs.isEmpty());
}
use of com.zimbra.client.ZFilterRules 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.ZFilterRules in project zm-mailbox by Zimbra.
the class TestFilter method testCurrentTimeTest.
@Test
public void testCurrentTimeTest() throws Exception {
TimeZone userTz = Util.getAccountTimeZone(user1);
Calendar calendar = Calendar.getInstance(userTz);
// Add 5 mins to current time
calendar.add(Calendar.MINUTE, 5);
// format time in HHmm
SimpleDateFormat format = new SimpleDateFormat("HHmm");
format.setTimeZone(userTz);
String timeStr = format.format(calendar.getTime());
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
// Condition true if msg received after timeStr
conditions.add(new ZFilterCondition.ZCurrentTimeCondition(DateOp.AFTER, timeStr));
actions.add(new ZTagAction(mTag1.getName()));
rules.add(new ZFilterRule("testCurrentTimeTest after", true, false, conditions, actions));
saveIncomingRules(mMbox, new ZFilterRules(rules));
String subject = NAME_PREFIX + " testCurrentTimeTest1";
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());
rules = new ArrayList<ZFilterRule>();
conditions = new ArrayList<ZFilterCondition>();
// Condition true if msg received before timeStr
conditions.add(new ZFilterCondition.ZCurrentTimeCondition(DateOp.BEFORE, timeStr));
rules.add(new ZFilterRule("testCurrentTimeTest before", true, false, conditions, actions));
saveIncomingRules(mMbox, new ZFilterRules(rules));
subject = NAME_PREFIX + " testCurrentTimeTest2";
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()));
}
Aggregations