Search in sources :

Example 61 with ZMailbox

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

the class TestLmtp method testDiskStreamingMultipleRecipients.

/**
 * Confirms that mail can successfully be delivered to multiple users when streaming to disk.
 */
@Test
public void testDiskStreamingMultipleRecipients() throws Exception {
    TestUtil.createAccount(USER2_NAME);
    TestUtil.setServerAttr(Provisioning.A_zimbraMailDiskStreamingThreshold, "0");
    String[] recipients = { TestUtil.getAddress(USER_NAME), TestUtil.getAddress(USER2_NAME) };
    String subject = NAME_PREFIX + " testDiskStreamingMultipleRecipients";
    ZMailbox mbox1 = TestUtil.getZMailbox(USER_NAME);
    ZMailbox mbox2 = TestUtil.getZMailbox(USER2_NAME);
    TestUtil.addMessageLmtp(subject, recipients, TestUtil.getAddress(USER_NAME));
    TestUtil.waitForMessage(mbox1, "in:inbox subject:\"" + subject + "\"");
    ZMessage msg2 = TestUtil.waitForMessage(mbox2, "in:inbox subject:\"" + subject + "\"");
    // Test bug 25484.  Make sure that user1 can still read the message after user2
    // deletes it.
    mbox2.deleteMessage(msg2.getId());
    mbox1 = TestUtil.getZMailbox(USER_NAME);
    TestUtil.waitForMessage(mbox1, "in:inbox subject:\"" + subject + "\"");
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) Test(org.junit.Test)

Example 62 with ZMailbox

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

the class TestLmtp method testDedupePref.

/**
 * Verifies the behavior of {@code zimbraPrefMessageIdDedupingEnabled}.
 */
@Test
public void testDedupePref() throws Exception {
    String subject = NAME_PREFIX + " testDedupePref";
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    Account account = TestUtil.getAccount(USER_NAME);
    String[] recipients = new String[] { USER_NAME };
    // Deliver initial message.
    String content = new MessageBuilder().withSubject(subject).withToRecipient(USER_NAME).withFrom(USER_NAME).withMessageIdHeader().create();
    TestUtil.addMessageLmtp(recipients, USER_NAME, content);
    String query = "in:inbox subject:\"" + subject + "\"";
    // Redeliver with deduping enabled.
    account.setPrefMessageIdDedupingEnabled(true);
    TestUtil.addMessageLmtp(recipients, USER_NAME, content);
    Assert.assertEquals(1, TestUtil.search(mbox, query).size());
    // Redeliver with deduping disabled;
    account.setPrefMessageIdDedupingEnabled(false);
    TestUtil.addMessageLmtp(recipients, USER_NAME, content);
    Assert.assertEquals(2, TestUtil.search(mbox, query).size());
}
Also used : Account(com.zimbra.cs.account.Account) ZMailbox(com.zimbra.client.ZMailbox) Test(org.junit.Test)

Example 63 with ZMailbox

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

the class TestLmtp method disableTestDedupeCacheTimeout.

/**
 * Verifies the behavior of {@code zimbraMessageIdDedupeCacheTimeout}.
 */
// disable due to bug 76332
public void disableTestDedupeCacheTimeout() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    // Deliver initial message.
    String subject = NAME_PREFIX + " testDedupeCacheTimeout";
    String[] recipients = new String[] { USER_NAME };
    String content = new MessageBuilder().withSubject(subject).withToRecipient(USER_NAME).withFrom(USER_NAME).withMessageIdHeader().create();
    TestUtil.addMessageLmtp(recipients, USER_NAME, content);
    String query = "in:inbox subject:\"" + subject + "\"";
    Assert.assertEquals("message should have been delivered", 1, TestUtil.search(mbox, query).size());
    // Set deduping cache timeout to 0.5 sec
    TestUtil.setConfigAttr(Provisioning.A_zimbraMessageIdDedupeCacheTimeout, "500ms");
    // Redeliver same message immediately
    TestUtil.addMessageLmtp(recipients, USER_NAME, content);
    Assert.assertEquals("deduping should have happened", 1, TestUtil.search(mbox, query).size());
    // sleep for just over 0.5 sec
    Thread.sleep(501);
    // Redeliver
    TestUtil.addMessageLmtp(recipients, USER_NAME, content);
    Assert.assertEquals("dedupe cache entry should have timed out", 2, TestUtil.search(mbox, query).size());
}
Also used : ZMailbox(com.zimbra.client.ZMailbox)

Example 64 with ZMailbox

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

the class TestLmtp method testStartTLSSuccess.

@Test
public void testStartTLSSuccess() 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 65 with ZMailbox

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

the class TestLmtp method testAllowReceiveButNotSendWhenOverQuota.

/**
 * Verifies send/receive behavior for {@code zimbraMailAllowReceiveButNotSendWhenOverQuota}.
 */
@Test
public void testAllowReceiveButNotSendWhenOverQuota() throws Exception {
    TestUtil.setAccountAttr(USER_NAME, Provisioning.A_zimbraMailAllowReceiveButNotSendWhenOverQuota, LdapConstants.LDAP_TRUE);
    TestUtil.setAccountAttr(USER_NAME, Provisioning.A_zimbraMailQuota, "1");
    String subject = NAME_PREFIX + " testAllowReceiveButNotSendWhenOverQuota";
    // Verify that receive is allowed.
    TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    TestUtil.getMessage(mbox, "in:inbox subject:\"" + subject + "\"");
    // Verify that send is disallowed.
    try {
        TestUtil.sendMessage(mbox, USER_NAME, subject);
        Assert.fail("Send should have failed");
    } catch (ServiceException e) {
        Assert.assertEquals(MailServiceException.QUOTA_EXCEEDED, e.getCode());
    }
    // Verify that adding a document is disallowed.
    try {
        byte[] data = new byte[1024];
        TestUtil.createDocument(mbox, Integer.toString(Mailbox.ID_FOLDER_BRIEFCASE), NAME_PREFIX + " receivenosend.bin", "application/content-stream", data);
        Assert.fail("Document creation should have failed");
    } catch (ServiceException e) {
        Assert.assertEquals(MailServiceException.QUOTA_EXCEEDED, e.getCode());
    }
    // Verify that saving a draft is allowed (bug 51457).
    String draftSubject1 = subject + " save draft 1";
    String draftSubject2 = subject + " save draft 2 two";
    ZOutgoingMessage outgoingDraft = TestUtil.getOutgoingMessage(USER_NAME, draftSubject1, draftSubject1, null);
    // Add message
    ZMessage draftMsg = mbox.saveDraft(outgoingDraft, null, Integer.toString(Mailbox.ID_FOLDER_DRAFTS));
    outgoingDraft = TestUtil.getOutgoingMessage(USER_NAME, draftSubject2, draftSubject2, null);
    // Set content of existing message
    mbox.saveDraft(outgoingDraft, draftMsg.getId(), Integer.toString(Mailbox.ID_FOLDER_DRAFTS));
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) ZMailbox(com.zimbra.client.ZMailbox) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) Test(org.junit.Test)

Aggregations

ZMailbox (com.zimbra.client.ZMailbox)383 Test (org.junit.Test)288 ZFolder (com.zimbra.client.ZFolder)90 ZMessage (com.zimbra.client.ZMessage)82 Mailbox (com.zimbra.cs.mailbox.Mailbox)61 Account (com.zimbra.cs.account.Account)60 ServiceException (com.zimbra.common.service.ServiceException)55 ArrayList (java.util.ArrayList)38 IOException (java.io.IOException)35 MessageData (com.zimbra.cs.mailclient.imap.MessageData)28 ZMountpoint (com.zimbra.client.ZMountpoint)26 Message (com.zimbra.cs.mailbox.Message)24 HashMap (java.util.HashMap)23 ZOutgoingMessage (com.zimbra.client.ZMailbox.ZOutgoingMessage)21 ZTag (com.zimbra.client.ZTag)21 SoapFaultException (com.zimbra.common.soap.SoapFaultException)21 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)21 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)20 HttpClient (org.apache.http.client.HttpClient)19 ZSearchParams (com.zimbra.client.ZSearchParams)18