Search in sources :

Example 46 with ZMessage

use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.

the class TestImapImport method compare.

private void compare(ZMailbox mbox1, ZFolder folder1, ZMailbox mbox2, ZFolder folder2) throws Exception {
    assertNotNull(mbox1);
    assertNotNull(folder1);
    assertNotNull(mbox2);
    assertNotNull(folder2);
    // Recursively compare children
    for (ZFolder child1 : folder1.getSubFolders()) {
        if (isMailFolder(child1)) {
            ZFolder child2 = folder2.getSubFolderByPath(child1.getName());
            String msg = String.format("Could not find folder %s/%s for %s", folder2.getPath(), child1.getName(), mbox2.getName());
            assertNotNull(msg, child2);
            compare(mbox1, child1, mbox2, child2);
        }
    }
    assertEquals("Message count doesn't match (folder1 = " + folder1 + ", folder2 = " + folder2 + ")", folder1.getMessageCount(), folder2.getMessageCount());
    // Compare folders as long as neither one is the user root
    if (!(folder1.getPath().equals("/") || folder2.getPath().equals("/"))) {
        List<ZMessage> msgs1 = TestUtil.search(mbox1, "in:" + folder1.getPath());
        List<ZMessage> msgs2 = TestUtil.search(mbox2, "in:" + folder2.getPath());
        compareMessages(msgs1, msgs2);
    }
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZFolder(com.zimbra.client.ZFolder)

Example 47 with ZMessage

use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.

the class TestImapOneWayImport method compareMessages.

private void compareMessages(List<ZMessage> msgs1, List<ZMessage> msgs2) throws Exception {
    // Keep track of message ID's in first set
    Map<String, ZMessage> msgMap = new HashMap<String, ZMessage>();
    for (ZMessage msg : msgs1) {
        msgMap.put(msg.getMessageIdHeader(), msg);
    }
    // Compare messages in second set
    for (ZMessage msg2 : msgs2) {
        String id = msg2.getMessageIdHeader();
        ZMessage msg1 = msgMap.remove(id);
        assertNotNull("Found message '" + msg2.getSubject() + "' in mbox2 but not in mbox1", msg1);
        assertEquals("Message content", msg1.getContent(), msg2.getContent());
        String f1 = msg1.getFlags() != null ? msg1.getFlags() : "";
        String f2 = msg2.getFlags() != null ? msg2.getFlags() : "";
        assertEquals("Flags for message '" + msg1.getSubject() + "' don't match", f1, f2);
    }
    // Fail if there are any remaining messages
    if (msgMap.size() != 0) {
        List<String> subjects = new ArrayList<String>();
        for (ZMessage msg : msgMap.values()) {
            subjects.add(msg.getSubject());
        }
        fail("Found messages in mbox1 but not in mbox2: " + StringUtil.join(",", subjects));
    }
}
Also used : ZMessage(com.zimbra.client.ZMessage) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 48 with ZMessage

use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.

the class TestGetMsg method verifyMessageContent.

private void verifyMessageContent(ZMailbox mbox, String msgId, boolean wantHtml, Integer requestMaxLength, Integer expectedLength, boolean expectedTruncated, String body, String contentType) throws Exception {
    ZGetMessageParams params = new ZGetMessageParams();
    params.setId(msgId);
    params.setWantHtml(wantHtml);
    params.setMax(requestMaxLength);
    ZMessage msg = mbox.getMessage(params);
    ZMimePart mp = msg.getMimeStructure();
    Assert.assertEquals(expectedTruncated, mp.wasTruncated());
    String expected = body;
    if (expectedLength != null) {
        expected = body.substring(0, expectedLength);
    }
    if (contentType.equals(MimeConstants.CT_TEXT_ENRICHED)) {
        // HTML conversion in TextEnrichedHandler will drop trailing
        // characters when the enriched data is malformed (tags not
        // closed, etc.).
        Assert.assertTrue(mp.getContent().length() > 0);
        Assert.assertTrue(expected.startsWith(mp.getContent()));
    } else {
        Assert.assertEquals(expected, mp.getContent());
    }
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZGetMessageParams(com.zimbra.client.ZGetMessageParams) ZMimePart(com.zimbra.client.ZMessage.ZMimePart)

Example 49 with ZMessage

use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.

the class TestFilter method testOutgoingFiltersWithAddMsg.

/**
     * Confirms that outgoing filters are applied as expected when a sent message is added via AddMsgRequest.
     */
public void testOutgoingFiltersWithAddMsg() throws Exception {
    String sender = TestUtil.getAddress(USER_NAME);
    String recipient = TestUtil.getAddress(REMOTE_USER_NAME);
    String subject = NAME_PREFIX + " outgoing";
    String content = new MessageBuilder().withSubject(subject).withFrom(sender).withToRecipient(recipient).create();
    // add a msg flagged as sent; filterSent=TRUE
    mMbox.addMessage("" + Mailbox.ID_FOLDER_SENT, "s", null, System.currentTimeMillis(), content, false, true);
    // make sure that the message has been correctly tagged and filed into the correct folder
    ZMessage msg = TestUtil.getMessage(mMbox, "in:" + FOLDER1_NAME + " " + subject);
    TestUtil.verifyTag(mMbox, msg, TAG1_NAME);
    // make sure that the message has not been filed into the (default) Sent folder
    List<ZMessage> msgs = TestUtil.search(mMbox, "in:Sent" + " " + subject);
    assertTrue(msgs.isEmpty());
    // add another msg flagged as sent; this time filterSent=FALSE
    mMbox.addMessage("" + Mailbox.ID_FOLDER_SENT, "s", null, System.currentTimeMillis(), content, false, false);
    // make sure that the message has been added to the (default) Sent folder
    TestUtil.getMessage(mMbox, "in:Sent" + " " + subject);
}
Also used : ZMessage(com.zimbra.client.ZMessage)

Example 50 with ZMessage

use of com.zimbra.client.ZMessage in project zm-mailbox by Zimbra.

the class TestFilter method testHeaderFolding.

/**
     * Confirms that the header test works with headers that are folded.
     * See section 2.2.3 of RFC 2822 and bug 14942.
     */
@Test
public void testHeaderFolding() throws Exception {
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    // if subject contains "a b c", mark as flagged
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "a b c"));
    actions.add(new ZMarkAction(MarkOp.FLAGGED));
    rules.add(new ZFilterRule("testHeaderFolding", true, false, conditions, actions));
    ZFilterRules zRules = new ZFilterRules(rules);
    saveIncomingRules(mMbox, zRules);
    // Add a message and confirm it is flagged
    String address = TestUtil.getAddress(USER_NAME);
    String subject = NAME_PREFIX + " a b\r\n c";
    TestUtil.addMessageLmtp(subject, address, address);
    ZMessage msg = TestUtil.getMessage(mMbox, "in:inbox subject:\"a b c\"");
    assertTrue("Message was not flagged", msg.isFlagged());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZHeaderCondition(com.zimbra.client.ZFilterCondition.ZHeaderCondition) ZFilterCondition(com.zimbra.client.ZFilterCondition) ArrayList(java.util.ArrayList) ZFilterAction(com.zimbra.client.ZFilterAction) ZFilterRule(com.zimbra.client.ZFilterRule) ZMarkAction(com.zimbra.client.ZFilterAction.ZMarkAction) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

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