Search in sources :

Example 1 with ZGetMessageParams

use of com.zimbra.client.ZGetMessageParams 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 2 with ZGetMessageParams

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

the class ZMailboxUtil method doGetMessage.

private void doGetMessage(String[] args) throws ServiceException {
    ZGetMessageParams params = new ZGetMessageParams();
    params.setMarkRead(true);
    params.setId(id(args[0]));
    ZMessage msg = mMbox.getMessage(params);
    if (verboseOpt()) {
        stdout.println(msg.dump());
    } else {
        dumpMessage(msg);
    }
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZGetMessageParams(com.zimbra.client.ZGetMessageParams)

Example 3 with ZGetMessageParams

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

the class TestSendAndReceive method testReceivedHeaders.

/**
     * Verifies that we set the Return-Path and Received headers
     * for incoming messages.
     */
@Test
public void testReceivedHeaders() throws Exception {
    TestUtil.createAccount(USER_NAME);
    TestUtil.createAccount(REMOTE_USER_NAME);
    // Send message from user2 to user1
    String sender = TestUtil.getAddress(REMOTE_USER_NAME);
    String recipient = TestUtil.getAddress(USER_NAME);
    TestUtil.addMessageLmtp(NAME_PREFIX + " testReceivedHeaders()", recipient, sender);
    // Search
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    List<ZMessage> messages = TestUtil.search(mbox, NAME_PREFIX);
    Assert.assertEquals("Unexpected message count", 1, messages.size());
    // Get the message content, since a search won't return the content
    ZGetMessageParams params = new ZGetMessageParams();
    params.setId(messages.get(0).getId());
    params.setRawContent(true);
    ZMessage message = mbox.getMessage(params);
    String content = message.getContent();
    // Check headers
    boolean foundReceived = false;
    boolean foundReturnPath = false;
    BufferedReader reader = new BufferedReader(new StringReader(content));
    String line = reader.readLine();
    while (line != null) {
        Matcher matcher = PAT_RECEIVED.matcher(line);
        if (matcher.matches()) {
            ZimbraLog.test.debug("Found " + line);
            foundReceived = true;
        }
        matcher = PAT_RETURN_PATH.matcher(line);
        if (matcher.matches()) {
            foundReturnPath = true;
            Assert.assertEquals("Sender doesn't match", sender, matcher.group(1));
            ZimbraLog.test.debug("Found " + line);
        }
        line = reader.readLine();
    }
    reader.close();
    Assert.assertTrue("Received header not found.  Content=\n" + content, foundReceived);
    Assert.assertTrue("Return-Path header not found.  Content=\n" + content, foundReturnPath);
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) ZGetMessageParams(com.zimbra.client.ZGetMessageParams) Matcher(java.util.regex.Matcher) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 4 with ZGetMessageParams

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

the class TestLmtp method testSizeHint.

/**
     * Confirms that a message gets delivered regardless of what the size hint is set to.
     */
@Test
public void testSizeHint() throws Exception {
    // Send the same message 5 times with different size hints
    String address = TestUtil.getAddress(USER_NAME);
    String subject = NAME_PREFIX + " testIncorrectSizeHint";
    String messageString = TestUtil.getTestMessage(subject, address, address, null);
    String[] recipients = new String[] { address };
    LmtpClient lmtp = new LmtpClient("localhost", 7025);
    byte[] data = messageString.getBytes();
    lmtp.sendMessage(new ByteArrayInputStream(data), recipients, address, "TestLmtp", null);
    lmtp.sendMessage(new ByteArrayInputStream(data), recipients, address, "TestLmtp", 0L);
    lmtp.sendMessage(new ByteArrayInputStream(data), recipients, address, "TestLmtp", 10L);
    lmtp.sendMessage(new ByteArrayInputStream(data), recipients, address, "TestLmtp", (long) data.length);
    lmtp.sendMessage(new ByteArrayInputStream(data), recipients, address, "TestLmtp", (long) Integer.MAX_VALUE);
    lmtp.close();
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    List<ZMessage> messages = TestUtil.search(mbox, subject);
    Assert.assertEquals(5, messages.size());
    // Check message bodies
    ZGetMessageParams params = new ZGetMessageParams();
    params.setRawContent(true);
    for (ZMessage msg : messages) {
        String content = TestUtil.getContent(mbox, msg.getId());
        TestUtil.assertMessageContains(content, messageString);
    }
}
Also used : ZMessage(com.zimbra.client.ZMessage) LmtpClient(com.zimbra.common.lmtp.LmtpClient) ZMailbox(com.zimbra.client.ZMailbox) ZGetMessageParams(com.zimbra.client.ZGetMessageParams) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 5 with ZGetMessageParams

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

the class TestUtil method search.

public static List<ZMessage> search(ZMailbox mbox, ZSearchParams params) throws ServiceException {
    List<ZMessage> msgs = new ArrayList<ZMessage>();
    for (ZSearchHit hit : mbox.search(params).getHits()) {
        ZGetMessageParams msgParams = new ZGetMessageParams();
        msgParams.setId(hit.getId());
        msgs.add(mbox.getMessage(msgParams));
    }
    return msgs;
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZSearchHit(com.zimbra.client.ZSearchHit) ZGetMessageParams(com.zimbra.client.ZGetMessageParams) ArrayList(java.util.ArrayList)

Aggregations

ZGetMessageParams (com.zimbra.client.ZGetMessageParams)5 ZMessage (com.zimbra.client.ZMessage)5 ZMailbox (com.zimbra.client.ZMailbox)2 Test (org.junit.Test)2 ZMimePart (com.zimbra.client.ZMessage.ZMimePart)1 ZSearchHit (com.zimbra.client.ZSearchHit)1 LmtpClient (com.zimbra.common.lmtp.LmtpClient)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1