Search in sources :

Example 46 with MessageData

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

the class TestRemoteImapMultiServer method testListFolderContents.

@Test
public void testListFolderContents() throws IOException, ServiceException, MessagingException {
    String folderName = "TestRemoteImap-testOpenFolder";
    String subject = "TestRemoteImap-testMessage";
    ZMailbox zmbox = TestUtil.getZMailbox(USER);
    ZFolder folder = TestUtil.createFolder(zmbox, folderName);
    String msgId = TestUtil.addMessage(zmbox, subject, folder.getId(), null);
    ZMessage msg = zmbox.getMessageById(msgId);
    connection = connect(imapServer);
    connection.login(PASS);
    MailboxInfo info = connection.select(folderName);
    Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE INTERNALDATE BODY BODY[TEXT])");
    assertEquals(1, mdMap.size());
    MessageData md = mdMap.values().iterator().next();
    assertNotNull(md);
    Envelope env = md.getEnvelope();
    assertNotNull(env);
    assertEquals(msg.getSubject(), env.getSubject());
    assertEquals(msg.getDate(), md.getInternalDate().getTime());
    BodyStructure bs = md.getBodyStructure();
    assertNotNull(bs);
    assertEquals("TEXT", bs.getType());
    assertEquals("PLAIN", bs.getSubtype());
    assertNotNull(md.getBodySections());
    assertEquals(1, md.getBodySections().length);
    Body body = md.getBodySections()[0];
    assertNotNull(body);
    Literal imapData = (Literal) body.getData();
    assertEquals(MessageBuilder.DEFAULT_MESSAGE_BODY, imapData.toString());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) Literal(com.zimbra.cs.mailclient.imap.Literal) BodyStructure(com.zimbra.cs.mailclient.imap.BodyStructure) ZFolder(com.zimbra.client.ZFolder) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) Envelope(com.zimbra.cs.mailclient.imap.Envelope) Body(com.zimbra.cs.mailclient.imap.Body) Test(org.junit.Test)

Example 47 with MessageData

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

the class TestImapClient method testFetch.

@Test
public void testFetch() throws Exception {
    connect();
    login();
    MailboxInfo mb = connection.select("INBOX");
    final AtomicLong count = new AtomicLong(mb.getExists());
    connection.uidFetch("1:*", "(FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODY BODY.PEEK[])", new ResponseHandler() {

        @Override
        public void handleResponse(ImapResponse res) throws Exception {
            if (res.getCCode() != CAtom.FETCH)
                return;
            MessageData md = (MessageData) res.getData();
            assertNotNull(md);
            Envelope env = md.getEnvelope();
            assertNotNull(env);
            assertNotNull(env.getSubject());
            assertNotNull(md.getUid());
            assertTrue(md.getRfc822Size() != -1);
            assertNotNull(md.getInternalDate());
            BodyStructure bs = md.getBodyStructure();
            assertNotNull(bs);
            if (bs.isMultipart()) {
                BodyStructure[] parts = bs.getParts();
                for (BodyStructure part : parts) {
                    assertNotNull(part.getType());
                    assertNotNull(part.getSubtype());
                }
            } else {
                assertNotNull(bs.getType());
                assertNotNull(bs.getSubtype());
            }
            Body[] body = md.getBodySections();
            assertNotNull(body);
            assertEquals(1, body.length);
            // assertNotNull(body[0].getBytes());
            count.decrementAndGet();
            System.out.printf("Fetched uid = %s\n", md.getUid());
        }
    });
    assertEquals(0, count.longValue());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ResponseHandler(com.zimbra.cs.mailclient.imap.ResponseHandler) MessageData(com.zimbra.cs.mailclient.imap.MessageData) BodyStructure(com.zimbra.cs.mailclient.imap.BodyStructure) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) ImapResponse(com.zimbra.cs.mailclient.imap.ImapResponse) Envelope(com.zimbra.cs.mailclient.imap.Envelope) MailException(com.zimbra.cs.mailclient.MailException) MessagingException(javax.mail.MessagingException) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) IOException(java.io.IOException) Test(org.junit.Test)

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