Search in sources :

Example 6 with BodyStructure

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

Example 7 with BodyStructure

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

the class SharedImapTests method doCopy.

private void doCopy(ImapConnection imapConn, ZMailbox shareeZmbox, String fromFolderName, String toFolderName, String srcMsgSubject) throws IOException, ServiceException, MessagingException {
    imapConn.list("", "*");
    imapConn.create(toFolderName);
    // This loop is to create some distance between the IDs in the from and to mailboxes
    for (int cnt = 1; cnt < 10; cnt++) {
        TestUtil.addMessage(shareeZmbox, String.format("inbox msg %s", cnt));
    }
    doSelectShouldSucceed(imapConn, fromFolderName);
    CopyResult copyResult = imapConn.copy("1", toFolderName);
    assertNotNull("copyResult.getFromUids()", copyResult.getFromUids());
    assertNotNull("copyResult.getToUids()", copyResult.getToUids());
    assertEquals("Number of fromUIDs", 1, copyResult.getFromUids().length);
    assertEquals("Number of toUIDs", 1, copyResult.getToUids().length);
    MailboxInfo selectMboxInfo = imapConn.select(toFolderName);
    assertNotNull(String.format("Select result for folder=%s", toFolderName), selectMboxInfo);
    assertEquals("Select result Folder Name folder", toFolderName, selectMboxInfo.getName());
    assertEquals(String.format("Number of exists for folder=%s after copy", toFolderName), 1, selectMboxInfo.getExists());
    Map<Long, MessageData> mdMap = this.doFetchShouldSucceed(imapConn, "1:*", "(ENVELOPE)", Lists.newArrayList(srcMsgSubject));
    MessageData md = mdMap.values().iterator().next();
    assertNull("Internal date was NOT requested and should be NULL", md.getInternalDate());
    BodyStructure bs = md.getBodyStructure();
    assertNull("Body Structure was not requested and should be NULL", bs);
    Body[] body = md.getBodySections();
    assertNull("body sections were not requested and should be null", body);
}
Also used : MessageData(com.zimbra.cs.mailclient.imap.MessageData) BodyStructure(com.zimbra.cs.mailclient.imap.BodyStructure) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) Body(com.zimbra.cs.mailclient.imap.Body) CopyResult(com.zimbra.cs.mailclient.imap.CopyResult)

Example 8 with BodyStructure

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

Aggregations

BodyStructure (com.zimbra.cs.mailclient.imap.BodyStructure)8 MessageData (com.zimbra.cs.mailclient.imap.MessageData)8 Test (org.junit.Test)7 ZMailbox (com.zimbra.client.ZMailbox)6 Body (com.zimbra.cs.mailclient.imap.Body)6 Envelope (com.zimbra.cs.mailclient.imap.Envelope)6 ZFolder (com.zimbra.client.ZFolder)4 MailboxInfo (com.zimbra.cs.mailclient.imap.MailboxInfo)4 CopyResult (com.zimbra.cs.mailclient.imap.CopyResult)2 ZMessage (com.zimbra.client.ZMessage)1 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)1 MailException (com.zimbra.cs.mailclient.MailException)1 ImapResponse (com.zimbra.cs.mailclient.imap.ImapResponse)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 MessagingException (javax.mail.MessagingException)1