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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to