Search in sources :

Example 1 with FolderType

use of com.fsck.k9.mail.FolderType in project k-9 by k9mail.

the class RealImapStore method listFolders.

private List<FolderListItem> listFolders(ImapConnection connection, boolean subscribedOnly) throws IOException, MessagingException {
    String commandFormat;
    if (subscribedOnly) {
        commandFormat = "LSUB \"\" %s";
    } else if (connection.hasCapability(Capabilities.SPECIAL_USE) && connection.hasCapability(Capabilities.LIST_EXTENDED)) {
        commandFormat = "LIST \"\" %s RETURN (SPECIAL-USE)";
    } else {
        commandFormat = "LIST \"\" %s";
    }
    String encodedListPrefix = ImapUtility.encodeString(getCombinedPrefix() + "*");
    List<ImapResponse> responses = connection.executeSimpleCommand(String.format(commandFormat, encodedListPrefix));
    List<ListResponse> listResponses = (subscribedOnly) ? ListResponse.parseLsub(responses) : ListResponse.parseList(responses);
    Map<String, FolderListItem> folderMap = new HashMap<>(listResponses.size());
    for (ListResponse listResponse : listResponses) {
        String serverId = listResponse.getName();
        if (pathDelimiter == null) {
            pathDelimiter = listResponse.getHierarchyDelimiter();
            combinedPrefix = null;
        }
        if (RealImapFolder.INBOX.equalsIgnoreCase(serverId)) {
            continue;
        } else if (listResponse.hasAttribute("\\NoSelect")) {
            continue;
        }
        String name = getFolderDisplayName(serverId);
        String oldServerId = getOldServerId(serverId);
        FolderType type;
        if (listResponse.hasAttribute("\\Archive") || listResponse.hasAttribute("\\All")) {
            type = FolderType.ARCHIVE;
        } else if (listResponse.hasAttribute("\\Drafts")) {
            type = FolderType.DRAFTS;
        } else if (listResponse.hasAttribute("\\Sent")) {
            type = FolderType.SENT;
        } else if (listResponse.hasAttribute("\\Junk")) {
            type = FolderType.SPAM;
        } else if (listResponse.hasAttribute("\\Trash")) {
            type = FolderType.TRASH;
        } else {
            type = FolderType.REGULAR;
        }
        FolderListItem existingItem = folderMap.get(serverId);
        if (existingItem == null || existingItem.getType() == FolderType.REGULAR) {
            folderMap.put(serverId, new FolderListItem(serverId, name, type, oldServerId));
        }
    }
    List<FolderListItem> folders = new ArrayList<>(folderMap.size() + 1);
    folders.add(new FolderListItem(RealImapFolder.INBOX, RealImapFolder.INBOX, FolderType.INBOX, RealImapFolder.INBOX));
    folders.addAll(folderMap.values());
    return folders;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FolderType(com.fsck.k9.mail.FolderType)

Example 2 with FolderType

use of com.fsck.k9.mail.FolderType in project k-9 by k9mail.

the class WebDavStore method createFolder.

/**
 * Creates a folder using the URL passed as parameter (only if it has not been already created) and adds this to
 * our store folder map.
 */
private WebDavFolder createFolder(String folderUrl, Map<String, String> specialFoldersMap) {
    if (folderUrl == null) {
        return null;
    }
    WebDavFolder wdFolder = null;
    String folderName = getFolderName(folderUrl);
    if (folderName != null) {
        wdFolder = getFolder(folderName);
        if (wdFolder != null) {
            wdFolder.setUrl(folderUrl);
            FolderType type = getFolderType(folderName, specialFoldersMap);
            wdFolder.setType(type);
        }
    }
    return wdFolder;
}
Also used : FolderType(com.fsck.k9.mail.FolderType)

Aggregations

FolderType (com.fsck.k9.mail.FolderType)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1