Search in sources :

Example 96 with ZMessage

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

the class TestLmtp method testTransparency.

@Test
public void testTransparency() throws Exception {
    String subject = NAME_PREFIX + " LMTPTransparency1";
    String body = "line1\r\n.line2\r\n..line3\r\n...line4\r\n";
    Assert.assertTrue(TestUtil.addMessageLmtp(subject, new String[] { USER_NAME }, USER_NAME, body));
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    ZMessage msg = TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
    String currentBody = msg.getMimeStructure().getContent();
    TestUtil.assertMessageContains(currentBody, body);
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) Test(org.junit.Test)

Example 97 with ZMessage

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

the class TestLmtp method testAttachedMessage.

/**
     * Sends a message with another message attached and confirms that the subject
     * of the attached message is indexed.
     * @see MessageRFC822Handler
     */
@Test
public void testAttachedMessage() throws Exception {
    String outerSubject = NAME_PREFIX + " testAttachedMessage outer";
    String innerSubject = NAME_PREFIX + " testAttachedMessage inner";
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    // Assemble outer message
    ZOutgoingMessage msg = new ZOutgoingMessage();
    List<ZEmailAddress> addresses = new ArrayList<ZEmailAddress>();
    addresses.add(new ZEmailAddress(TestUtil.getAddress(USER_NAME), null, null, ZEmailAddress.EMAIL_TYPE_TO));
    msg.setAddresses(addresses);
    msg.setSubject(outerSubject);
    // Assemble body and inner message
    String attachedMessageString = TestUtil.getTestMessage(innerSubject, USER_NAME, USER_NAME, null);
    MessagePart attachedMessage = new MessagePart("message/rfc822", attachedMessageString);
    MessagePart body = new MessagePart("text/plain", "This is the outer message");
    msg.setMessagePart(new MessagePart("multipart/mixed", body, attachedMessage));
    // Send and wait for it to arrive
    mbox.sendMessage(msg, null, false);
    TestUtil.waitForMessage(mbox, "in:inbox " + outerSubject);
    // Test search for message subject
    List<ZMessage> msgs = TestUtil.search(mbox, "in:inbox " + innerSubject);
    Assert.assertEquals(1, msgs.size());
    msgs = TestUtil.search(mbox, "in:sent " + innerSubject);
    Assert.assertEquals(1, msgs.size());
    // Test search for message body
    msgs = TestUtil.search(mbox, "in:inbox " + NAME_PREFIX + " waves");
    Assert.assertEquals(1, msgs.size());
    msgs = TestUtil.search(mbox, "in:sent " + NAME_PREFIX + " waves");
    Assert.assertEquals(1, msgs.size());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) ZMailbox(com.zimbra.client.ZMailbox) ZEmailAddress(com.zimbra.client.ZEmailAddress) MessagePart(com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 98 with ZMessage

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

the class TestLmtp method testFinalDotNotSent.

// bug 53058
@Test
public void testFinalDotNotSent() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    LmtpClient lmtpClient = new LmtpClient("localhost", Provisioning.getInstance().getLocalServer().getIntAttr(Provisioning.A_zimbraLmtpBindPort, 7025));
    Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
    lmtpClient.sendLine("LHLO " + LC.zimbra_server_hostname.value());
    Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
    if (lmtpClient.getResponse().contains(STARTTLS)) {
        lmtpClient.startTLS();
        lmtpClient.sendLine("LHLO " + LC.zimbra_server_hostname.value());
        Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
    }
    lmtpClient.sendLine("MAIL FROM:<" + TestUtil.addDomainIfNecessary(USER_NAME) + ">");
    Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
    lmtpClient.sendLine("RCPT TO:<" + TestUtil.addDomainIfNecessary(USER_NAME) + ">");
    Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
    lmtpClient.sendLine("DATA");
    Assert.assertTrue(lmtpClient.getResponse(), lmtpClient.replyOk());
    String subject = NAME_PREFIX + " testFinalDotNotSent";
    lmtpClient.sendLine("Subject: " + subject);
    lmtpClient.abruptClose();
    // wait for some time
    Thread.sleep(1000);
    List<ZMessage> msgs = TestUtil.search(mbox, "in:inbox " + subject);
    Assert.assertTrue("msg got delivered via LMTP even though <CRLF>.<CRLF> was not received", msgs.isEmpty());
}
Also used : ZMessage(com.zimbra.client.ZMessage) LmtpClient(com.zimbra.common.lmtp.LmtpClient) ZMailbox(com.zimbra.client.ZMailbox) Test(org.junit.Test)

Example 99 with ZMessage

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

the class TestLmtp method testConcurrentDedupe.

/**
     * Tests the LMTP deduping code.  Attempts to deliver multiple copies of the
     * same message to the same message to the same mailbox simultaneously.  Confirms
     * that only one copy got delivered.  Bug 38898.
     */
@Test
public void testConcurrentDedupe() throws Exception {
    String subject = NAME_PREFIX + " testConcurrentDedupe";
    String content = TestUtil.getTestMessage(subject, USER_NAME, USER_NAME, null);
    content = "Message-ID: " + System.currentTimeMillis() + "\r\n" + content;
    Thread[] threads = new Thread[5];
    for (int i = 0; i < threads.length; i++) {
        threads[i] = new Thread(new LmtpClientThread(USER_NAME, content));
    }
    for (Thread thread : threads) {
        thread.start();
    }
    for (Thread thread : threads) {
        thread.join();
    }
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    List<ZMessage> messages = TestUtil.search(mbox, "in:inbox subject:\"" + subject + "\"");
    Assert.assertEquals(1, messages.size());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) Test(org.junit.Test)

Example 100 with ZMessage

use of com.zimbra.client.ZMessage 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

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