PROTOCOLS-117 MailboxPath creation SHOULD NOT be dynamic
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/48d7caf6 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/48d7caf6 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/48d7caf6 Branch: refs/heads/master Commit: 48d7caf604ca9090ba9253689b4b5b5f5d5c356c Parents: 9047b4b Author: benwa <btell...@linagora.com> Authored: Wed Nov 8 16:42:42 2017 +0700 Committer: Antoine Duprat <adup...@linagora.com> Committed: Mon Nov 13 16:23:06 2017 +0100 ---------------------------------------------------------------------- .../java/org/apache/james/mailbox/model/MailboxPath.java | 3 +-- .../james/mailbox/maildir/mail/MaildirMailboxMapper.java | 2 +- .../org/apache/james/imap/processor/CopyProcessorTest.java | 9 +++------ .../org/apache/james/imap/processor/MoveProcessorTest.java | 9 +++------ .../james/transport/mailets/delivery/MailboxAppender.java | 4 ++-- .../james/jmap/DefaultMailboxesProvisioningFilter.java | 2 +- .../james/jmap/methods/SetMailboxesCreationProcessor.java | 6 ++++-- .../james/jmap/methods/SetMailboxesUpdateProcessor.java | 6 +++--- .../apache/james/webadmin/service/UserMailboxesService.java | 2 +- 9 files changed, 19 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/48d7caf6/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java index 92afdf2..ea5e760 100644 --- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java +++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java @@ -39,7 +39,7 @@ public class MailboxPath { * @return inbox */ public static MailboxPath inbox(MailboxSession session) { - return new MailboxPath(session.getPersonalSpace(), session.getUser().getUserName(), MailboxConstants.INBOX); + return MailboxPath.forUser(session.getUser().getUserName(), MailboxConstants.INBOX); } /** @@ -47,7 +47,6 @@ public class MailboxPath { */ public static MailboxPath forUser(String username, String mailboxName) { return new MailboxPath(MailboxConstants.USER_NAMESPACE, username, mailboxName); - } private String namespace; http://git-wip-us.apache.org/repos/asf/james-project/blob/48d7caf6/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java ---------------------------------------------------------------------- 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 fe0348a..16ed62a 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 @@ -314,7 +314,7 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail } // Special case for INBOX: Let's use the user's folder. - MailboxPath inboxMailboxPath = new MailboxPath(session.getPersonalSpace(), userName, MailboxConstants.INBOX); + MailboxPath inboxMailboxPath = MailboxPath.forUser(userName, MailboxConstants.INBOX); mailboxList.add(maildirStore.loadMailbox(session, inboxMailboxPath)); // List all INBOX sub folders. http://git-wip-us.apache.org/repos/asf/james-project/blob/48d7caf6/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java index 5c0f875..eb61e67 100644 --- a/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java +++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java @@ -24,6 +24,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; + import java.util.Optional; import org.apache.james.imap.api.ImapCommand; @@ -48,11 +49,11 @@ import org.apache.james.mailbox.model.MailboxPath; import org.apache.james.mailbox.model.MessageRange; import org.apache.james.mailbox.store.MailboxMetaData; import org.apache.james.metrics.api.NoopMetricFactory; - -import com.google.common.collect.Lists; import org.junit.Before; import org.junit.Test; +import com.google.common.collect.Lists; + public class CopyProcessorTest { public static final String TAG = "TAG"; @@ -83,7 +84,6 @@ public class CopyProcessorTest { MailboxSession.User user = mock(MailboxSession.User.class); when(user.getUserName()).thenReturn("username"); - when(mockMailboxSession.getPersonalSpace()).thenReturn(""); when(mockMailboxSession.getUser()).thenReturn(user); when(mockMailboxSession.getSessionId()).thenReturn(42L); when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED); @@ -122,7 +122,6 @@ public class CopyProcessorTest { MailboxSession.User user = mock(MailboxSession.User.class); when(user.getUserName()).thenReturn("username"); - when(mockMailboxSession.getPersonalSpace()).thenReturn(""); when(mockMailboxSession.getUser()).thenReturn(user); when(mockMailboxSession.getSessionId()).thenReturn(42L); when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED); @@ -160,7 +159,6 @@ public class CopyProcessorTest { MailboxSession.User user = mock(MailboxSession.User.class); when(user.getUserName()).thenReturn("username"); - when(mockMailboxSession.getPersonalSpace()).thenReturn(""); when(mockMailboxSession.getUser()).thenReturn(user); when(mockMailboxSession.getSessionId()).thenReturn(42L); when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED); @@ -192,7 +190,6 @@ public class CopyProcessorTest { MailboxSession.User user = mock(MailboxSession.User.class); when(user.getUserName()).thenReturn("username"); - when(mockMailboxSession.getPersonalSpace()).thenReturn(""); when(mockMailboxSession.getUser()).thenReturn(user); when(mockMailboxSession.getSessionId()).thenReturn(42L); when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED); http://git-wip-us.apache.org/repos/asf/james-project/blob/48d7caf6/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java index aa8a754..7b45822 100644 --- a/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java +++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java @@ -26,6 +26,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; + import java.util.Optional; import org.apache.james.imap.api.ImapCommand; @@ -51,11 +52,11 @@ import org.apache.james.mailbox.model.MailboxPath; import org.apache.james.mailbox.model.MessageRange; import org.apache.james.mailbox.store.MailboxMetaData; import org.apache.james.metrics.api.NoopMetricFactory; - -import com.google.common.collect.Lists; import org.junit.Before; import org.junit.Test; +import com.google.common.collect.Lists; + public class MoveProcessorTest { public static final String TAG = "TAG"; @@ -100,7 +101,6 @@ public class MoveProcessorTest { MailboxSession.User user = mock(MailboxSession.User.class); when(user.getUserName()).thenReturn("username"); - when(mockMailboxSession.getPersonalSpace()).thenReturn(""); when(mockMailboxSession.getUser()).thenReturn(user); when(mockMailboxSession.getSessionId()).thenReturn(42L); when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED); @@ -141,7 +141,6 @@ public class MoveProcessorTest { MailboxSession.User user = mock(MailboxSession.User.class); when(user.getUserName()).thenReturn("username"); - when(mockMailboxSession.getPersonalSpace()).thenReturn(""); when(mockMailboxSession.getUser()).thenReturn(user); when(mockMailboxSession.getSessionId()).thenReturn(42L); when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED); @@ -180,7 +179,6 @@ public class MoveProcessorTest { MailboxSession.User user = mock(MailboxSession.User.class); when(user.getUserName()).thenReturn("username"); - when(mockMailboxSession.getPersonalSpace()).thenReturn(""); when(mockMailboxSession.getUser()).thenReturn(user); when(mockMailboxSession.getSessionId()).thenReturn(42L); when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED); @@ -212,7 +210,6 @@ public class MoveProcessorTest { MailboxSession.User user = mock(MailboxSession.User.class); when(user.getUserName()).thenReturn("username"); - when(mockMailboxSession.getPersonalSpace()).thenReturn(""); when(mockMailboxSession.getUser()).thenReturn(user); when(mockMailboxSession.getSessionId()).thenReturn(42L); when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED); http://git-wip-us.apache.org/repos/asf/james-project/blob/48d7caf6/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java ---------------------------------------------------------------------- diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java index 2a931c1..50e80dd 100644 --- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java +++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java @@ -25,7 +25,6 @@ import javax.mail.Flags; import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; -import org.apache.james.server.core.MimeMessageInputStream; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MessageManager; @@ -33,6 +32,7 @@ import org.apache.james.mailbox.exception.BadCredentialsException; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.model.ComposedMessageId; import org.apache.james.mailbox.model.MailboxPath; +import org.apache.james.server.core.MimeMessageInputStream; import com.google.common.base.Strings; @@ -65,7 +65,7 @@ public class MailboxAppender { private ComposedMessageId append(MimeMessage mail, String user, String folder, MailboxSession session) throws MessagingException { mailboxManager.startProcessingRequest(session); try { - MailboxPath mailboxPath = new MailboxPath(session.getPersonalSpace(), user, folder); + MailboxPath mailboxPath = MailboxPath.forUser(user, folder); return appendMessageToMailbox(mail, session, mailboxPath); } catch (MailboxException e) { throw new MessagingException("Unable to access mailbox.", e); http://git-wip-us.apache.org/repos/asf/james-project/blob/48d7caf6/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java index 7738e6a..4b9857b 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DefaultMailboxesProvisioningFilter.java @@ -98,7 +98,7 @@ public class DefaultMailboxesProvisioningFilter implements Filter { } private Function<String, MailboxPath> toMailboxPath(MailboxSession session) { - return mailbox -> new MailboxPath(session.getPersonalSpace(), session.getUser().getUserName(), mailbox); + return mailbox -> MailboxPath.forUser(session.getUser().getUserName(), mailbox); } private void createMailbox(MailboxPath mailboxPath, MailboxSession session) { http://git-wip-us.apache.org/repos/asf/james-project/blob/48d7caf6/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java index 51b9c54..d9e4f1f 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java @@ -20,9 +20,11 @@ package org.apache.james.jmap.methods; import static org.apache.james.jmap.methods.Method.JMAP_PREFIX; + import java.util.HashMap; import java.util.Map; import java.util.Optional; + import javax.inject.Inject; import org.apache.james.jmap.exceptions.MailboxParentNotFoundException; @@ -170,10 +172,10 @@ public class SetMailboxesCreationProcessor implements SetMailboxesProcessor { .orElseThrow(() -> new MailboxParentNotFoundException(parentId)) )); - return new MailboxPath(mailboxSession.getPersonalSpace(), mailboxSession.getUser().getUserName(), + return MailboxPath.forUser(mailboxSession.getUser().getUserName(), parentName + mailboxSession.getPathDelimiter() + mailboxRequest.getName()); } - return new MailboxPath(mailboxSession.getPersonalSpace(), mailboxSession.getUser().getUserName(), mailboxRequest.getName()); + return MailboxPath.forUser(mailboxSession.getUser().getUserName(), mailboxRequest.getName()); } private Optional<String> getMailboxNameFromId(MailboxCreationId creationId, MailboxSession mailboxSession) { http://git-wip-us.apache.org/repos/asf/james-project/blob/48d7caf6/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java index 4d7a8fd..645182e 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java @@ -235,9 +235,9 @@ public class SetMailboxesUpdateProcessor implements SetMailboxesProcessor { private MailboxPath computeNewMailboxPath(Mailbox mailbox, MailboxPath originMailboxPath, MailboxUpdateRequest updateRequest, MailboxSession mailboxSession) throws MailboxException { Optional<MailboxId> parentId = updateRequest.getParentId(); if (parentId == null) { - return new MailboxPath(mailboxSession.getPersonalSpace(), - mailboxSession.getUser().getUserName(), - updateRequest.getName().orElse(mailbox.getName())); + return MailboxPath.forUser( + mailboxSession.getUser().getUserName(), + updateRequest.getName().orElse(mailbox.getName())); } MailboxPath modifiedMailboxPath = updateRequest.getName() http://git-wip-us.apache.org/repos/asf/james-project/blob/48d7caf6/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java ---------------------------------------------------------------------- diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java index 581d1e9..35e1860 100644 --- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java +++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/UserMailboxesService.java @@ -122,7 +122,7 @@ public class UserMailboxesService { } private MailboxPath convertToMailboxPath(String username, String mailboxName, MailboxSession mailboxSession) { - return new MailboxPath(mailboxSession.getPersonalSpace(), username, mailboxName); + return MailboxPath.forUser(username, mailboxName); } private Stream<MailboxMetaData> listUserMailboxes(MailboxSession mailboxSession) throws MailboxException { --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org