/** * @see ImapHostManager#createPrivateMailAccount */ @Override public void createPrivateMailAccount(GreenMailUser user) throws FolderException { MailFolder root = store.getMailbox(USER_NAMESPACE); MailFolder userRoot = store.createMailbox(root, user.getQualifiedMailboxName(), false); store.createMailbox(userRoot, INBOX_NAME, true); }
/** * @see ImapHostManager#deleteMailbox */ @Override public void deleteMailbox(GreenMailUser user, String mailboxName) throws FolderException, AuthorizationException { MailFolder toDelete = getFolder(user, mailboxName, true); if (store.getChildren(toDelete).isEmpty()) { toDelete.deleteAllMessages(); toDelete.signalDeletion(); store.deleteMailbox(toDelete); } else { if (toDelete.isSelectable()) { toDelete.deleteAllMessages(); store.setSelectable(toDelete, false); } else { throw new FolderException("Can't delete a non-selectable store with children."); } } }
@Override public List<StoredMessage> getAllMessages() { List<StoredMessage> ret = new ArrayList<>(); try { Collection<MailFolder> boxes = store.listMailboxes("*"); for (MailFolder boxe : boxes) { ret.addAll(boxe.getMessages()); } } catch (FolderException e) { throw new IllegalStateException(e); } return ret; }
@Override protected void doProcess(final ImapRequestLineReader request, final ImapResponse response, final ImapSession session) throws ProtocolException, FolderException, AuthorizationException { if(!session.getHost().getStore().isQuotaSupported()) { response.commandFailed(this,"Quota is not supported. Activate quota capability first"); } String root = parser.mailbox(request); // NAME root (name usage limit) Quota[] quota = session.getHost().getStore().getQuota( root, session.getUser().getQualifiedMailboxName()); for(Quota q: quota) { StringBuilder buf = new StringBuilder(); appendQuota(q, buf); response.untaggedResponse(buf.toString()); } response.commandComplete(this); }
@Override protected void doProcess(final ImapRequestLineReader request, final ImapResponse response, final ImapSession session) { if(!session.getHost().getStore().isQuotaSupported()) { response.commandFailed(this,"Quota is not supported. Activate quota capability first"); } try { String root = parser.mailbox(request); Quota quota = new Quota(root); parser.consumeChar(request, ' '); parser.consumeChar(request, '('); quota.setResourceLimit(parser.astring(request), parser.consumeLong(request)); char c =request.nextWordChar(); if(')' != c) { quota.setResourceLimit(parser.astring(request), parser.consumeLong(request)); } parser.consumeChar(request, ')'); session.getHost().getStore().setQuota( quota, session.getUser().getQualifiedMailboxName()); response.commandComplete(this); } catch (ProtocolException e) { response.commandFailed(this, "Can not parse command"+e.getMessage()); } } }
@Override public void setQuotaSupported(boolean isEnabled) { managers.getImapHostManager().getStore().setQuotaSupported(isEnabled); }
/** * @see ImapHostManager#getFolder */ @Override public MailFolder getFolder(GreenMailUser user, String mailboxName) { String name = getQualifiedMailboxName(user, mailboxName); MailFolder folder = store.getMailbox(name); return checkViewable(folder); }
/** * @see ImapHostManager#renameMailbox */ @Override public void renameMailbox(GreenMailUser user, String oldMailboxName, String newMailboxName) throws FolderException, AuthorizationException { MailFolder existingFolder = getFolder(user, oldMailboxName, true); // TODO: check permissions. // Handle case where existing is INBOX // - just create new folder, move all messages, // and leave INBOX (with children) intact. String userInboxName = getQualifiedMailboxName(user, INBOX_NAME); if (userInboxName.equals(existingFolder.getFullName())) { MailFolder newBox = createMailbox(user, newMailboxName); long[] uids = existingFolder.getMessageUids(); for (long uid : uids) { existingFolder.copyMessage(uid, newBox); } existingFolder.deleteAllMessages(); return; } store.renameMailbox(existingFolder, newMailboxName); }
/** * @see CommandTemplate#doProcess */ @Override protected void doProcess(ImapRequestLineReader request, ImapResponse response, ImapSession session) throws ProtocolException, FolderException { parser.endLine(request); if( session.getHost().getStore().isQuotaSupported()) { response.untaggedResponse(CAPABILITY_RESPONSE + SP + "QUOTA"); } else { response.untaggedResponse(CAPABILITY_RESPONSE); } session.unsolicitedResponses(response); response.commandComplete(this); } }
@Override protected void doProcess(final ImapRequestLineReader request, final ImapResponse response, final ImapSession session) throws ProtocolException, FolderException, AuthorizationException { if(!session.getHost().getStore().isQuotaSupported()) { response.commandFailed(this,"Quota is not supported. Activate quota capability first"); } String root = parser.mailbox(request); // QUOTAROOT mailbox Quota[] quota = session.getHost().getStore().getQuota( root, session.getUser().getQualifiedMailboxName()); StringBuilder buf = new StringBuilder("QUOTAROOT "); buf.append(root); for (Quota q : quota) { buf.append(' '); appendQuotaRootName(q, buf); } response.untaggedResponse("QUOTAROOT "+root); for (Quota q : quota) { buf = new StringBuilder(); appendQuota(q, buf); response.untaggedResponse(buf.toString()); } response.commandComplete(this); } }
throws AuthorizationException, FolderException { String qualifiedName = getQualifiedMailboxName(user, mailboxName); if (store.getMailbox(qualifiedName) != null) { throw new FolderException("Mailbox already exists."); MailFolder folder = store.getMailbox(namespaceRoot); if (folder == null) { throw new FolderException("Invalid namespace " + namespaceRoot); MailFolder child = store.getMailbox(folder, childName); child = store.createMailbox(folder, childName, makeSelectable);
/** * Partial implementation of list functionality. * TODO: Handle wildcards anywhere in store pattern * (currently only supported as last character of pattern) * * @see com.icegreen.greenmail.imap.ImapHostManager#listMailboxes */ private Collection<MailFolder> listMailboxes(GreenMailUser user, String mailboxPattern, boolean subscribedOnly) throws FolderException { List<MailFolder> mailboxes = new ArrayList<>(); String qualifiedPattern = getQualifiedMailboxName(user, mailboxPattern); for (MailFolder folder : store.listMailboxes(qualifiedPattern)) { // TODO check subscriptions. if (subscribedOnly && !subscriptions.isSubscribed(user, folder)) { // if not subscribed folder = null; } // Sets the store to null if it's not viewable. folder = checkViewable(folder); if (folder != null) { mailboxes.add(folder); } } return mailboxes; }