This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 810dca40cddb0cb59622e82dd6b9e5ad52fa6a36 Author: Benoit Tellier <[email protected]> AuthorDate: Wed May 6 13:55:48 2020 +0700 [Refactoring] Slightly enhance MaildirMailboxMapper::visitUsersForMailboxList - Method extraction - Use of MailboxPath::forUser --- .../mailbox/maildir/mail/MaildirMailboxMapper.java | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java index f5af09c..b0f2238 100644 --- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java +++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java @@ -280,15 +280,10 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail private List<Mailbox> visitUsersForMailboxList(File domain, File[] users) throws MailboxException { ImmutableList.Builder<Mailbox> mailboxList = ImmutableList.builder(); - String userName = null; for (File user: users) { - if (domain == null) { - userName = user.getName(); - } else { - userName = user.getName() + "@" + domain.getName(); - } - + String userName = retrieveUsername(domain, user); + // Special case for INBOX: Let's use the user's folder. MailboxPath inboxMailboxPath = MailboxPath.forUser(Username.of(userName), MailboxConstants.INBOX); @@ -297,21 +292,27 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail } catch (MailboxException e) { //do nothing, we should still be able to list the mailboxes even if INBOX does not exist } - // List all INBOX sub folders. File[] mailboxes = user.listFiles(pathname -> pathname.getName().startsWith(".")); for (File mailbox: mailboxes) { - MailboxPath mailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, - Username.of(userName), - mailbox.getName().substring(1)); + MailboxPath mailboxPath = MailboxPath.forUser(Username.of(userName), + mailbox.getName().substring(1)); mailboxList.add(maildirStore.loadMailbox(session, mailboxPath)); } } return mailboxList.build(); } + private String retrieveUsername(File domain, File user) { + if (domain == null) { + return user.getName(); + } else { + return user.getName() + "@" + domain.getName(); + } + } + @Override public ACLDiff updateACL(Mailbox mailbox, MailboxACL.ACLCommand mailboxACLCommand) throws MailboxException { MaildirFolder folder = maildirStore.createMaildirFolder(mailbox); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
