@Override
    public MailFolder createMailbox(GreenMailUser user, String mailboxName)
            throws AuthorizationException, FolderException {
        String qualifiedName = getQualifiedMailboxName(user, mailboxName);
        if (store.getMailbox(qualifiedName) != null) {
            throw new FolderException("Mailbox already exists.");
        }

        StringTokenizer tokens = new StringTokenizer(qualifiedName,
                HIERARCHY_DELIMITER);

        if (tokens.countTokens() < 2) {
            throw new FolderException("Cannot create store at namespace level.");
        }

        String namespaceRoot = tokens.nextToken();
        MailFolder folder = store.getMailbox(namespaceRoot);
        if (folder == null) {
            throw new FolderException("Invalid namespace " + namespaceRoot);
        }

        while (tokens.hasMoreTokens()) {
            // Get the next name from the list, and find the child
            String childName = tokens.nextToken();
            MailFolder child = store.getMailbox(folder, childName);
            // Create if neccessary
            if (child == null) {
                // TODO check permissions.
                boolean makeSelectable = !tokens.hasMoreTokens();
                child = store.createMailbox(folder, childName, makeSelectable);
            }
            folder = child;
        }

        return folder;
    }
@ Override public MailFolder createMailbox ( GreenMailUser user , String mailboxName ) throws AuthorizationException , FolderException { String qualifiedName = getQualifiedMailboxName ( user , mailboxName ) ; if ( store . getMailbox ( qualifiedName ) != null ) { throw new FolderException ( "Mailbox already exists." ) ; } StringTokenizer tokens = new StringTokenizer ( qualifiedName , HIERARCHY_DELIMITER ) ; if ( tokens . countTokens ( ) < 2 ) { throw new FolderException ( "Cannot create store at namespace level." ) ; } String namespaceRoot = tokens . nextToken ( ) ; MailFolder folder = store . getMailbox ( namespaceRoot ) ; if ( folder == null ) { throw new FolderException ( "Invalid namespace " + namespaceRoot ) ; } while ( tokens . hasMoreTokens ( ) ) { String childName = tokens . nextToken ( ) ; MailFolder child = store . getMailbox ( folder , childName ) ; if ( child == null ) { boolean makeSelectable = ! tokens . hasMoreTokens ( ) ; child = store . createMailbox ( folder , childName , makeSelectable ) ; } folder = child ; } return folder ; }
@see ImapHostManager#createMailbox