Search in sources :

Example 31 with ZFilterRules

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

the class ZMailboxUtil method doDeleteOutgoingFilterRule.

private void doDeleteOutgoingFilterRule(String[] args) throws ServiceException {
    ZFilterRules rules = mMbox.getOutgoingFilterRules(true);
    doDeleteFilterRule(args, rules);
    mMbox.saveOutgoingFilterRules(rules);
}
Also used : ZFilterRules(com.zimbra.client.ZFilterRules)

Example 32 with ZFilterRules

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

the class TestFilterRFCCompliantNotify method saveIncomingRules.

/**
     * Saves the given incoming filter rules.  Then gets them from the server and confirms that
     * the element tree matches.
     */
private void saveIncomingRules(ZMailbox mbox, ZFilterRules rules) throws Exception {
    mbox.saveIncomingFilterRules(rules);
    ZFilterRules result = mbox.getIncomingFilterRules(true);
    TestUtil.assertEquals(rules.dump(), result.dump());
}
Also used : ZFilterRules(com.zimbra.client.ZFilterRules)

Example 33 with ZFilterRules

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

the class TestFilterRFCCompliantNotify method getTestIncomingRules.

private ZFilterRules getTestIncomingRules() throws Exception {
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    // if subject contains "folder1", file into folder1 and tag with tag1
    conditions = new ArrayList<ZFilterCondition>();
    actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, NAME_PREFIX));
    actions.add(new ZRFCCompliantNotifyAction(USER_NAME, "", "", "Notify You've got a mail!", "mailto:" + REMOTE_USER_NAME + "?body=This is the notification email alert&Importance=High&X-Priority=1"));
    rules.add(new ZFilterRule("testRFCCompliantNotify", 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) ZFilterRules(com.zimbra.client.ZFilterRules) ZRFCCompliantNotifyAction(com.zimbra.client.ZFilterAction.ZRFCCompliantNotifyAction)

Example 34 with ZFilterRules

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

the class TestFilter method testHeaderFolding.

/**
     * Confirms that the header test works with headers that are folded.
     * See section 2.2.3 of RFC 2822 and bug 14942.
     */
@Test
public void testHeaderFolding() throws Exception {
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    // if subject contains "a b c", mark as flagged
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "a b c"));
    actions.add(new ZMarkAction(MarkOp.FLAGGED));
    rules.add(new ZFilterRule("testHeaderFolding", 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 + " a b\r\n c";
    TestUtil.addMessageLmtp(subject, address, address);
    ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"a b c\"");
    assertTrue("Message was not flagged", msg.isFlagged());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZHeaderCondition(com.zimbra.client.ZFilterCondition.ZHeaderCondition) ZFilterCondition(com.zimbra.client.ZFilterCondition) ArrayList(java.util.ArrayList) ZFilterAction(com.zimbra.client.ZFilterAction) ZFilterRule(com.zimbra.client.ZFilterRule) ZMarkAction(com.zimbra.client.ZFilterAction.ZMarkAction) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Example 35 with ZFilterRules

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

the class TestFilter method testDateFiltering.

@Test
public void testDateFiltering() throws Exception {
    // Before tomorrow.
    ZTag tagBeforeTomorrow = mMbox.createTag(NAME_PREFIX + " before tomorrow", null);
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    conditions.add(new ZDateCondition(DateOp.BEFORE, new Date(System.currentTimeMillis() + Constants.MILLIS_PER_DAY)));
    actions.add(new ZTagAction(tagBeforeTomorrow.getName()));
    rules.add(new ZFilterRule("before tomorrow", true, false, conditions, actions));
    // After yesterday.
    ZTag tagAfterYesterday = mMbox.createTag(NAME_PREFIX + " after yesterday", null);
    conditions = new ArrayList<ZFilterCondition>();
    actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZDateCondition(DateOp.AFTER, new Date(System.currentTimeMillis() - Constants.MILLIS_PER_DAY)));
    actions.add(new ZTagAction(tagAfterYesterday.getName()));
    rules.add(new ZFilterRule("after yesterday", true, false, conditions, actions));
    // Save rules.
    ZFilterRules zRules = new ZFilterRules(rules);
    mMbox.saveIncomingFilterRules(zRules);
    // Old message.
    String[] recipients = new String[] { USER_NAME };
    String subject = NAME_PREFIX + " testDateFiltering old";
    String content = TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, new Date(System.currentTimeMillis() - (2 * Constants.MILLIS_PER_DAY)));
    TestUtil.addMessageLmtp(recipients, USER_NAME, content);
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    ZMessage msg = TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
    Set<String> tagIds = getTagIds(msg);
    assertEquals(1, tagIds.size());
    assertTrue(tagIds.contains(tagBeforeTomorrow.getId()));
    // Current message.
    subject = NAME_PREFIX + " testDateFiltering current";
    content = TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, null);
    TestUtil.addMessageLmtp(recipients, USER_NAME, content);
    msg = TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
    tagIds = getTagIds(msg);
    assertEquals(2, tagIds.size());
    assertTrue(tagIds.contains(tagAfterYesterday.getId()));
    assertTrue(tagIds.contains(tagBeforeTomorrow.getId()));
    // Future message.
    subject = NAME_PREFIX + " testDateFiltering future";
    content = TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, new Date(System.currentTimeMillis() + (2 * Constants.MILLIS_PER_DAY)));
    TestUtil.addMessageLmtp(recipients, USER_NAME, content);
    msg = TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
    tagIds = getTagIds(msg);
    assertEquals(1, tagIds.size());
    assertTrue(tagIds.contains(tagAfterYesterday.getId()));
    // No date header (bug 44079).
    subject = NAME_PREFIX + " testDateFiltering no date header";
    content = removeHeader(TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, null), "Date");
    TestUtil.addMessageLmtp(recipients, USER_NAME, content);
    msg = TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
    tagIds = getTagIds(msg);
    assertEquals(2, tagIds.size());
    assertTrue(tagIds.contains(tagAfterYesterday.getId()));
    assertTrue(tagIds.contains(tagBeforeTomorrow.getId()));
}
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) ZTag(com.zimbra.client.ZTag) Date(java.util.Date) ZMailbox(com.zimbra.client.ZMailbox) ZTagAction(com.zimbra.client.ZFilterAction.ZTagAction) ZFilterRules(com.zimbra.client.ZFilterRules) ZDateCondition(com.zimbra.client.ZFilterCondition.ZDateCondition) Test(org.junit.Test)

Aggregations

ZFilterRules (com.zimbra.client.ZFilterRules)48 ZFilterAction (com.zimbra.client.ZFilterAction)37 ZFilterCondition (com.zimbra.client.ZFilterCondition)37 ZFilterRule (com.zimbra.client.ZFilterRule)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