use of com.zimbra.client.ZFilterAction in project zm-mailbox by Zimbra.
the class TestFilter method testNotifyActionUseOrigHeaders.
@Test
public void testNotifyActionUseOrigHeaders() 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
// copy headers From,To,Cc,Subject from the original message onto the notification message
actions.add(new ZFilterAction.ZNotifyAction(TestUtil.getAddress(REMOTE_USER_NAME), null, "${BODY}", -1, "From,To,Cc,Subject"));
rules.add(new ZFilterRule("testNotifyActionUseOrigHeaders", true, false, conditions, actions));
saveIncomingRules(mMbox, new ZFilterRules(rules));
String subject = NAME_PREFIX + " testNotifyActionUseOrigHeaders";
String body = "Hi, How r u?";
String msg = new MessageBuilder().withFrom(REMOTE_USER_NAME).withToRecipient(USER_NAME).withCcRecipient(USER_NAME).withSubject(subject).withBody(body).create();
// send msg to user1
TestUtil.addMessageLmtp(new String[] { USER_NAME }, REMOTE_USER_NAME, msg);
// check notification msg from user1 in user2's mailbox
ZMessage zMessage = TestUtil.waitForMessage(TestUtil.getZMailbox(REMOTE_USER_NAME), "in:inbox subject:\"" + subject + "\"");
boolean checkedFrom = false, checkedTo = false, checkedCc = false;
List<ZEmailAddress> msgAddrs = zMessage.getEmailAddresses();
for (ZEmailAddress addr : msgAddrs) {
if ("f".equals(addr.getType())) {
assertEquals(TestUtil.addDomainIfNecessary(REMOTE_USER_NAME), addr.getAddress());
if (!checkedFrom) {
checkedFrom = true;
} else {
fail("multiple From addresses");
}
}
if ("t".equals(addr.getType())) {
assertEquals(TestUtil.addDomainIfNecessary(USER_NAME), addr.getAddress());
if (!checkedTo) {
checkedTo = true;
} else {
fail("multiple To addresses");
}
}
if ("c".equals(addr.getType())) {
assertEquals(TestUtil.addDomainIfNecessary(USER_NAME), addr.getAddress());
if (!checkedCc) {
checkedCc = true;
} else {
fail("multiple Cc addresses");
}
}
}
assertEquals(subject, zMessage.getSubject());
}
use of com.zimbra.client.ZFilterAction in project zm-mailbox by Zimbra.
the class TestFilter method testMarkRead.
@Test
public void testMarkRead() throws Exception {
String folderName = NAME_PREFIX + " testMarkRead";
// if the subject contains "testMarkRead", file into a folder and mark read
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, "testMarkRead"));
actions.add(new ZFileIntoAction(folderName));
actions.add(new ZMarkAction(MarkOp.READ));
rules.add(new ZFilterRule("testMarkRead", true, false, conditions, actions));
saveIncomingRules(mMbox, new ZFilterRules(rules));
// Deliver message.
String address = TestUtil.getAddress(USER_NAME);
String subject = NAME_PREFIX + " testMarkRead";
TestUtil.addMessageLmtp(subject, address, address);
// Check folder and unread state.
ZMessage msg = TestUtil.getMessage(mMbox, "in:\"" + folderName + "\" subject:\"" + subject + "\"");
String flags = msg.getFlags();
assertTrue("Unexpected flags: " + flags, flags == null || flags.indexOf(ZMessage.Flag.unread.getFlagChar()) < 0);
}
use of com.zimbra.client.ZFilterAction in project zm-mailbox by Zimbra.
the class TestFilter method testSpecialCharInBody.
/**
* Tests fix for bug 56019.
*/
@Test
public void testSpecialCharInBody() throws Exception {
assertTrue("To run this test copy data/unittest/TestFilter-testSpecialCharInBody.msg to /opt/zimbra/unittest", Files.exists(Paths.get("/opt/zimbra/unittest/TestFilter-testSpecialCharInBody.msg")));
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
conditions.add(new ZBodyCondition(BodyOp.CONTAINS, "André"));
actions.add(new ZMarkAction(MarkOp.FLAGGED));
rules.add(new ZFilterRule("testSpecialCharInBody", 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);
// TestFilter-testSpecialCharInBody.msg's body contains base64 encoded content (containing "André")
String msgContent = new String(ByteUtil.getContent(new File("/opt/zimbra/unittest/TestFilter-testSpecialCharInBody.msg")));
TestUtil.addMessageLmtp(new String[] { address }, address, msgContent);
ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:testSpecialCharInBody");
assertTrue("Unexpected message flag state", msg.isFlagged());
}
use of com.zimbra.client.ZFilterAction in project zm-mailbox by Zimbra.
the class TestFilter method testReplyAction.
@Test
public void testReplyAction() throws Exception {
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
conditions.add(new ZFilterCondition.ZTrueCondition());
actions.add(new ZFilterAction.ZReplyAction("Hi ${FROM}, Your message was: '${BODY}'. Thanks!"));
rules.add(new ZFilterRule("testReplyAction", true, false, conditions, actions));
saveIncomingRules(mMbox, new ZFilterRules(rules));
String subject = NAME_PREFIX + " testReplyAction";
String body = "Hi, How r u?";
String msg = new MessageBuilder().withFrom(REMOTE_USER_NAME).withSubject(subject).withBody(body).create();
// send msg from user2 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 auto reply from user1 in user2's mailbox
ZMessage zMessage = TestUtil.waitForMessage(TestUtil.getZMailbox(REMOTE_USER_NAME), "in:inbox subject:\"Re: " + 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));
}
use of com.zimbra.client.ZFilterAction in project zm-mailbox by Zimbra.
the class TestFilter method testAttachment.
@Test
public void testAttachment() throws Exception {
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
// If attachment exists, set tag1. If attachment doesn't exist, set tag2.
ZTag tag1 = mMbox.createTag(NAME_PREFIX + " testAttachment1", null);
ZTag tag2 = mMbox.createTag(NAME_PREFIX + " testAttachment2", null);
conditions.add(new ZAttachmentExistsCondition(true));
actions.add(new ZTagAction(tag1.getName()));
rules.add(new ZFilterRule("testAttachment1", true, false, conditions, actions));
conditions = new ArrayList<ZFilterCondition>();
actions = new ArrayList<ZFilterAction>();
conditions.add(new ZAttachmentExistsCondition(false));
actions.add(new ZTagAction(tag2.getName()));
rules.add(new ZFilterRule("testAttachment2", true, false, conditions, actions));
ZFilterRules zRules = new ZFilterRules(rules);
saveIncomingRules(mMbox, zRules);
// Add a message with an attachment.
String address = TestUtil.getAddress(USER_NAME);
String subject = NAME_PREFIX + " testAttachment1";
String msgContent = new MessageBuilder().withSubject(subject).withAttachment("attach this", "attach.txt", "text/plain").create();
TestUtil.addMessageLmtp(new String[] { address }, address, msgContent);
ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
// Check the tag states.
Set<String> tagIds = getTagIds(msg);
assertEquals(1, tagIds.size());
assertTrue(tagIds.contains(tag1.getId()));
// Add a message with no attachment.
subject = NAME_PREFIX + " testAttachment2";
msgContent = new MessageBuilder().withSubject(subject).create();
TestUtil.addMessageLmtp(new String[] { address }, address, msgContent);
msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"" + subject + "\"");
// Check the tag states.
tagIds = getTagIds(msg);
assertEquals(1, tagIds.size());
assertTrue(tagIds.contains(tag2.getId()));
}
Aggregations