Search in sources :

Example 6 with LmtpClient

use of com.zimbra.common.lmtp.LmtpClient in project zm-mailbox by Zimbra.

the class TestLmtp method testLhloNotSendByClientAfterStartTLS.

@Test
public void testLhloNotSendByClientAfterStartTLS() throws Exception {
    String[] commands = new String[] { NOOP, RSET, VRFY + " " + USER_NAME, "MAIL FROM:<" + TestUtil.addDomainIfNecessary(USER_NAME) + ">" };
    LmtpClient lmtpClient;
    Provisioning prov = Provisioning.getInstance();
    boolean lhloRequired = prov.getLocalServer().getBooleanAttr(Provisioning.A_zimbraLmtpLHLORequired, true);
    boolean replyOk;
    for (String command : commands) {
        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(command);
            replyOk = lmtpClient.replyOk();
            Assert.assertTrue("Response :" + lmtpClient.getResponse() + " for command :" + command, lhloRequired ? !replyOk : replyOk);
        }
        lmtpClient.abruptClose();
    }
}
Also used : LmtpClient(com.zimbra.common.lmtp.LmtpClient) Provisioning(com.zimbra.cs.account.Provisioning) Test(org.junit.Test)

Example 7 with LmtpClient

use of com.zimbra.common.lmtp.LmtpClient 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 8 with LmtpClient

use of com.zimbra.common.lmtp.LmtpClient 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 9 with LmtpClient

use of com.zimbra.common.lmtp.LmtpClient in project zm-mailbox by Zimbra.

the class TestLmtp method testServeShouldNotPublishStartTlsOnSecondLlhoCommand.

@Test
public void testServeShouldNotPublishStartTlsOnSecondLlhoCommand() throws Exception {
    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());
        Assert.assertTrue(lmtpClient.getResponse(), !lmtpClient.getResponse().contains(STARTTLS));
    }
    lmtpClient.abruptClose();
}
Also used : LmtpClient(com.zimbra.common.lmtp.LmtpClient) Test(org.junit.Test)

Aggregations

LmtpClient (com.zimbra.common.lmtp.LmtpClient)9 Test (org.junit.Test)7 ZMailbox (com.zimbra.client.ZMailbox)3 ZMessage (com.zimbra.client.ZMessage)3 Provisioning (com.zimbra.cs.account.Provisioning)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ZGetMessageParams (com.zimbra.client.ZGetMessageParams)1 ZMountpoint (com.zimbra.client.ZMountpoint)1 LmtpProtocolException (com.zimbra.common.lmtp.LmtpProtocolException)1 Rfc822ValidationInputStream (com.zimbra.common.mime.Rfc822ValidationInputStream)1 DeliveryServiceException (com.zimbra.common.service.DeliveryServiceException)1 ServiceException (com.zimbra.common.service.ServiceException)1 CopyInputStream (com.zimbra.common.util.CopyInputStream)1 Server (com.zimbra.cs.account.Server)1 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 BlobInputStream (com.zimbra.cs.store.BlobInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MessagingException (javax.mail.MessagingException)1