use of com.zimbra.client.ZFilterAction 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.ZFilterAction in project zm-mailbox by Zimbra.
the class TestFilter method testReplyAction.
@Test
public void testReplyAction() throws Exception {
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
conditions.add(new ZFilterCondition.ZTrueCondition());
actions.add(new ZFilterAction.ZReplyAction("Hi ${FROM}, Your message was: '${BODY}'. Thanks!"));
rules.add(new ZFilterRule("testReplyAction", true, false, conditions, actions));
saveIncomingRules(mMbox, new ZFilterRules(rules));
String subject = NAME_PREFIX + " testReplyAction";
String body = "Hi, How r u?";
String msg = new MessageBuilder().withFrom(REMOTE_USER_NAME).withSubject(subject).withBody(body).create();
// send msg from user2 to user1
TestUtil.addMessageLmtp(new String[] { USER_NAME }, REMOTE_USER_NAME, msg);
// check msg got filed into user1's mailbox
TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
// check auto reply from user1 in user2's mailbox
ZMessage zMessage = TestUtil.waitForMessage(TestUtil.getZMailbox(REMOTE_USER_NAME), "in:inbox subject:\"Re: " + subject + "\"");
ZMessage.ZMimePart mimeStructure = zMessage.getMimeStructure();
String bodyContent = mimeStructure.getContent();
assertTrue("template vars should be replaced", !bodyContent.contains("${FROM}") && !bodyContent.contains("${BODY}"));
assertTrue(bodyContent.contains(TestUtil.getAddress(REMOTE_USER_NAME)) && bodyContent.contains(body));
// bug 65369
assertTrue(!mimeStructure.getContentType().contains("charset") || mimeStructure.getContentType().contains(MimeConstants.P_CHARSET_ASCII));
}
use of com.zimbra.client.ZFilterAction 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.ZFilterAction 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.ZFilterAction 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"));
}
}
Aggregations