Search in sources :

Example 21 with MessageData

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

the class SharedImapNotificationTests method testDeleteFolderNotificationActiveFolder.

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

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

        @Override
        protected String checkResult() throws Exception {
            try {
                connection.fetch("1:*", "(ENVELOPE BODY)");
                return "should not be able to connect; connection should be closed";
            }// connection is force closed
             catch (SocketException | CommandFailedException e) {
            }
            return null;
        }
    };
    runOp(deleteFolder, zmbox, folder);
}
Also used : SocketException(java.net.SocketException) 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 22 with MessageData

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

the class SharedImapNotificationTests method testNotificationsEmptyActiveFolder.

@Test
public void testNotificationsEmptyActiveFolder() throws Exception {
    String folderName = "testNotificationsEmptyActiveFolder-folder";
    String subject1 = "testNotificationsEmptyActiveFolder-msg";
    ZMailbox zmbox = TestUtil.getZMailbox(USER);
    ZFolder folder = TestUtil.createFolder(zmbox, folderName);
    connection = connect();
    connection.login(PASS);
    connection.select(folderName);
    MailboxOperation addMessage = new MailboxOperation() {

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

        @Override
        protected String checkResult() throws Exception {
            try {
                Map<Long, MessageData> 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());
                }
            } catch (CommandFailedException cfe) {
                return cfe.getError();
            }
            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) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) Test(org.junit.Test)

Example 23 with MessageData

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

the class ImapTestBase method fetchMessage.

protected MessageData fetchMessage(ImapConnection conn, long uid) throws IOException {
    checkConnection(conn);
    MessageData md = conn.uidFetch(uid, "(FLAGS BODY.PEEK[])");
    assertNotNull(String.format("`UID FETCH %s (FLAGS BODY.PEEK[])` returned no data - assume message not found", uid), md);
    assertEquals(String.format("`UID FETCH %s (FLAGS BODY.PEEK[])` returned wrong UID", uid), uid, md.getUid());
    return md;
}
Also used : MessageData(com.zimbra.cs.mailclient.imap.MessageData)

Example 24 with MessageData

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

the class TestImapClient method testAppend.

@Test
public void testAppend() throws Exception {
    login();
    MailboxInfo mb = connection.select("INBOX");
    long exists = mb.getExists();
    Date date = new Date((System.currentTimeMillis() / 1000) * 1000);
    Flags flags = Flags.fromSpec("fs");
    AppendResult res = connection.append("INBOX", Flags.fromSpec("fs"), date, new Literal(Ascii.getBytes(MESSAGE)));
    assertNotNull(res);
    mb = connection.select("INBOX");
    assertEquals(1, mb.getExists() - exists);
    MessageData md = connection.uidFetch(res.getUid(), "(FLAGS BODY.PEEK[] INTERNALDATE)");
    assertNotNull(md);
    assertEquals(date, md.getInternalDate());
    assertEquals(res.getUid(), md.getUid());
    assertEquals(flags, md.getFlags());
    Body[] parts = md.getBodySections();
    assertNotNull(parts);
    assertEquals(1, parts.length);
}
Also used : MessageData(com.zimbra.cs.mailclient.imap.MessageData) Literal(com.zimbra.cs.mailclient.imap.Literal) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) Flags(com.zimbra.cs.mailclient.imap.Flags) Body(com.zimbra.cs.mailclient.imap.Body) Date(java.util.Date) Test(org.junit.Test)

Example 25 with MessageData

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

the class TestImap 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