Search in sources :

Example 46 with ZMailbox

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

the class SharedImapNotificationTests method testDeleteMessageNotificationActiveFolder.

@Test
public void testDeleteMessageNotificationActiveFolder() throws Exception {
    String folderName1 = "TestRemoteImapNotifications-folder";
    String subject1 = "TestRemoteImapNotifications-testMessage1";
    String subject2 = "TestRemoteImapNotifications-testMessage2";
    ZMailbox zmbox = TestUtil.getZMailbox(USER);
    ZFolder folder = TestUtil.createFolder(zmbox, folderName1);
    String msgId = TestUtil.addMessage(zmbox, subject1, folder.getId(), null);
    TestUtil.addMessage(zmbox, subject2, folder.getId(), null);
    connection = connect();
    connection.login(PASS);
    connection.select(folderName1);
    Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE BODY)");
    assertEquals("Size of map returned by initial fetch", 2, mdMap.size());
    MailboxOperation deleteMessage = new MailboxOperation() {

        @Override
        protected void run(ZMailbox zmbox) throws Exception {
            zmbox.deleteMessage(msgId);
        }

        @Override
        protected String checkResult() throws Exception {
            Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE BODY)");
            assertEquals("Size of map returned by fetch 2", 2, mdMap.size());
            MessageData md = mdMap.get(1L);
            // verify that the deleted message has a NIL response
            Envelope envelope = md.getEnvelope();
            if (envelope == null) {
                return "Envelope should not be NULL";
            }
            if (envelope.getSubject() != null) {
                return "Envelope::subject should be NULL";
            }
            BodyStructure bs = md.getBodyStructure();
            if (bs.getSize() != 0) {
                return "BodyStructure::geSize should return 0";
            }
            // verify that the second message is correct
            md = mdMap.get(2L);
            if (!subject2.equals(md.getEnvelope().getSubject())) {
                return String.format("Subject should be %s. Getting %d", subject2, md.getEnvelope().getSubject());
            }
            connection.expunge();
            mdMap = connection.fetch("1:*", "(ENVELOPE BODY)");
            if (mdMap.size() != 1) {
                return String.format("Size of map returned by fetch should be 1. Getting %d", mdMap.size());
            }
            return null;
        }
    };
    runOp(deleteMessage, zmbox, folder);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) BodyStructure(com.zimbra.cs.mailclient.imap.BodyStructure) ZFolder(com.zimbra.client.ZFolder) Envelope(com.zimbra.cs.mailclient.imap.Envelope) Test(org.junit.Test)

Example 47 with ZMailbox

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

the class SharedImapNotificationTests method testNotificationsCachedFolder.

@Test
public void testNotificationsCachedFolder() throws Exception {
    String folderName1 = "testNotificationsCachedFolder-folder1";
    String folderName2 = "testNotificationsCachedFolder-folder2";
    String subject1 = "TestRemoteImapNotifications-testMessage1";
    String subject2 = "TestRemoteImapNotifications-testMessage2";
    ZMailbox zmbox = TestUtil.getZMailbox(USER);
    ZFolder folder1 = TestUtil.createFolder(zmbox, folderName1);
    TestUtil.createFolder(zmbox, folderName2);
    TestUtil.addMessage(zmbox, subject1, folder1.getId(), null);
    connection = connect();
    connection.login(PASS);
    connection.select(folderName1);
    Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE BODY)");
    assertEquals("Size of map returned by initial fetch", 1, mdMap.size());
    connection.select(folderName2);
    MailboxOperation addMessage = new MailboxOperation() {

        @Override
        protected void run(ZMailbox zmbox) throws Exception {
            TestUtil.addMessage(zmbox, subject2, folder1.getId(), null);
        }

        @Override
        protected String checkResult() throws Exception {
            connection.select(folderName1);
            Map<Long, MessageData> mdMap = connection.fetch("1:*", "(FLAGS)");
            if (mdMap.size() != 2) {
                return String.format("Size of map returned by fetch afer reselecting cached folder should be 2. Getting %d", mdMap.size());
            }
            return null;
        }
    };
    runOp(addMessage, zmbox, folder1);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) ZFolder(com.zimbra.client.ZFolder) Test(org.junit.Test)

Example 48 with ZMailbox

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

the class SharedImapNotificationTests method testDeleteTagNotificationActiveFolder.

@Test
public void testDeleteTagNotificationActiveFolder() throws Exception {
    String folderName = "TestRemoteImapNotifications-folder";
    String tagName = "TestRemoteImapNotifications-tag";
    String subject = "TestRemoteImapNotifications-testMessage";
    ZMailbox zmbox = TestUtil.getZMailbox(USER);
    ZFolder folder = TestUtil.createFolder(zmbox, folderName);
    ZTag tag = zmbox.createTag(tagName, Color.blue);
    zmbox.addMessage(folder.getId(), null, tag.getId(), 0, TestUtil.getTestMessage(subject), true);
    connection = connect();
    connection.login(PASS);
    MailboxInfo info = connection.select(folderName);
    Flags flags = info.getPermanentFlags();
    assertTrue("folder info should list tag", flags.contains(new Atom(tagName)));
    Map<Long, MessageData> mdMap = connection.fetch("1:*", "(FLAGS)");
    Flags msgFlags = mdMap.get(1L).getFlags();
    assertTrue("message should be flagged with tag", msgFlags.contains(new Atom(tagName)));
    MailboxOperation deleteTag = new MailboxOperation() {

        @Override
        protected void run(ZMailbox zmbox) throws Exception {
            zmbox.deleteTag(tag.getId());
        }

        @Override
        protected String checkResult() throws Exception {
            MailboxInfo info = connection.select(folderName);
            Flags flags = info.getPermanentFlags();
            if (flags.contains(new Atom(tagName))) {
                return String.format("folder info should not list tag %s", tagName);
            }
            Map<Long, MessageData> mdMap = connection.fetch("1:*", "(FLAGS)");
            Flags msgFlags = mdMap.get(1L).getFlags();
            if (msgFlags.contains(new Atom(tagName))) {
                return String.format("message should not be flagged with %s", tagName);
            }
            return null;
        }
    };
    runOp(deleteTag, zmbox, folder);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) ZFolder(com.zimbra.client.ZFolder) ZTag(com.zimbra.client.ZTag) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) Flags(com.zimbra.cs.mailclient.imap.Flags) Atom(com.zimbra.cs.mailclient.imap.Atom) Test(org.junit.Test)

Example 49 with ZMailbox

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

the class SharedImapNotificationTests method testDeleteMessageNotificationCachedFolder.

@Test
public void testDeleteMessageNotificationCachedFolder() throws Exception {
    String folderName1 = "TestRemoteImapNotifications-folder";
    String folderName2 = "TestRemoteImapNotifications-folder2";
    String subject1 = "TestRemoteImapNotifications-testMessage1";
    String subject2 = "TestRemoteImapNotifications-testMessage2";
    ZMailbox zmbox = TestUtil.getZMailbox(USER);
    ZFolder folder = TestUtil.createFolder(zmbox, folderName1);
    TestUtil.createFolder(zmbox, folderName2);
    String msgId = TestUtil.addMessage(zmbox, subject1, folder.getId(), null);
    TestUtil.addMessage(zmbox, subject2, folder.getId(), null);
    connection = connect();
    connection.login(PASS);
    connection.select(folderName1);
    Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE BODY)");
    assertEquals("Size of map returned by initial fetch", 2, mdMap.size());
    connection.select(folderName2);
    MailboxOperation deleteMessage = new MailboxOperation() {

        @Override
        protected void run(ZMailbox zmbox) throws Exception {
            zmbox.deleteMessage(msgId);
        }

        @Override
        protected String checkResult() throws Exception {
            connection.select(folderName1);
            Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE BODY)");
            // expunged messages are not returned as NIL responses if folder is re-selected
            if (mdMap.size() != 1) {
                return String.format("Size of map returned by fetch should be 1. Getting %d", mdMap.size());
            }
            return null;
        }
    };
    runOp(deleteMessage, zmbox, folder);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) ZFolder(com.zimbra.client.ZFolder) Test(org.junit.Test)

Example 50 with ZMailbox

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

the class SharedImapNotificationTests method testModifyItemNotificationCachedFolder.

@Test
public void testModifyItemNotificationCachedFolder() throws Exception {
    String folderName1 = "testNotificationsActiveFolder-folder1";
    String folderName2 = "testNotificationsActiveFolder-folder2";
    String subject = "testNotificationsActiveFolder-msg1";
    String tagName = "testNotificationsActiveFolder-tag";
    ZMailbox zmbox = TestUtil.getZMailbox(USER);
    ZFolder folder = TestUtil.createFolder(zmbox, folderName1);
    TestUtil.createFolder(zmbox, folderName2);
    ZTag tag = zmbox.createTag(tagName, Color.blue);
    String msgId = TestUtil.addMessage(zmbox, subject, folder.getId(), null);
    connection = connect();
    connection.login(PASS);
    connection.select(folderName1);
    Map<Long, MessageData> mdMap = connection.fetch("1:*", "(FLAGS)");
    assertEquals("Size of map returned by fetch 1", 1, mdMap.size());
    // sanity check - make sure the tag is not already set on the message
    Flags flags = mdMap.get(1L).getFlags();
    assertFalse(flags.contains(new Atom(tag.getName())));
    connection.select(folderName2);
    MailboxOperation tagMessage = new MailboxOperation() {

        @Override
        protected void run(ZMailbox zmbox) throws Exception {
            zmbox.tagMessage(msgId, tag.getId(), true);
        }

        @Override
        protected String checkResult() throws Exception {
            connection.select(folderName1);
            Map<Long, MessageData> mdMap = connection.fetch("1:*", "(FLAGS)");
            if (mdMap.size() != 1) {
                return String.format("Size of map returned by fetch should be 1. Found: %d", mdMap.size());
            }
            Flags flags = mdMap.get(1L).getFlags();
            if (!flags.contains(new Atom(tag.getName()))) {
                return String.format("Flags should contain %s", tag.getName());
            }
            return null;
        }
    };
    runOp(tagMessage, zmbox, folder);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) ZFolder(com.zimbra.client.ZFolder) ZTag(com.zimbra.client.ZTag) Flags(com.zimbra.cs.mailclient.imap.Flags) Atom(com.zimbra.cs.mailclient.imap.Atom) 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