use of com.zimbra.client.ZFilterCondition in project zm-mailbox by Zimbra.
the class TestFilter method testRedirectMailLoop.
/**
* Confirms that the message gets delivered even when a mail loop occurs.
*/
@Test
public void testRedirectMailLoop() throws Exception {
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
// if subject contains "testRedirectMailLoop", redirect to user1
conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "testRedirectMailLoop"));
actions.add(new ZRedirectAction(TestUtil.getAddress(USER_NAME)));
rules.add(new ZFilterRule("testRedirectMailLoop", true, false, conditions, actions));
ZFilterRules zRules = new ZFilterRules(rules);
saveIncomingRules(mMbox, zRules);
// Add a message.
String subject = NAME_PREFIX + " testRedirectMailLoop";
TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
// Confirm that user1 received it.
ZMessage msg = TestUtil.waitForMessage(mMbox, "subject:\"" + subject + "\"");
byte[] content = TestUtil.getContent(mMbox, msg.getId()).getBytes();
MimeMessage mimeMsg = new MimeMessage(new ByteArrayInputStream(content));
assertEquals(user1.getName(), mimeMsg.getHeader(FilterUtil.HEADER_FORWARDED));
}
use of com.zimbra.client.ZFilterCondition in project zm-mailbox by Zimbra.
the class TestFilter method testBase64Subject.
/**
* Confirms that a message with a base64-encoded subject can be filtered correctly
* (bug 11219).
*/
public void testBase64Subject() throws Exception {
// if subject contains "Cortes de luz", tag with testBase64Subject and stop
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, "Cortes de luz"));
actions.add(new ZTagAction(TAG1_NAME));
rules.add(new ZFilterRule("testBase64Subject", true, false, conditions, actions));
ZFilterRules zRules = new ZFilterRules(rules);
saveIncomingRules(mMbox, zRules);
String address = TestUtil.getAddress(USER_NAME);
TestUtil.addMessageLmtp("=?UTF-8?B?W2l0dnNmLUluY2lkZW5jaWFzXVs0OTc3Ml0gW2luY2lkZW5jaWFzLXZpbGxhbnVldmFdIENvcnRlcyBkZSBsdXosIGTDrWEgMjUvMDkvMjAwNi4=?=", address, address);
List<ZMessage> messages = TestUtil.search(mMbox, "Cortes de luz");
assertEquals("Unexpected number of messages", 1, messages.size());
List<ZTag> tags = mMbox.getTags(messages.get(0).getTagIds());
assertEquals("Unexpected number of tags", 1, tags.size());
assertEquals("Tag didn't match", TAG1_NAME, tags.get(0).getName());
}
Aggregations