use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestFilter method testAddressTestPart.
@Test
public void testAddressTestPart() throws Exception {
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
// use address test for address domain match
conditions.add(new ZFilterCondition.ZAddressCondition("From", Sieve.AddressPart.domain, HeaderOp.IS, false, "example.com"));
actions.add(new ZMarkAction(MarkOp.FLAGGED));
rules.add(new ZFilterRule("testAddressTestPart1", true, false, conditions, actions));
saveIncomingRules(mMbox, new ZFilterRules(rules));
String subject = NAME_PREFIX + " testAddressTestPart1";
String mime = new MessageBuilder().withFrom("John Doe <JOHN.DOE@EXAMPLE.COM>").withSubject(subject).create();
TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, mime);
ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
assertTrue("Unexpected message flag state", msg.isFlagged());
// use address test for address local-part match
conditions.add(new ZFilterCondition.ZAddressCondition("From", Sieve.AddressPart.localpart, HeaderOp.MATCHES, true, "j*doe"));
actions.add(new ZMarkAction(MarkOp.FLAGGED));
rules.add(new ZFilterRule("testAddressTestPart2", true, false, conditions, actions));
saveIncomingRules(mMbox, new ZFilterRules(rules));
subject = NAME_PREFIX + " testAddressTestPart2";
mime = new MessageBuilder().withFrom("John Doe <john.doe@example.com>").withSubject(subject).create();
TestUtil.addMessageLmtp(new String[] { USER_NAME }, USER_NAME, mime);
msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
assertTrue("Unexpected message flag state", msg.isFlagged());
}
use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestFilterExisting method testBatchSize.
/**
* Confirms that we're enforcing {@code zimbraFilterBatchSize}.
*/
@Test
public void testBatchSize() throws Exception {
TestUtil.getAccount(USER_NAME).setFilterBatchSize(1);
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
String subject = NAME_PREFIX + " testBatchSize flag";
String msg1Id = TestUtil.addMessage(mbox, subject + " 1");
String msg2Id = TestUtil.addMessage(mbox, subject + " 2");
try {
runRules(new String[] { FLAG_RULE_NAME }, null, "subject: \'" + subject + "\'");
Assert.fail("Batch size was not enforced");
} catch (SoapFaultException e) {
String msg = e.getMessage();
Assert.assertTrue(msg.contains("2 messages"));
Assert.assertTrue(msg.contains("limit of 1"));
}
// Make sure the rule was not executed.
ZMessage msg = mbox.getMessageById(msg1Id);
if (msg.hasFlags()) {
Assert.assertFalse(msg.getFlags().contains("f"));
}
msg = mbox.getMessageById(msg2Id);
if (msg.hasFlags()) {
Assert.assertFalse(msg.getFlags().contains("f"));
}
}
use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestFilterExisting method testFlag.
@Test
public void testFlag() throws Exception {
// Add message
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
String subject = NAME_PREFIX + " test flag";
String id = TestUtil.addMessage(mbox, subject);
ZMessage msg = mbox.getMessageById(id);
// Run tag rule and make sure the message is not tagged.
Set<String> affectedIds = runRules(new String[] { TAG_RULE_NAME }, id, null);
Assert.assertEquals(0, affectedIds.size());
Assert.assertFalse(msg.isFlagged());
// Run flag rule and make sure the message is flagged.
affectedIds = runRules(new String[] { FLAG_RULE_NAME }, id, null);
mbox.noOp();
msg = mbox.getMessageById(id);
Assert.assertTrue(msg.isFlagged());
}
use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestFilterExisting method testDiscard.
@Test
public void testDiscard() throws Exception {
// Add message
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
String subject = NAME_PREFIX + " test keep, fileinto folder1, and discard";
String id = TestUtil.addMessage(mbox, subject);
// Run the keep and discard rules, and make sure the message was kept.
Set<String> affectedIds = runRules(new String[] { KEEP_RULE_NAME, DISCARD_RULE_NAME }, id, null);
Assert.assertEquals(0, affectedIds.size());
TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
// Run the discard and fileinto rules, and make sure the message was filed.
affectedIds = runRules(new String[] { DISCARD_RULE_NAME, FOLDER1_RULE_NAME }, id, null);
assertMoved("inbox", FOLDER1_NAME, subject);
// Run the discard rule by itself and make sure the message was deleted.
String query = "in:" + FOLDER1_NAME + " subject:\"" + subject + "\"";
ZMessage msg = TestUtil.getMessage(mbox, query);
affectedIds = runRules(new String[] { DISCARD_RULE_NAME }, null, query);
Assert.assertEquals(1, affectedIds.size());
Assert.assertTrue(affectedIds.contains(msg.getId()));
List<ZMessage> messages = TestUtil.search(mbox, query);
Assert.assertEquals(0, messages.size());
}
use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestFilterExisting method testFileInto.
@Test
public void testFileInto() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
TestUtil.createFolder(mbox, FOLDER1_PATH);
TestUtil.createFolder(mbox, FOLDER2_PATH);
String subject = NAME_PREFIX + " test keep, fileinto folder1 and folder2";
String id = TestUtil.addMessage(mbox, subject);
String[] ruleNames = new String[] { FOLDER1_RULE_NAME };
// Test file into folder1 by id.
Set<String> affectedIds = runRules(ruleNames, id, null);
Assert.assertEquals(1, affectedIds.size());
Assert.assertTrue(affectedIds.contains(id));
assertMoved("inbox", FOLDER1_NAME, subject);
// Test file into folder2 by query.
ZMessage msg = TestUtil.getMessage(mbox, "in:" + FOLDER1_NAME + " subject:\"" + subject + "\"");
id = msg.getId();
ruleNames = new String[] { FOLDER2_RULE_NAME };
affectedIds = runRules(ruleNames, null, "in:" + FOLDER1_NAME);
Assert.assertEquals(1, affectedIds.size());
Assert.assertTrue(affectedIds.contains(id));
assertMoved(FOLDER1_NAME, FOLDER2_NAME, subject);
// Move message back to inbox.
msg = TestUtil.getMessage(mbox, "in:" + FOLDER2_NAME + " subject:\"" + subject + "\"");
id = msg.getId();
mbox.moveMessage(id, Integer.toString(Mailbox.ID_FOLDER_INBOX));
// Test keep and file into folder1 and folder2.
ruleNames = new String[] { KEEP_RULE_NAME, FOLDER1_RULE_NAME, FOLDER2_RULE_NAME };
affectedIds = runRules(ruleNames, id, null);
Assert.assertEquals(1, affectedIds.size());
Assert.assertTrue(affectedIds.contains(id));
TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
TestUtil.getMessage(mbox, "in:" + FOLDER1_NAME + " subject:\"" + subject + "\"");
TestUtil.getMessage(mbox, "in:" + FOLDER2_NAME + " subject:\"" + subject + "\"");
}
Aggregations