Search in sources :

Example 6 with Envelope

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

the class SharedImapTests method testListFolderContents.

@Test(timeout = 100000)
public void testListFolderContents() throws IOException, ServiceException, MessagingException {
    String folderName = "SharedImapTests-testOpenFolder";
    String subject = "SharedImapTests-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 INTERNALDATE BODY BODY.PEEK[])");
    assertEquals("Size of map returned by fetch", 1, mdMap.size());
    MessageData md = mdMap.values().iterator().next();
    assertNotNull("MessageData", md);
    Envelope env = md.getEnvelope();
    assertNotNull("Envelope", env);
    assertEquals("Subject from envelope is wrong", subject, env.getSubject());
    assertNotNull("Internal date was requested and should not be NULL", md.getInternalDate());
    BodyStructure bs = md.getBodyStructure();
    assertNotNull("Body Structure is null", bs);
    if (bs.isMultipart()) {
        BodyStructure[] parts = bs.getParts();
        for (BodyStructure part : parts) {
            assertNotNull("part type should not be null", part.getType());
            assertNotNull("part subType should not be null", part.getSubtype());
        }
    } else {
        assertNotNull("Body structure type", bs.getType());
        assertNotNull("Body structure sub-type", bs.getSubtype());
    }
    Body[] body = md.getBodySections();
    assertNotNull("body sections should not be null", body);
    assertEquals("expecting one body section. Got " + body.length, 1, body.length);
}
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) Body(com.zimbra.cs.mailclient.imap.Body) Test(org.junit.Test)

Example 7 with Envelope

use of com.zimbra.cs.mailclient.imap.Envelope 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 8 with Envelope

use of com.zimbra.cs.mailclient.imap.Envelope 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

Envelope (com.zimbra.cs.mailclient.imap.Envelope)8 MessageData (com.zimbra.cs.mailclient.imap.MessageData)8 Test (org.junit.Test)7 ZMailbox (com.zimbra.client.ZMailbox)6 BodyStructure (com.zimbra.cs.mailclient.imap.BodyStructure)6 ZFolder (com.zimbra.client.ZFolder)4 Body (com.zimbra.cs.mailclient.imap.Body)4 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)2 MailboxInfo (com.zimbra.cs.mailclient.imap.MailboxInfo)2 ZMessage (com.zimbra.client.ZMessage)1 ZSearchFolder (com.zimbra.client.ZSearchFolder)1 MailException (com.zimbra.cs.mailclient.MailException)1 ImapResponse (com.zimbra.cs.mailclient.imap.ImapResponse)1 ListData (com.zimbra.cs.mailclient.imap.ListData)1 Literal (com.zimbra.cs.mailclient.imap.Literal)1 ResponseHandler (com.zimbra.cs.mailclient.imap.ResponseHandler)1 VCard (com.zimbra.cs.service.formatter.VCard)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1