Search in sources :

Example 6 with ListData

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

the class TestImapClient method testList.

@Test
public void testList() throws Exception {
    login();
    List<ListData> lds = connection.list("", "*");
    for (ListData ld : lds) {
        assertEquals('/', ld.getDelimiter());
        assertNotNull(ld.getMailbox());
        assertTrue(ld.getFlags().size() > 0);
    }
}
Also used : ListData(com.zimbra.cs.mailclient.imap.ListData) Test(org.junit.Test)

Example 7 with ListData

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

the class TestImapUtil method parseFolders.

private List<ListData> parseFolders(String[] folders) throws IOException {
    List<ListData> lds = new ArrayList<ListData>();
    ImapInputStream is = getImapInputStream(folders);
    while (!is.isEOF()) {
        is.skipChar('*');
        is.skipChar(' ');
        is.readAtom();
        is.skipChar(' ');
        lds.add(ListData.read(is));
        is.skipCRLF();
    }
    return lds;
}
Also used : ArrayList(java.util.ArrayList) ImapInputStream(com.zimbra.cs.mailclient.imap.ImapInputStream) ListData(com.zimbra.cs.mailclient.imap.ListData)

Example 8 with ListData

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

the class TestImap method testFoldersList.

@Test
public void testFoldersList() throws Exception {
    List<ListData> listResult = connection.list("", "*");
    assertNotNull(listResult);
    assertTrue("List result should have atleast 5  entries", listResult.size() >= 5);
    boolean hasContacts = false;
    boolean hasChats = false;
    boolean hasEmailedContacts = false;
    boolean hasTrash = false;
    boolean hasDrafts = false;
    boolean hasInbox = false;
    boolean hasJunk = false;
    boolean hasSent = false;
    for (ListData ld : listResult) {
        if ((ld.getMailbox().equalsIgnoreCase("Contacts"))) {
            hasContacts = true;
        } else if ((ld.getMailbox().equalsIgnoreCase("Chats"))) {
            hasChats = true;
        } else if ((ld.getMailbox().equalsIgnoreCase("Emailed Contacts"))) {
            hasEmailedContacts = true;
        } else if ((ld.getMailbox().equalsIgnoreCase("Trash"))) {
            hasTrash = true;
        } else if ((ld.getMailbox().equalsIgnoreCase("Drafts"))) {
            hasDrafts = true;
        } else if ((ld.getMailbox().equalsIgnoreCase("Inbox"))) {
            hasInbox = true;
        } else if ((ld.getMailbox().equalsIgnoreCase("Sent"))) {
            hasSent = true;
        } else if ((ld.getMailbox().equalsIgnoreCase("Junk"))) {
            hasJunk = true;
        }
    }
    assertTrue("folderList * contains chats", hasChats);
    assertTrue("folderList * contains contacts", hasContacts);
    assertTrue("folderList * contains emailed contacts", hasEmailedContacts);
    assertTrue("folderList * contains Trash", hasTrash);
    assertTrue("folderList * contains Drafts ", hasDrafts);
    assertTrue("folderList * contains Inbox", hasInbox);
    assertTrue("folderList * contains Sent", hasSent);
    assertTrue("folderList * contains Junk", hasJunk);
}
Also used : ListData(com.zimbra.cs.mailclient.imap.ListData) Test(org.junit.Test)

Example 9 with ListData

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

the class TestImap method testListContacts.

@Test
public void testListContacts() throws Exception {
    List<ListData> listResult = connection.list("", "*Contacts*");
    assertNotNull(listResult);
    // 'Contacts' and 'Emailed Contacts'
    assertTrue("List result should have at least 2 entries", listResult.size() >= 2);
    for (ListData le : listResult) {
        assertTrue(String.format("mailbox '%s' contains 'Contacts'", le.getMailbox()), le.getMailbox().contains("Contacts"));
    }
}
Also used : ListData(com.zimbra.cs.mailclient.imap.ListData) Test(org.junit.Test)

Example 10 with ListData

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

the class ImapUtil method sortFolders.

public static List<ListData> sortFolders(List<ListData> folders) {
    // Keep INBOX and inferiors separate so we can return them first
    ListData inbox = null;
    ListData defaultInbox = null;
    List<ListData> inboxInferiors = new ArrayList<ListData>();
    List<ListData> otherFolders = new ArrayList<ListData>();
    for (ListData ld : folders) {
        if (INBOX.equalsIgnoreCase(ld.getMailbox())) {
            //rfc3501(5.1), INBOX is case-insensitive
            if (inbox == null) {
                // Ignore duplicate INBOX (fixes bug 26483)
                inbox = ld;
            }
        } else if (isInboxInferior(ld)) {
            inboxInferiors.add(ld);
            if (defaultInbox == null) {
                defaultInbox = new ListData(INBOX, ld.getDelimiter());
            }
        } else {
            otherFolders.add(ld);
        }
    }
    List<ListData> sorted = new ArrayList<ListData>(folders.size());
    if (inbox == null) {
        // If INBOX missing from LIST response, then see if we can
        // determine a reasonable default (bug 30844).
        inbox = defaultInbox;
    }
    if (inbox != null) {
        sorted.add(inbox);
    }
    Collections.sort(inboxInferiors, COMPARATOR);
    sorted.addAll(inboxInferiors);
    Collections.sort(otherFolders, COMPARATOR);
    sorted.addAll(otherFolders);
    return sorted;
}
Also used : ArrayList(java.util.ArrayList) ListData(com.zimbra.cs.mailclient.imap.ListData)

Aggregations

ListData (com.zimbra.cs.mailclient.imap.ListData)10 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)2 ZFolder (com.zimbra.client.ZFolder)1 ZMailbox (com.zimbra.client.ZMailbox)1 RemoteServiceException (com.zimbra.common.service.RemoteServiceException)1 ServiceException (com.zimbra.common.service.ServiceException)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)1 ImapInputStream (com.zimbra.cs.mailclient.imap.ImapInputStream)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 Before (org.junit.Before)1