Search in sources :

Example 1 with ImapResponse

use of com.zimbra.cs.mailclient.imap.ImapResponse in project zm-mailbox by Zimbra.

the class TestImap method testStoreTagsDirty.

@Test
public void testStoreTagsDirty() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER);
    List<ZTag> tags = mbox.getAllTags();
    assertTrue(tags == null || tags.size() == 0);
    String tagName = "T1";
    final String tagName2 = "T2";
    ZTag tag = mbox.getTag(tagName);
    if (tag == null) {
        tag = mbox.createTag(tagName, Color.blue);
    }
    tags = mbox.getAllTags();
    assertTrue(tags != null && tags.size() == 1);
    assertEquals("T1", tags.get(0).getName());
    String folderName = "newfolder1";
    ZFolder folder = mbox.createFolder(Mailbox.ID_FOLDER_USER_ROOT + "", folderName, ZFolder.View.message, ZFolder.Color.DEFAULTCOLOR, null, null);
    mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", tag.getId(), System.currentTimeMillis(), simpleMessage("foo1"), true);
    MailboxInfo info = connection.select("INBOX");
    assertTrue("INBOX does not contain expected flag " + tagName, info.getFlags().isSet(tagName));
    assertFalse("INBOX contain unexpected flag " + tagName2, info.getFlags().isSet(tagName2));
    Map<Long, MessageData> data = connection.fetch("1:*", "FLAGS");
    assertEquals(1, data.size());
    Iterator<Long> it = data.keySet().iterator();
    Long seq = it.next();
    assertTrue("flag not set on first message", data.get(seq).getFlags().isSet(tagName));
    ImapRequest req = connection.newRequest("STORE", seq + "", "+FLAGS", tagName2);
    req.setResponseHandler(new ResponseHandler() {

        @Override
        public void handleResponse(ImapResponse res) throws Exception {
            if (res.isUntagged() && res.getCCode() == CAtom.FLAGS) {
                Flags flags = (Flags) res.getData();
                assertTrue(flags.isSet(tagName2));
            }
        }
    });
    req.sendCheckStatus();
}
Also used : ResponseHandler(com.zimbra.cs.mailclient.imap.ResponseHandler) MessageData(com.zimbra.cs.mailclient.imap.MessageData) ImapRequest(com.zimbra.cs.mailclient.imap.ImapRequest) ZTag(com.zimbra.client.ZTag) ImapResponse(com.zimbra.cs.mailclient.imap.ImapResponse) Flags(com.zimbra.cs.mailclient.imap.Flags) ServiceException(com.zimbra.common.service.ServiceException) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) Test(org.junit.Test)

Example 2 with ImapResponse

use of com.zimbra.cs.mailclient.imap.ImapResponse in project zm-mailbox by Zimbra.

the class SharedImapTests method testOverflowNotAppend.

@Test(timeout = 100000)
public void testOverflowNotAppend() throws Exception {
    connection = connectAndSelectInbox();
    int oldReadTimeout = connection.getConfig().getReadTimeout();
    try {
        connection.setReadTimeout(10);
        ImapRequest req = connection.newRequest(CAtom.FETCH, "1:*");
        req.addParam("{" + ((long) (Integer.MAX_VALUE) + 1) + "+}");
        ImapResponse resp = req.send();
        assertTrue("response should be NO or BAD", resp.isNO() || resp.isBAD());
    } finally {
        connection.setReadTimeout(oldReadTimeout);
    }
}
Also used : ImapRequest(com.zimbra.cs.mailclient.imap.ImapRequest) ImapResponse(com.zimbra.cs.mailclient.imap.ImapResponse) Test(org.junit.Test)

Example 3 with ImapResponse

use of com.zimbra.cs.mailclient.imap.ImapResponse in project zm-mailbox by Zimbra.

the class SharedImapTests method testAppendTagsDirty.

@Test(timeout = 100000)
public void testAppendTagsDirty() throws Exception {
    connection = connectAndSelectInbox();
    Flags flags = Flags.fromSpec("afs");
    // new tag; does not exist in mbox
    final String tag1 = "NEWDIRTYTAG";
    MailboxInfo info = connection.select("INBOX");
    assertFalse("INBOX contains unexpected flag " + tag1, info.getFlags().isSet(tag1));
    flags.set(tag1);
    Date date = new Date(System.currentTimeMillis());
    Literal msg = message(10);
    try {
        ImapRequest req = connection.newRequest("APPEND", "INBOX", flags, date, msg);
        req.setResponseHandler(new ResponseHandler() {

            @Override
            public void handleResponse(ImapResponse res) throws Exception {
                if (res.isUntagged() && res.getCCode() == CAtom.FLAGS) {
                    Flags flags = (Flags) res.getData();
                    assertTrue(flags.isSet(tag1));
                }
            }
        });
        req.sendCheckStatus();
    } finally {
        msg.dispose();
    }
}
Also used : ResponseHandler(com.zimbra.cs.mailclient.imap.ResponseHandler) Literal(com.zimbra.cs.mailclient.imap.Literal) ImapRequest(com.zimbra.cs.mailclient.imap.ImapRequest) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) ImapResponse(com.zimbra.cs.mailclient.imap.ImapResponse) Flags(com.zimbra.cs.mailclient.imap.Flags) Date(java.util.Date) MessagingException(javax.mail.MessagingException) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with ImapResponse

use of com.zimbra.cs.mailclient.imap.ImapResponse in project zm-mailbox by Zimbra.

the class SharedImapTests method testFolderDeletedByOtherConnectionSelected.

@Test(timeout = 100000)
public void testFolderDeletedByOtherConnectionSelected() throws Exception {
    String newFolder = "imaptest1";
    connection = connectAndLogin(USER);
    connection.create(newFolder);
    otherConnection = connectAndLogin(USER);
    otherConnection.select(newFolder);
    assertTrue("Second connection should be in SELECTED state", otherConnection.isSelected());
    assertFalse("First connection should NOT be in SELECTED state", connection.isSelected());
    final CountDownLatch doneSignal = new CountDownLatch(1);
    final AtomicBoolean gotBye = new AtomicBoolean(false);
    // Wait for BYE from IMAP server. Zimbra IMAP client does not detect when connection is dropped by server
    otherConnection.idle(new ResponseHandler() {

        @Override
        public void handleResponse(ImapResponse res) {
            if (res.isBYE()) {
                gotBye.set(true);
                doneSignal.countDown();
            }
        }
    });
    assertTrue("Connection is not idling when it should be", otherConnection.isIdling());
    connection.delete(newFolder);
    try {
        doneSignal.await(10, TimeUnit.SECONDS);
    } catch (Exception e) {
        fail("Wait interrupted. ");
    }
    assertTrue("Second connection should have received BYE", gotBye.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ResponseHandler(com.zimbra.cs.mailclient.imap.ResponseHandler) ImapResponse(com.zimbra.cs.mailclient.imap.ImapResponse) CountDownLatch(java.util.concurrent.CountDownLatch) MessagingException(javax.mail.MessagingException) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with ImapResponse

use of com.zimbra.cs.mailclient.imap.ImapResponse in project zm-mailbox by Zimbra.

the class SharedImapTests method testZCS1781.

@Test(timeout = 100000)
public void testZCS1781() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER);
    TestUtil.addMessage(mbox, "test for ZCS-1781");
    connection = connectAndSelectInbox();
    final AtomicReference<MessageData> storeResponse = new AtomicReference<MessageData>();
    final CountDownLatch doneSignal = new CountDownLatch(1);
    connection.store("1", "FLAGS", "(\\Deleted)", new ResponseHandler() {

        @Override
        public void handleResponse(ImapResponse res) {
            storeResponse.set((MessageData) (res.getData()));
            doneSignal.countDown();
        }
    });
    try {
        doneSignal.await(10, TimeUnit.SECONDS);
    } catch (Exception e) {
        fail("Wait interrupted. ");
    }
    MessageData data = storeResponse.get();
    assertNotNull("data in IMAP response should not be null", data);
    Flags flags = data.getFlags();
    assertNotNull("flags in IMAP response should not be null", flags);
    assertTrue("should have \\Deleted flag", flags.isDeleted());
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ResponseHandler(com.zimbra.cs.mailclient.imap.ResponseHandler) MessageData(com.zimbra.cs.mailclient.imap.MessageData) AtomicReference(java.util.concurrent.atomic.AtomicReference) ImapResponse(com.zimbra.cs.mailclient.imap.ImapResponse) Flags(com.zimbra.cs.mailclient.imap.Flags) CountDownLatch(java.util.concurrent.CountDownLatch) MessagingException(javax.mail.MessagingException) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

ImapResponse (com.zimbra.cs.mailclient.imap.ImapResponse)12 Test (org.junit.Test)12 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)8 ImapRequest (com.zimbra.cs.mailclient.imap.ImapRequest)8 ResponseHandler (com.zimbra.cs.mailclient.imap.ResponseHandler)8 IOException (java.io.IOException)8 Flags (com.zimbra.cs.mailclient.imap.Flags)7 ServiceException (com.zimbra.common.service.ServiceException)6 MailboxInfo (com.zimbra.cs.mailclient.imap.MailboxInfo)6 MessagingException (javax.mail.MessagingException)6 MessageData (com.zimbra.cs.mailclient.imap.MessageData)4 ZMailbox (com.zimbra.client.ZMailbox)3 Date (java.sql.Date)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ZTag (com.zimbra.client.ZTag)2 MailException (com.zimbra.cs.mailclient.MailException)2 Literal (com.zimbra.cs.mailclient.imap.Literal)2 MailboxName (com.zimbra.cs.mailclient.imap.MailboxName)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2