Search in sources :

Example 41 with MessageData

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

the class SharedImapNotificationTests method testModifyItemNotificationActiveFolder.

@Test
public void testModifyItemNotificationActiveFolder() throws Exception {
    String folderName = "testNotificationsActiveFolder-folder";
    String subject = "testNotificationsActiveFolder-msg1";
    String tagName = "testNotificationsActiveFolder-tag";
    ZMailbox zmbox = TestUtil.getZMailbox(USER);
    ZFolder folder = TestUtil.createFolder(zmbox, folderName);
    ZTag tag = zmbox.createTag(tagName, Color.blue);
    String msgId = TestUtil.addMessage(zmbox, subject, folder.getId(), null);
    connection = connect();
    connection.login(PASS);
    connection.select(folderName);
    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())));
    MailboxOperation tagMessage = new MailboxOperation() {

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

        @Override
        protected String checkResult() throws Exception {
            Map<Long, MessageData> mdMap = connection.fetch("1:*", "(FLAGS)");
            if (mdMap.size() != 1) {
                return String.format("Size of map returned by fetch should be 1. Getting %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)

Example 42 with MessageData

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

the class SharedImapNotificationTests method testNotificationsActiveFolder.

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

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

        @Override
        protected String checkResult() throws Exception {
            Map<Long, MessageData> mdMap = connection.fetch("1:*", "(FLAGS)");
            if (mdMap.size() != 2) {
                return String.format("Size of map returned by fetch should be 2. Getting %d", mdMap.size());
            }
            return null;
        }
    };
    runOp(addMessage, 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 43 with MessageData

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

the class SharedImapNotificationTests method testDeleteTagNotificationCachedFolder.

@Test
public void testDeleteTagNotificationCachedFolder() throws Exception {
    String folderName1 = "TestRemoteImapNotifications-folder";
    String folderName2 = "TestRemoteImapNotifications-folder2";
    String tagName = "TestRemoteImapNotifications-tag";
    String subject = "TestRemoteImapNotifications-testMessage";
    ZMailbox zmbox = TestUtil.getZMailbox(USER);
    ZFolder folder = TestUtil.createFolder(zmbox, folderName1);
    TestUtil.createFolder(zmbox, folderName2);
    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(folderName1);
    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)));
    connection.select(folderName2);
    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(folderName1);
            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 44 with MessageData

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

the class SharedImapNotificationTests method testDeleteFolderNotificationCachedFolder.

@Test
public void testDeleteFolderNotificationCachedFolder() throws Exception {
    String folderName1 = "TestRemoteImapNotifications-folder";
    String folderName2 = "TestRemoteImapNotifications-folder2";
    String subject = "TestRemoteImapNotifications-testMessage";
    ZMailbox zmbox = TestUtil.getZMailbox(USER);
    ZFolder folder = TestUtil.createFolder(zmbox, folderName1);
    TestUtil.createFolder(zmbox, folderName2);
    TestUtil.addMessage(zmbox, subject, 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", 1, mdMap.size());
    connection.select(folderName2);
    MailboxOperation deleteFolder = new MailboxOperation() {

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

        @Override
        protected String checkResult() throws Exception {
            try {
                connection.list("", "*");
            } catch (CommandFailedException e) {
                return "should be able to connect after deleting a cached folder";
            }
            return null;
        }
    };
    runOp(deleteFolder, zmbox, folder);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) ZFolder(com.zimbra.client.ZFolder) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) Test(org.junit.Test)

Example 45 with MessageData

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

the class TestRemoteImapMultiServer method fetchBody.

private byte[] fetchBody(long uid) throws IOException {
    MessageData md = connection.uidFetch(uid, "(BODY.PEEK[])");
    assertNotNull("message not found", md);
    assertEquals(uid, md.getUid());
    Body[] bs = md.getBodySections();
    assertNotNull(bs);
    assertEquals(1, bs.length);
    return bs[0].getImapData().getBytes();
}
Also used : MessageData(com.zimbra.cs.mailclient.imap.MessageData) Body(com.zimbra.cs.mailclient.imap.Body)

Aggregations

MessageData (com.zimbra.cs.mailclient.imap.MessageData)47 Test (org.junit.Test)33 ZMailbox (com.zimbra.client.ZMailbox)28 ZFolder (com.zimbra.client.ZFolder)19 Flags (com.zimbra.cs.mailclient.imap.Flags)16 MailboxInfo (com.zimbra.cs.mailclient.imap.MailboxInfo)14 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)11 ZTag (com.zimbra.client.ZTag)10 Body (com.zimbra.cs.mailclient.imap.Body)9 BodyStructure (com.zimbra.cs.mailclient.imap.BodyStructure)8 Envelope (com.zimbra.cs.mailclient.imap.Envelope)8 Literal (com.zimbra.cs.mailclient.imap.Literal)8 IOException (java.io.IOException)8 Date (java.util.Date)8 ServiceException (com.zimbra.common.service.ServiceException)7 AppendResult (com.zimbra.cs.mailclient.imap.AppendResult)6 MailException (com.zimbra.cs.mailclient.MailException)5 RemoteServiceException (com.zimbra.common.service.RemoteServiceException)4 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)4 Atom (com.zimbra.cs.mailclient.imap.Atom)4