Search in sources :

Example 1 with Envelope

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

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

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

the class SharedImapTests method savedSearch.

@Test(timeout = 100000)
public void savedSearch() throws ServiceException, IOException, MessagingException {
    ZMailbox mbox = TestUtil.getZMailbox(USER);
    String subjectPrefix = String.format("%s test message ", testId);
    TestUtil.addMessage(mbox, subjectPrefix + "1", ZFolder.ID_INBOX);
    TestUtil.addMessage(mbox, subjectPrefix + "2", ZFolder.ID_DRAFTS);
    TestUtil.addMessage(mbox, subjectPrefix + "3 - does not match search", ZFolder.ID_SENT);
    String folderName = "searchFolderInDraftsOrInOnbox";
    ZSearchFolder srchFolder = mbox.createSearchFolder(ZFolder.ID_USER_ROOT, folderName, "in:drafts or in:inbox", ZSearchParams.TYPE_CONVERSATION, SearchSortBy.nameAsc, ZFolder.Color.ORANGE);
    assertNotNull("SearchFolder in Response to CreateSearchFolderRequest should not be null", srchFolder);
    connection = this.connectAndLogin(USER);
    List<ListData> listResult;
    // LIST "" "mountpointName"
    doListShouldSucceed(connection, "", folderName, Lists.newArrayList(folderName), "Just search folder");
    listResult = connection.list("", "*");
    assertNotNull("list result 'list \"\" \"*\"' should not be null", listResult);
    boolean seenIt = false;
    for (ListData listEnt : listResult) {
        if (folderName.equals(listEnt.getMailbox())) {
            seenIt = true;
            break;
        }
    }
    assertTrue(String.format("'%s' mailbox not in result of 'list \"\" \"*\"'", folderName), seenIt);
    connection.select(folderName);
    Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE)");
    assertEquals("Size of map returned by fetch", 2, mdMap.size());
    Iterator<MessageData> iter = mdMap.values().iterator();
    while (iter.hasNext()) {
        MessageData md = iter.next();
        assertNotNull("MessageData", md);
        Envelope env = md.getEnvelope();
        assertNotNull("Envelope", env);
        assertTrue(String.format("Message subject was '%s' expected to contain '%s'", env.getSubject(), subjectPrefix), env.getSubject().contains(subjectPrefix));
    }
    connection.logout();
    connection = null;
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) Envelope(com.zimbra.cs.mailclient.imap.Envelope) ZSearchFolder(com.zimbra.client.ZSearchFolder) ListData(com.zimbra.cs.mailclient.imap.ListData) Test(org.junit.Test)

Example 4 with Envelope

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

the class ImapTestBase method doFetchShouldSucceed.

protected Map<Long, MessageData> doFetchShouldSucceed(ImapConnection conn, String range, String what, List<String> expectedSubjects) throws IOException {
    checkConnection(conn);
    try {
        Map<Long, MessageData> mdMap = conn.fetch(range, what);
        assertNotNull(String.format("map returned by 'FETCH %s %s' should not be null", range, what), mdMap);
        assertEquals(String.format("Size of map returned by 'FETCH %s %s'", range, what), expectedSubjects.size(), mdMap.size());
        int cnt = 0;
        Iterator<MessageData> iter = mdMap.values().iterator();
        while (iter.hasNext()) {
            MessageData md = iter.next();
            assertNotNull("MessageData should not be null", md);
            Envelope env = md.getEnvelope();
            assertNotNull(String.format("Envelope for MessageData for %s item in results of 'FETCH %s %s' should not be null", cnt, range, what), env);
            assertEquals(String.format("Subject for %s item in results of 'FETCH %s %s'", cnt, range, what), expectedSubjects.get(cnt), env.getSubject());
            cnt++;
        }
        return mdMap;
    } catch (CommandFailedException cfe) {
        fail(String.format("'FETCH %s %s' failed with '%s'", range, what, cfe.getError()));
        return null;
    }
}
Also used : MessageData(com.zimbra.cs.mailclient.imap.MessageData) Envelope(com.zimbra.cs.mailclient.imap.Envelope) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException)

Example 5 with Envelope

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

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