use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestFilterRFCCompliantNotify method testNotifyAction.
public void testNotifyAction() throws Exception {
if (!mAvailableRFCCompliantNotify) {
fail("Unable to test because 'zimbraSieveNotifyActionRFCCompliant' is set to FALSE");
return;
}
List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
conditions.add(new ZFilterCondition.ZTrueCondition());
String notifyMsg = "This is the notification email alert";
StringBuilder mailto = new StringBuilder("mailto:").append(TestUtil.getAddress(REMOTE_USER_NAME)).append("?body=").append(notifyMsg).append("&Importance=High&X-Priority=1");
String subject = NAME_PREFIX + " testRFCCompliantNotifyAction";
// add an action to notify user2
actions.add(new ZFilterAction.ZRFCCompliantNotifyAction(TestUtil.getAddress(USER_NAME), subject, mailto.toString()));
rules.add(new ZFilterRule("testRFCCompliantNotifyAction", true, false, conditions, actions));
saveIncomingRules(mMbox, new ZFilterRules(rules));
String body = "Hi, How are you today?";
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
ZMailbox zMailbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
List<ZMessage> msgs = TestUtil.waitForMessages(zMailbox, "in:inbox subject:\"" + subject + "\"", 1, 120000);
ZMessage zMessage = msgs.get(0);
// ZMessage zMessage = TestUtil.waitForMessage(zMailbox, "in:inbox subject:\"" + subject + "\"");
ZMessage.ZMimePart mimeStructure = zMessage.getMimeStructure();
String bodyContent = mimeStructure.getContent();
// check body text of the notification msg
assertTrue(bodyContent.contains(notifyMsg));
// check headers of the notification msg
String content = TestUtil.getContent(zMailbox, zMessage.getId());
assertTrue(content.contains("From: " + USER_NAME));
assertTrue(content.contains("To: " + REMOTE_USER_NAME));
assertTrue(content.contains("Subject: " + subject));
assertTrue(content.contains("Auto-Submitted: auto-notified;"));
assertTrue(content.contains("X-Zimbra-Forwarded: " + USER_NAME));
}
use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestFilterExisting method testMarkRead.
@Test
public void testMarkRead() throws Exception {
// Add message
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
String subject = NAME_PREFIX + " test mark read";
String id = TestUtil.addMessage(mbox, subject);
mbox.markMessageRead(id, false);
ZMessage msg = mbox.getMessageById(id);
Assert.assertTrue(msg.isUnread());
// Run mark unread rule and validate.
Set<String> affectedIds = runRules(new String[] { MARK_READ_RULE_NAME }, id, null);
Assert.assertEquals(1, affectedIds.size());
mbox.noOp();
Assert.assertFalse(msg.isUnread());
}
use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestFilterExisting method testFileIntoSameFolderAndFlag.
/**
* Confirms that a flag rule runs when a message is filed into the same
* folder (bug 44588).
*/
@Test
public void testFileIntoSameFolderAndFlag() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
ZFolder folder1 = TestUtil.createFolder(mbox, FOLDER1_PATH);
String subject = NAME_PREFIX + " test folder1 and flag";
String id = TestUtil.addMessage(mbox, subject, folder1.getId(), null);
ZMessage msg = mbox.getMessageById(id);
Assert.assertTrue(StringUtil.isNullOrEmpty(msg.getFlags()));
// Run the rule, make sure the message was flagged but not moved.
Set<String> affectedIds = runRules(new String[] { FOLDER1_AND_FLAG_RULE_NAME }, id, null);
Assert.assertEquals(1, affectedIds.size());
msg = TestUtil.getMessage(mbox, "subject:\"" + subject + "\"");
Assert.assertEquals("f", msg.getFlags());
}
use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestFilterExisting method testTag.
@Test
public void testTag() throws Exception {
// Add message
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
ZTag tag = mbox.createTag(TAG_NAME, null);
String subject = NAME_PREFIX + " test tag";
String id = TestUtil.addMessage(mbox, subject);
ZMessage msg = mbox.getMessageById(id);
// Run flag rule and make sure the message is not tagged.
Set<String> affectedIds = runRules(new String[] { FLAG_RULE_NAME }, id, null);
Assert.assertEquals(0, affectedIds.size());
Assert.assertFalse(msg.hasTags());
// Run tag rule and make sure the message is tagged.
affectedIds = runRules(new String[] { TAG_RULE_NAME }, id, null);
Assert.assertEquals(1, affectedIds.size());
Assert.assertTrue(affectedIds.contains(id));
mbox.noOp();
msg = mbox.getMessageById(id);
Assert.assertEquals(tag.getId(), msg.getTagIds());
}
use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.
the class TestFilterExisting method assertMoved.
private void assertMoved(String sourceFolderName, String destFolderName, String subject) throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
List<ZMessage> messages = TestUtil.search(mbox, "in:" + sourceFolderName + " subject:\"" + subject + "\"");
Assert.assertEquals(0, messages.size());
messages = TestUtil.search(mbox, "in:" + destFolderName + " subject:\"" + subject + "\"");
Assert.assertEquals(1, messages.size());
}
Aggregations