/** * Hack constructor which creates an in-memory store, and creates a console logger. */ public ImapHostManagerImpl() { store = new InMemoryStore(); subscriptions = new MailboxSubscriptions(); }
private void addAllChildren(HierarchicalFolder mailbox, Collection<MailFolder> mailboxes) { Collection<HierarchicalFolder> children = mailbox.getChildren(); for (HierarchicalFolder child : children) { mailboxes.add(child); addAllChildren(child, mailboxes); } }
private void updateQuotas(final Set<Quota> quotas, final String qualifiedRootPrefix) { for (Quota q : quotas) { updateQuota(q, qualifiedRootPrefix); } }
HierarchicalFolder parent = (HierarchicalFolder) getMailbox(parentName); addAllChildren(child, mailboxes); MailFolder folder = getMailbox(searchPattern); if (folder != null) { mailboxes.add(folder);
@Override public Quota[] getQuota(final String root, final String qualifiedRootPrefix) { Set<String> rootPaths = new HashSet<>(); if (!root.contains(ImapConstants.HIERARCHY_DELIMITER)) { rootPaths.add(qualifiedRootPrefix + root); } else { for (String r : root.split(ImapConstants.HIERARCHY_DELIMITER)) { rootPaths.add(qualifiedRootPrefix + r); } } rootPaths.add(qualifiedRootPrefix); // Add default root Set<Quota> collectedQuotas = new HashSet<>(); for (String p : rootPaths) { Set<Quota> quotas = quotaMap.get(p); if (null != quotas) { collectedQuotas.addAll(quotas); } } updateQuotas(collectedQuotas, qualifiedRootPrefix); return collectedQuotas.toArray(new Quota[collectedQuotas.size()]); }
private HierarchicalFolder getInboxOrUserRootFolder(HierarchicalFolder folder) { final HierarchicalFolder inboxFolder = findParentByName(folder, ImapConstants.INBOX_NAME); if(null==inboxFolder) { return folder.getParent(); } return inboxFolder.getParent(); }
private void updateQuota(final Quota quota, final String pQualifiedRootPrefix) { MailFolder folder = getMailbox( ImapConstants.USER_NAMESPACE + ImapConstants.HIERARCHY_DELIMITER + pQualifiedRootPrefix + ImapConstants.HIERARCHY_DELIMITER + quota.quotaRoot); try { for (Quota.Resource r : quota.resources) { if (STORAGE.equals(r.name)) { long size = 0; for (StoredMessage m : folder.getMessages()) { size += m.getMimeMessage().getSize(); } r.usage = size; } else if (MESSAGES.equals(r.name)) { r.usage = folder.getMessageCount(); } else { throw new IllegalStateException("Quota " + r.name + " not supported"); } } } catch (MessagingException ex) { throw new IllegalStateException("Can not update/verify quota " + quota, ex); } }
@Override public void purgeEmailFromAllMailboxes() throws FolderException { ImapHostManager imaphost = getManagers().getImapHostManager(); InMemoryStore store = (InMemoryStore) imaphost.getStore(); Collection<MailFolder> mailboxes = store.listMailboxes("*"); for (MailFolder folder : mailboxes) { folder.deleteAllMessages(); } }
@Override public void renameMailbox(MailFolder existingFolder, String newName) throws FolderException { HierarchicalFolder toRename = (HierarchicalFolder) existingFolder; HierarchicalFolder parent = toRename.getParent(); int idx = newName.lastIndexOf(ImapConstants.HIERARCHY_DELIMITER_CHAR); String newFolderName; String newFolderPathWithoutName; if (idx > 0) { newFolderName = newName.substring(idx + 1); newFolderPathWithoutName = newName.substring(0, idx); } else { newFolderName = newName; newFolderPathWithoutName = ""; } if (parent.getName().equals(newFolderPathWithoutName)) { // Simple rename toRename.setName(newFolderName); } else { // Hierarchy change parent.removeChild(toRename); HierarchicalFolder userFolder = getInboxOrUserRootFolder(toRename); String[] path = newName.split('\\' + ImapConstants.HIERARCHY_DELIMITER); HierarchicalFolder newParent = userFolder; for (int i = 0; i < path.length - 1; i++) { newParent = newParent.getChild(path[i]); } toRename.moveToNewParent(newParent); toRename.setName(newFolderName); } }