use of com.zimbra.client.ZFilterRule in project zm-mailbox by Zimbra.
the class ZMailboxUtil method doDeleteFilterRule.
private static void doDeleteFilterRule(String[] args, ZFilterRules rules) throws ServiceException {
String name = args[0];
List<ZFilterRule> list = rules.getRules();
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getName().equalsIgnoreCase(name)) {
list.remove(i);
return;
}
}
throw ZClientException.CLIENT_ERROR("can't find rule: " + args, null);
}
use of com.zimbra.client.ZFilterRule in project zm-mailbox by Zimbra.
the class TestFilter method testQuoteEscape.
public void testQuoteEscape() throws Exception {
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
String folderName = NAME_PREFIX + " testQuoteEscape";
TestUtil.createFolder(mMbox, folderName);
// if subject contains "a " b", file into folder
ZFilterCondition condition = new ZHeaderCondition("subject", HeaderOp.CONTAINS, "a \" b");
ZFilterAction action = new ZFileIntoAction(folderName);
conditions.add(condition);
actions.add(action);
rules.add(new ZFilterRule(folderName, true, false, conditions, actions));
ZFilterRules zRules = new ZFilterRules(rules);
saveIncomingRules(mMbox, zRules);
// Add a message and confirm it gets filed into the correct folder
String address = TestUtil.getAddress(USER_NAME);
String subject = NAME_PREFIX + " a \" b y z";
// Search barfs on unmatched quote
String searchSubject = NAME_PREFIX + " a b y z";
TestUtil.addMessageLmtp(subject, address, address);
TestUtil.getMessage(mMbox, "in:\"" + folderName + "\" subject:\"" + searchSubject + "\"");
}
use of com.zimbra.client.ZFilterRule in project zm-mailbox by Zimbra.
the class TestFilter method testCurrentDayOfWeekTest.
@Test
public void testCurrentDayOfWeekTest() throws Exception {
TimeZone userTz = Util.getAccountTimeZone(user1);
Calendar calendar = Calendar.getInstance(userTz);
int dayToday = calendar.get(Calendar.DAY_OF_WEEK) - 1;
int dayYesterday = dayToday == 0 ? 6 : dayToday - 1;
int dayTomorrow = dayToday == 6 ? 0 : dayToday + 1;
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
// Condition true if msg received on the day yesterday or tomorrow
conditions.add(new ZFilterCondition.ZCurrentDayOfWeekCondition(SimpleOp.IS, dayYesterday + "," + dayTomorrow));
actions.add(new ZTagAction(mTag1.getName()));
rules.add(new ZFilterRule("testCurrentDayOfWeekTest day not today", true, false, conditions, actions));
saveIncomingRules(mMbox, new ZFilterRules(rules));
String subject = NAME_PREFIX + " testCurrentDayOfWeekTest1";
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 on the day today
conditions.add(new ZFilterCondition.ZCurrentDayOfWeekCondition(SimpleOp.IS, Integer.toString(dayToday)));
rules.add(new ZFilterRule("testCurrentDayOfWeekTest today", true, false, conditions, actions));
saveIncomingRules(mMbox, new ZFilterRules(rules));
subject = NAME_PREFIX + " testCurrentDayOfWeekTest2";
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()));
}
use of com.zimbra.client.ZFilterRule in project zm-mailbox by Zimbra.
the class TestFilter method doBodyContainsTest.
private void doBodyContainsTest(String substring, boolean contains) 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.
conditions.add(new ZBodyCondition(BodyOp.CONTAINS, substring));
actions.add(new ZMarkAction(MarkOp.FLAGGED));
rules.add(new ZFilterRule("testBodyContains", true, false, conditions, actions));
ZFilterRules zRules = new ZFilterRules(rules);
saveIncomingRules(mMbox, zRules);
// Add a message and test the flagged state.
String address = TestUtil.getAddress(USER_NAME);
String msgContent = new String(ByteUtil.getContent(new File("/opt/zimbra/unittest/TestFilter-testBodyContains.msg")));
TestUtil.addMessageLmtp(new String[] { address }, address, msgContent);
ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:testBodyContains");
assertEquals("Unexpected message flag state", contains, msg.isFlagged());
mMbox.deleteMessage(msg.getId());
}
use of com.zimbra.client.ZFilterRule in project zm-mailbox by Zimbra.
the class TestFilter method testNotifyAction.
@Test
public /**
* Tests the Zimbra-specifict 'notify' action format (not RFC compliant format)
*
* Note: please set 'zimbraSieveNotifyActionRFCCompliant' to FALSE.
*/
void testNotifyAction() 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 user2
actions.add(new ZFilterAction.ZNotifyAction(TestUtil.getAddress(REMOTE_USER_NAME), "${SUBJECT}", "From: ${FROM}, Message: ${BODY}"));
rules.add(new ZFilterRule("testNotifyAction", true, false, conditions, actions));
saveIncomingRules(mMbox, new ZFilterRules(rules));
String subject = NAME_PREFIX + " testNotifyAction";
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 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
ZMessage zMessage = TestUtil.waitForMessage(TestUtil.getZMailbox(REMOTE_USER_NAME), "in:inbox subject:\"" + 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));
}
Aggregations