Search in sources :

Example 1 with BodyStructure

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

the class SharedImapTests method testListFolderContentsEnvelope.

@Test(timeout = 100000)
public void testListFolderContentsEnvelope() 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)");
    assertEquals("Size of map returned by fetch", 1, mdMap.size());
    MessageData md = mdMap.values().iterator().next();
    assertNotNull("MessageData should not be null", md);
    Envelope env = md.getEnvelope();
    assertNotNull("Envelope should not be null", env);
    assertEquals("Subject from envelope is wrong", subject, env.getSubject());
    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 : 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 2 with BodyStructure

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

the class SharedImapTests method testListContactsContents.

@Test(timeout = 100000)
public void testListContactsContents() throws IOException, ServiceException, MessagingException {
    // create a contact
    ZMailbox zmbox = TestUtil.getZMailbox(USER);
    Map<String, String> attrs = new HashMap<String, String>();
    String contactName = "testListContactsContents";
    attrs.put("fullName", contactName);
    zmbox.createContact(Integer.toString(Mailbox.ID_FOLDER_CONTACTS), null, attrs);
    // connect to IMAP
    String folderName = "Contacts";
    connection = connect();
    connection.login(PASS);
    connection.select(folderName);
    // fetch
    Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE BODY BODY.PEEK[])");
    // verify
    assertEquals("Size of map returned by fetch", 1, mdMap.size());
    MessageData md = mdMap.values().iterator().next();
    assertNotNull("MessageData should not be null", md);
    Envelope env = md.getEnvelope();
    assertNotNull("Envelope should not be null", env);
    BodyStructure bs = md.getBodyStructure();
    assertNotNull("Body Structure should not be null", bs);
    Body[] body = md.getBodySections();
    assertNotNull("body sections should not be null", body);
    assertEquals("Expecting 1 body section. Found " + body.length, 1, body.length);
    assertEquals("Envelope subject is wrong", contactName, env.getSubject());
    assertEquals("Body type should be TEXT", "TEXT", bs.getType());
    assertEquals("Body subtype should be X-VCARD", "X-VCARD", bs.getSubtype());
    // fetch one contact
    List<Long> uids = connection.getUids("1:*");
    assertNotNull("uids should not be null", uids);
    assertEquals("expecting to find 1 UID", 1, uids.size());
    byte[] b = getBody(fetchMessage(connection, uids.get(0)));
    assertNotNull("fetched body should not be null", b);
    List<VCard> cards = VCard.parseVCard(new String(b, MimeConstants.P_CHARSET_UTF8));
    assertNotNull("parsed vcards list should not be null", cards);
    assertEquals("expecting to find 1 Vcard", 1, cards.size());
    assertNotNull("parsed vcard should not be null", cards.get(0));
    assertEquals("VCArd's full name is wrong", contactName, cards.get(0).fn);
}
Also used : HashMap(java.util.HashMap) MessageData(com.zimbra.cs.mailclient.imap.MessageData) Envelope(com.zimbra.cs.mailclient.imap.Envelope) ZMailbox(com.zimbra.client.ZMailbox) BodyStructure(com.zimbra.cs.mailclient.imap.BodyStructure) Body(com.zimbra.cs.mailclient.imap.Body) VCard(com.zimbra.cs.service.formatter.VCard) Test(org.junit.Test)

Example 3 with BodyStructure

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

the class SharedImapNotificationTests method testDeleteMessageNotificationActiveFolder.

@Test
public void testDeleteMessageNotificationActiveFolder() throws Exception {
    String folderName1 = "TestRemoteImapNotifications-folder";
    String subject1 = "TestRemoteImapNotifications-testMessage1";
    String subject2 = "TestRemoteImapNotifications-testMessage2";
    ZMailbox zmbox = TestUtil.getZMailbox(USER);
    ZFolder folder = TestUtil.createFolder(zmbox, folderName1);
    String msgId = TestUtil.addMessage(zmbox, subject1, folder.getId(), null);
    TestUtil.addMessage(zmbox, subject2, 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", 2, mdMap.size());
    MailboxOperation deleteMessage = new MailboxOperation() {

        @Override
        protected void run(ZMailbox zmbox) throws Exception {
            zmbox.deleteMessage(msgId);
        }

        @Override
        protected String checkResult() throws Exception {
            Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE BODY)");
            assertEquals("Size of map returned by fetch 2", 2, mdMap.size());
            MessageData md = mdMap.get(1L);
            // verify that the deleted message has a NIL response
            Envelope envelope = md.getEnvelope();
            if (envelope == null) {
                return "Envelope should not be NULL";
            }
            if (envelope.getSubject() != null) {
                return "Envelope::subject should be NULL";
            }
            BodyStructure bs = md.getBodyStructure();
            if (bs.getSize() != 0) {
                return "BodyStructure::geSize should return 0";
            }
            // verify that the second message is correct
            md = mdMap.get(2L);
            if (!subject2.equals(md.getEnvelope().getSubject())) {
                return String.format("Subject should be %s. Getting %d", subject2, md.getEnvelope().getSubject());
            }
            connection.expunge();
            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());
            }
            return null;
        }
    };
    runOp(deleteMessage, zmbox, folder);
}
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) Test(org.junit.Test)

Example 4 with BodyStructure

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

the class SharedImapTests method copyToMountpoint.

@Test(timeout = 100000)
public void copyToMountpoint() throws Exception {
    TestUtil.createAccount(SHAREE);
    ZMailbox userZmbox = TestUtil.getZMailbox(USER);
    ZMailbox shareeZmbox = TestUtil.getZMailbox(SHAREE);
    String sharedFolder = "INBOX/share";
    String mountpoint = String.format("shared-", testInfo.getMethodName());
    String subject = "SharedImapTests-testMessage";
    TestUtil.createMountpoint(userZmbox, "/" + sharedFolder, shareeZmbox, mountpoint);
    TestUtil.addMessage(shareeZmbox, subject, Integer.toString(Mailbox.ID_FOLDER_INBOX), null);
    connection = connectAndSelectInbox(SHAREE);
    CopyResult copyResult = connection.copy("1", mountpoint);
    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 = connection.select(mountpoint);
    assertNotNull(String.format("Select result for folder=%s", mountpoint), selectMboxInfo);
    assertEquals("Select result Folder Name folder", mountpoint, selectMboxInfo.getName());
    assertEquals(String.format("Number of exists for folder=%s after copy", mountpoint), 1, selectMboxInfo.getExists());
    Map<Long, MessageData> mdMap = this.doFetchShouldSucceed(connection, "1:*", "(ENVELOPE)", Lists.newArrayList(subject));
    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 : ZMailbox(com.zimbra.client.ZMailbox) 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) Test(org.junit.Test)

Example 5 with BodyStructure

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

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