Search in sources :

Example 11 with ListData

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

the class TestImap method testMailfoldersOnlyList.

@Test
public void testMailfoldersOnlyList() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER);
    String folderName = "newfolder1";
    ZFolder folder = mbox.createFolder(Mailbox.ID_FOLDER_USER_ROOT + "", folderName, ZFolder.View.unknown, ZFolder.Color.DEFAULTCOLOR, null, null);
    Provisioning.getInstance().getLocalServer().setImapDisplayMailFoldersOnly(true);
    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;
    boolean hasUnknown = 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("newfolder1"))) {
            hasUnknown = 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;
        }
    }
    assertFalse("MailonlyfolderList * contains chats", hasChats);
    assertFalse("MailonlyfolderList * contains contacts", hasContacts);
    assertFalse("MailonlyfolderList * contains emailed contacts", hasEmailedContacts);
    assertTrue("MailonlyfolderList * contains Trash", hasTrash);
    assertTrue("MailonlyfolderList * contains Drafts ", hasDrafts);
    assertTrue("MailonlyfolderList * contains Inbox", hasInbox);
    assertTrue("MailonlyfolderList * contains Sent", hasSent);
    assertTrue("MailonlyfolderList * contains Junk", hasJunk);
    assertTrue("MailonlyfolderList * contains unknown sub folders", hasUnknown);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) ListData(com.zimbra.cs.mailclient.imap.ListData) Test(org.junit.Test)

Example 12 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 13 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 14 with ListData

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

the class ImapUtilTest method testSortFolders.

@Test
public void testSortFolders() {
    List<ListData> result = ImapUtil.sortFolders(this.folders);
    // dup of "INBOX"
    Assert.assertEquals(result.size(), this.folders.size() - 1);
    this.folders.add(new ListData("INbox/t/a", '/'));
    this.folders.add(new ListData("INBox/t/a", '/'));
    result = ImapUtil.sortFolders(this.folders);
    Assert.assertEquals(result.size(), this.folders.size() - 1);
    folders.add(new ListData("INBox/T/a", '/'));
    folders.add(new ListData("INBox/T/A", '/'));
    result = ImapUtil.sortFolders(this.folders);
    Assert.assertEquals(result.size(), this.folders.size() - 1);
}
Also used : ListData(com.zimbra.cs.mailclient.imap.ListData) Test(org.junit.Test)

Example 15 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)19 Test (org.junit.Test)13 ZMailbox (com.zimbra.client.ZMailbox)6 ZFolder (com.zimbra.client.ZFolder)2 ServiceException (com.zimbra.common.service.ServiceException)2 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ZGetInfoResult (com.zimbra.client.ZGetInfoResult)1 ZSearchFolder (com.zimbra.client.ZSearchFolder)1 RemoteServiceException (com.zimbra.common.service.RemoteServiceException)1 AuthTokenException (com.zimbra.cs.account.AuthTokenException)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 Envelope (com.zimbra.cs.mailclient.imap.Envelope)1 ImapInputStream (com.zimbra.cs.mailclient.imap.ImapInputStream)1 MessageData (com.zimbra.cs.mailclient.imap.MessageData)1 AuthProviderException (com.zimbra.cs.service.AuthProviderException)1 Method (java.lang.reflect.Method)1 TimeoutException (java.util.concurrent.TimeoutException)1 MessagingException (javax.mail.MessagingException)1