You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by "woj-tek (via GitHub)" <gi...@apache.org> on 2023/03/13 19:57:47 UTC

[GitHub] [james-project] woj-tek commented on a diff in pull request #1476: JAMES-3895 Automatically provision default (IMAP) mailboxes

woj-tek commented on code in PR #1476:
URL: https://github.com/apache/james-project/pull/1476#discussion_r1134553367


##########
protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractAuthProcessor.java:
##########
@@ -137,17 +147,29 @@ protected void provisionInbox(ImapSession session, MailboxManager mailboxManager
         if (Mono.from(mailboxManager.mailboxExists(inboxPath, mailboxSession)).block()) {
             LOGGER.debug("INBOX exists. No need to create it.");
         } else {
-            try {
-                mailboxManager.createMailbox(inboxPath, MailboxManager.CreateOption.CREATE_SUBSCRIPTION, mailboxSession)
-                    .ifPresentOrElse(
-                        id -> LOGGER.info("Provisioning INBOX. {} created.", id),
-                        () -> LOGGER.warn("Provisioning INBOX successful. But no MailboxId have been returned."));
-            } catch (MailboxExistsException e) {
-                LOGGER.warn("Mailbox INBOX created by concurrent call. Safe to ignore this exception.");
+            provisionMailbox(DefaultMailboxes.INBOX, session, mailboxManager, mailboxSession);
+            if (imapConfiguration.isProvisionDefaultMailboxes()) {
+                for (String mailbox : DefaultMailboxes.DEFAULT_MAILBOXES) {
+                    provisionMailbox(mailbox, session, mailboxManager, mailboxSession);
+                }
             }
         }
     }
 
+    private void provisionMailbox(String mailbox, ImapSession session, MailboxManager mailboxManager,
+                                  MailboxSession mailboxSession) throws MailboxException {
+        var mailboxPath = PathConverter.forSession(session).buildFullPath(mailbox);
+        try {
+            mailboxManager.createMailbox(mailboxPath, MailboxManager.CreateOption.CREATE_SUBSCRIPTION, mailboxSession)
+                    .ifPresentOrElse(id -> LOGGER.info("Provisioning mailbox {}. {} created.", mailbox, id),
+                                     () -> LOGGER.warn(
+                                             "Provisioning mailbox {} successful. But no MailboxId have been returned.",
+                                             mailbox));
+        } catch (MailboxExistsException e) {
+            LOGGER.warn("Mailbox {} created by concurrent call. Safe to ignore this exception.", mailbox);
+        }

Review Comment:
   I pushed the change with the checking. Opted to repeat the check to keep it simple as it would most likely be run only once per account.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org