Search in sources :

Example 1 with ZFilterCondition

use of com.zimbra.client.ZFilterCondition in project zm-mailbox by Zimbra.

the class TestFilter method testFullMatchAfterPartialMatch.

/**
     * Tests fix for bug 55927.
     */
@Test
public void testFullMatchAfterPartialMatch() throws Exception {
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    conditions.add(new ZBodyCondition(BodyOp.CONTAINS, "MatchThis"));
    actions.add(new ZMarkAction(MarkOp.FLAGGED));
    rules.add(new ZFilterRule("testFullMatchAfterPartialMatch", true, false, conditions, actions));
    ZFilterRules zRules = new ZFilterRules(rules);
    saveIncomingRules(mMbox, zRules);
    // Add a message and test the flagged state.
    String subject = NAME_PREFIX + " testFullMatchAfterPartialMatch";
    String content = new MessageBuilder().withSubject(subject).withBody("MatchMatchThis").create();
    TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, content);
    ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
    assertTrue("Unexpected message flag state", msg.isFlagged());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZFilterCondition(com.zimbra.client.ZFilterCondition) ArrayList(java.util.ArrayList) ZFilterAction(com.zimbra.client.ZFilterAction) ZFilterRule(com.zimbra.client.ZFilterRule) ZBodyCondition(com.zimbra.client.ZFilterCondition.ZBodyCondition) ZMarkAction(com.zimbra.client.ZFilterAction.ZMarkAction) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Example 2 with ZFilterCondition

use of com.zimbra.client.ZFilterCondition in project zm-mailbox by Zimbra.

the class TestFilterRFCCompliantNotify method testNotifyAction.

public void testNotifyAction() throws Exception {
    if (!mAvailableRFCCompliantNotify) {
        fail("Unable to test because 'zimbraSieveNotifyActionRFCCompliant' is set to FALSE");
        return;
    }
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZFilterCondition.ZTrueCondition());
    String notifyMsg = "This is the notification email alert";
    StringBuilder mailto = new StringBuilder("mailto:").append(TestUtil.getAddress(REMOTE_USER_NAME)).append("?body=").append(notifyMsg).append("&Importance=High&X-Priority=1");
    String subject = NAME_PREFIX + " testRFCCompliantNotifyAction";
    // add an action to notify user2
    actions.add(new ZFilterAction.ZRFCCompliantNotifyAction(TestUtil.getAddress(USER_NAME), subject, mailto.toString()));
    rules.add(new ZFilterRule("testRFCCompliantNotifyAction", true, false, conditions, actions));
    saveIncomingRules(mMbox, new ZFilterRules(rules));
    String body = "Hi, How are you today?";
    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 got filed into user1's mailbox
    TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
    // check notification msg from user1 in user2's mailbox, it should have the same subject
    ZMailbox zMailbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
    List<ZMessage> msgs = TestUtil.waitForMessages(zMailbox, "in:inbox subject:\"" + subject + "\"", 1, 120000);
    ZMessage zMessage = msgs.get(0);
    //        ZMessage zMessage = TestUtil.waitForMessage(zMailbox, "in:inbox subject:\"" + subject + "\"");
    ZMessage.ZMimePart mimeStructure = zMessage.getMimeStructure();
    String bodyContent = mimeStructure.getContent();
    // check body text of the notification msg
    assertTrue(bodyContent.contains(notifyMsg));
    // check headers of the notification msg
    String content = TestUtil.getContent(zMailbox, zMessage.getId());
    assertTrue(content.contains("From: " + USER_NAME));
    assertTrue(content.contains("To: " + REMOTE_USER_NAME));
    assertTrue(content.contains("Subject: " + subject));
    assertTrue(content.contains("Auto-Submitted: auto-notified;"));
    assertTrue(content.contains("X-Zimbra-Forwarded: " + USER_NAME));
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZFilterCondition(com.zimbra.client.ZFilterCondition) ArrayList(java.util.ArrayList) ZFilterRule(com.zimbra.client.ZFilterRule) ZFilterAction(com.zimbra.client.ZFilterAction) ZRFCCompliantNotifyAction(com.zimbra.client.ZFilterAction.ZRFCCompliantNotifyAction) ZMailbox(com.zimbra.client.ZMailbox) ZFilterRules(com.zimbra.client.ZFilterRules)

Example 3 with ZFilterCondition

use of com.zimbra.client.ZFilterCondition in project zm-mailbox by Zimbra.

the class TestFilterExisting method saveNewRules.

private void saveNewRules() throws Exception {
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    // if subject contains "tag", tag
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "tag"));
    actions.add(new ZTagAction(TAG_NAME));
    rules.add(new ZFilterRule(TAG_RULE_NAME, true, false, conditions, actions));
    // if subject contains "flag", flag
    conditions = new ArrayList<ZFilterCondition>();
    actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "flag"));
    actions.add(new ZMarkAction(MarkOp.FLAGGED));
    rules.add(new ZFilterRule(FLAG_RULE_NAME, true, false, conditions, actions));
    // if subject contains "mark read", mark read
    conditions = new ArrayList<ZFilterCondition>();
    actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "mark read"));
    actions.add(new ZMarkAction(MarkOp.READ));
    rules.add(new ZFilterRule(MARK_READ_RULE_NAME, true, false, conditions, actions));
    // if subject contains "keep", keep
    conditions = new ArrayList<ZFilterCondition>();
    actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "keep"));
    actions.add(new ZKeepAction());
    rules.add(new ZFilterRule(KEEP_RULE_NAME, true, false, conditions, actions));
    // if subject contains "folder1", file into folder1
    conditions = new ArrayList<ZFilterCondition>();
    actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "folder1"));
    actions.add(new ZFileIntoAction(FOLDER1_PATH));
    rules.add(new ZFilterRule(FOLDER1_RULE_NAME, true, false, conditions, actions));
    // if the subject contains "folder1 and flag", file into folder1 and flag
    conditions = new ArrayList<ZFilterCondition>();
    actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "folder1 and flag"));
    actions.add(new ZFileIntoAction(FOLDER1_PATH));
    actions.add(new ZMarkAction(MarkOp.FLAGGED));
    rules.add(new ZFilterRule(FOLDER1_AND_FLAG_RULE_NAME, true, false, conditions, actions));
    // if subject contains "folder2", file into folder2
    conditions = new ArrayList<ZFilterCondition>();
    actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "folder2"));
    actions.add(new ZFileIntoAction(FOLDER2_PATH));
    rules.add(new ZFilterRule(FOLDER2_RULE_NAME, true, false, conditions, actions));
    // if subject contains "folder3", file into folder3.  This one uses the
    // folder name without the leading slash.
    conditions = new ArrayList<ZFilterCondition>();
    actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "folder3"));
    actions.add(new ZFileIntoAction(FOLDER3_NAME));
    rules.add(new ZFilterRule(FOLDER3_RULE_NAME, true, false, conditions, actions));
    // if subject contains "discard", discard
    conditions = new ArrayList<ZFilterCondition>();
    actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "discard"));
    actions.add(new ZDiscardAction());
    rules.add(new ZFilterRule(DISCARD_RULE_NAME, true, false, conditions, actions));
    // If subject contains "redirect", redirect to user2.  This rule should
    // be ignored when applied to existing messages.
    conditions = new ArrayList<ZFilterCondition>();
    actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "redirect"));
    actions.add(new ZRedirectAction(TestUtil.getAddress(USER_NAME2)));
    rules.add(new ZFilterRule(REDIRECT_RULE_NAME, true, false, conditions, actions));
    // Save rules
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    mbox.saveIncomingFilterRules(new ZFilterRules(rules));
}
Also used : ZDiscardAction(com.zimbra.client.ZFilterAction.ZDiscardAction) ZHeaderCondition(com.zimbra.client.ZFilterCondition.ZHeaderCondition) ZFilterCondition(com.zimbra.client.ZFilterCondition) ArrayList(java.util.ArrayList) ZFilterRule(com.zimbra.client.ZFilterRule) ZFilterAction(com.zimbra.client.ZFilterAction) ZRedirectAction(com.zimbra.client.ZFilterAction.ZRedirectAction) ZMailbox(com.zimbra.client.ZMailbox) ZFileIntoAction(com.zimbra.client.ZFilterAction.ZFileIntoAction) ZTagAction(com.zimbra.client.ZFilterAction.ZTagAction) ZKeepAction(com.zimbra.client.ZFilterAction.ZKeepAction) ZMarkAction(com.zimbra.client.ZFilterAction.ZMarkAction) ZFilterRules(com.zimbra.client.ZFilterRules)

Example 4 with ZFilterCondition

use of com.zimbra.client.ZFilterCondition in project zm-mailbox by Zimbra.

the class TestSpam method testSpamHandler.

@Test
public void testSpamHandler() throws Exception {
    TestUtil.createAccount(REMOTE_USER_NAME);
    TestUtil.createAccount(SPAM_NAME);
    TestUtil.createAccount(HAM_NAME);
    //check if AS is installed
    List<String> zimbraServiceInstalled = Arrays.asList(prov.getLocalServer().getServiceInstalled());
    if (zimbraServiceInstalled == null || zimbraServiceInstalled.isEmpty() || !zimbraServiceInstalled.contains("antispam")) {
        return;
    }
    Config config = prov.getConfig();
    config.setSpamIsSpamAccount(TestUtil.getAddress(SPAM_NAME));
    config.setSpamIsNotSpamAccount(TestUtil.getAddress(HAM_NAME));
    // Set filter rule.
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    ZFilterCondition cond = new ZHeaderCondition("Subject", ZFilterCondition.HeaderOp.CONTAINS, NAME_PREFIX);
    ZFolder spamFolder = mbox.getFolderById(Integer.toString(Mailbox.ID_FOLDER_SPAM));
    ZFolder inboxFolder = mbox.getFolderById(Integer.toString(Mailbox.ID_FOLDER_INBOX));
    ZFilterAction action = new ZFileIntoAction(spamFolder.getPath());
    ZFilterRule rule = new ZFilterRule(NAME_PREFIX + " testSpamHandler", true, true, Arrays.asList(cond), Arrays.asList(action));
    ZFilterRules rules = new ZFilterRules(Arrays.asList(rule));
    mbox.saveIncomingFilterRules(rules);
    // Confirm that the message was delivered to the Spam folder and that the report was sent.
    String subject = NAME_PREFIX + " testSpamHandler";
    TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
    ZMessage msg = TestUtil.getMessage(mbox, "in:" + spamFolder.getPath() + " subject:\"" + subject + "\"");
    ZMailbox spamMbox = TestUtil.getZMailbox(SPAM_NAME);
    ZMessage reportMsg = TestUtil.waitForMessage(spamMbox, "zimbra-spam-report spam");
    validateSpamReport(TestUtil.getContent(spamMbox, reportMsg.getId()), TestUtil.getAddress(USER_NAME), "spam", "filter", null, spamFolder.getPath(), null);
    spamMbox.deleteMessage(reportMsg.getId());
    // Move out of spam folder.
    mbox.moveMessage(msg.getId(), Integer.toString(Mailbox.ID_FOLDER_INBOX));
    ZMailbox hamMbox = TestUtil.getZMailbox(HAM_NAME);
    reportMsg = TestUtil.waitForMessage(hamMbox, "zimbra-spam-report ham");
    validateSpamReport(TestUtil.getContent(hamMbox, reportMsg.getId()), TestUtil.getAddress(USER_NAME), "ham", "move", spamFolder.getPath(), inboxFolder.getPath(), null);
    hamMbox.deleteMessage(reportMsg.getId());
    // Move back to spam folder.
    mbox.moveMessage(msg.getId(), Integer.toString(Mailbox.ID_FOLDER_SPAM));
    reportMsg = TestUtil.waitForMessage(spamMbox, "zimbra-spam-report spam");
    validateSpamReport(TestUtil.getContent(spamMbox, reportMsg.getId()), TestUtil.getAddress(USER_NAME), "spam", "move", inboxFolder.getPath(), spamFolder.getPath(), null);
    spamMbox.deleteMessage(reportMsg.getId());
    // Move to remote folder.
    ZMailbox remoteMbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
    String mountpointPath = NAME_PREFIX + " remote";
    TestUtil.createMountpoint(remoteMbox, "/Inbox", mbox, mountpointPath);
    ZFolder mountpoint = mbox.getFolderByPath(mountpointPath);
    mbox.moveMessage(msg.getId(), mountpoint.getId());
    reportMsg = TestUtil.waitForMessage(hamMbox, "zimbra-spam-report ham");
    validateSpamReport(TestUtil.getContent(hamMbox, reportMsg.getId()), TestUtil.getAddress(USER_NAME), "ham", "remote move", spamFolder.getPath(), inboxFolder.getPath(), TestUtil.getAddress(REMOTE_USER_NAME));
    hamMbox.deleteMessage(reportMsg.getId());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) Config(com.zimbra.cs.account.Config) ZHeaderCondition(com.zimbra.client.ZFilterCondition.ZHeaderCondition) ZFilterCondition(com.zimbra.client.ZFilterCondition) ZFileIntoAction(com.zimbra.client.ZFilterAction.ZFileIntoAction) ZFilterAction(com.zimbra.client.ZFilterAction) ZFilterRule(com.zimbra.client.ZFilterRule) ZFolder(com.zimbra.client.ZFolder) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Example 5 with ZFilterCondition

use of com.zimbra.client.ZFilterCondition in project zm-mailbox by Zimbra.

the class TestTagFilterRules method getRules.

private ZFilterRules getRules() throws Exception {
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    // if subject contains "TestTagFilterRules", tag TestTagFilterRules
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, SUBJECT_PREFIX));
    actions.add(new ZTagAction(TAG_NAME));
    rules.add(new ZFilterRule(TAG_NAME, true, false, conditions, actions));
    // if subject contains "TestTagFilterRules", tag TestTagFilterRules2
    conditions = new ArrayList<ZFilterCondition>();
    actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, SUBJECT_PREFIX));
    actions.add(new ZTagAction(TAG2_NAME));
    rules.add(new ZFilterRule(TAG2_NAME, true, false, conditions, actions));
    return new ZFilterRules(rules);
}
Also used : ZHeaderCondition(com.zimbra.client.ZFilterCondition.ZHeaderCondition) ZFilterCondition(com.zimbra.client.ZFilterCondition) ArrayList(java.util.ArrayList) ZFilterRule(com.zimbra.client.ZFilterRule) ZFilterAction(com.zimbra.client.ZFilterAction) ZTagAction(com.zimbra.client.ZFilterAction.ZTagAction) ZFilterRules(com.zimbra.client.ZFilterRules)

Aggregations

ZFilterAction (com.zimbra.client.ZFilterAction)37 ZFilterCondition (com.zimbra.client.ZFilterCondition)37 ZFilterRule (com.zimbra.client.ZFilterRule)37 ZFilterRules (com.zimbra.client.ZFilterRules)37 ArrayList (java.util.ArrayList)35 ZMessage (com.zimbra.client.ZMessage)28 Test (org.junit.Test)23 ZHeaderCondition (com.zimbra.client.ZFilterCondition.ZHeaderCondition)20 ZTagAction (com.zimbra.client.ZFilterAction.ZTagAction)13 ZMarkAction (com.zimbra.client.ZFilterAction.ZMarkAction)10 ZFileIntoAction (com.zimbra.client.ZFilterAction.ZFileIntoAction)9 ZMailbox (com.zimbra.client.ZMailbox)9 HashSet (java.util.HashSet)5 ZBodyCondition (com.zimbra.client.ZFilterCondition.ZBodyCondition)4 ZTag (com.zimbra.client.ZTag)4 ZDiscardAction (com.zimbra.client.ZFilterAction.ZDiscardAction)3 ZRedirectAction (com.zimbra.client.ZFilterAction.ZRedirectAction)3 ZKeepAction (com.zimbra.client.ZFilterAction.ZKeepAction)2 ZRFCCompliantNotifyAction (com.zimbra.client.ZFilterAction.ZRFCCompliantNotifyAction)2 ZFolder (com.zimbra.client.ZFolder)2