Search in sources :

Example 16 with ZMessage

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));
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZFilterCondition(com.zimbra.client.ZFilterCondition) ArrayList(java.util.ArrayList) ZFilterRule(com.zimbra.client.ZFilterRule) ZFilterAction(com.zimbra.client.ZFilterAction) ZRFCCompliantNotifyAction(com.zimbra.client.ZFilterAction.ZRFCCompliantNotifyAction) ZMailbox(com.zimbra.client.ZMailbox) ZFilterRules(com.zimbra.client.ZFilterRules)

Example 17 with ZMessage

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());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) Test(org.junit.Test)

Example 18 with ZMessage

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());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) Test(org.junit.Test)

Example 19 with ZMessage

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());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) ZTag(com.zimbra.client.ZTag) Test(org.junit.Test)

Example 20 with ZMessage

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());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox)

Aggregations

ZMessage (com.zimbra.client.ZMessage)101 Test (org.junit.Test)63 ZMailbox (com.zimbra.client.ZMailbox)59 ArrayList (java.util.ArrayList)43 ZFilterRule (com.zimbra.client.ZFilterRule)29 ZFilterAction (com.zimbra.client.ZFilterAction)28 ZFilterCondition (com.zimbra.client.ZFilterCondition)28 ZFilterRules (com.zimbra.client.ZFilterRules)28 ZHeaderCondition (com.zimbra.client.ZFilterCondition.ZHeaderCondition)12 ZOutgoingMessage (com.zimbra.client.ZMailbox.ZOutgoingMessage)12 ZEmailAddress (com.zimbra.client.ZEmailAddress)11 ZTagAction (com.zimbra.client.ZFilterAction.ZTagAction)10 ZFolder (com.zimbra.client.ZFolder)10 ZMarkAction (com.zimbra.client.ZFilterAction.ZMarkAction)8 Account (com.zimbra.cs.account.Account)8 MessagePart (com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart)7 Date (java.util.Date)7 ZGetMessageParams (com.zimbra.client.ZGetMessageParams)5 ZMimePart (com.zimbra.client.ZMessage.ZMimePart)5 ZTag (com.zimbra.client.ZTag)5