james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From matth...@apache.org
Subject [22/27] james-project git commit: MAILBOX-310 Mailbox query refactoring: Mailbox query should rely on MailboxNameExpression
Date Thu, 05 Oct 2017 18:02:34 GMT
MAILBOX-310 Mailbox query refactoring: Mailbox query should rely on MailboxNameExpression


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d1030584
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d1030584
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d1030584

Branch: refs/heads/master
Commit: d10305840f8f20b2e974bde0e66f796b0ff13110
Parents: 0cfb395
Author: benwa <btellier@linagora.com>
Authored: Wed Oct 4 13:06:31 2017 +0700
Committer: Matthieu Baechler <matthieu@apache.org>
Committed: Thu Oct 5 20:00:38 2017 +0200

----------------------------------------------------------------------
 .../model/search/MailboxNameExpression.java     |  42 +++-
 .../mailbox/model/search/MailboxQuery.java      | 230 ++++---------------
 .../james/mailbox/model/search/Wildcard.java    |  18 ++
 .../james/mailbox/MailboxManagerTest.java       |  25 +-
 .../mailbox/model/search/MailboxQueryTest.java  | 115 +++-------
 .../mailbox/model/search/WildcardTest.java      |  10 +-
 .../inmemory/InMemoryMessageIdManager.java      |  14 +-
 .../InMemoryMessageIdManagerTestSystem.java     |   4 +-
 .../InMemoryMessageManagerTestSystem.java       |   5 +-
 .../mailbox/store/StoreMailboxManager.java      |  10 +-
 .../store/AbstractCombinationManagerTest.java   |  12 +-
 .../mailbox/store/StoreMailboxManagerTest.java  |  11 +-
 .../james/imap/processor/LSubProcessor.java     |  11 +-
 .../james/imap/processor/ListProcessor.java     |   9 +-
 .../apache/james/modules/MailboxProbeImpl.java  |  11 +-
 .../mailbox/MailboxManagerManagement.java       |  12 +-
 .../matchers/AbstractStorageQuota.java          |   7 +-
 .../james/jmap/methods/GetMailboxesMethod.java  |   4 +-
 .../jmap/utils/SystemMailboxesProviderImpl.java |   4 +-
 .../webadmin/service/UserMailboxesService.java  |  16 +-
 20 files changed, 221 insertions(+), 349 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/MailboxNameExpression.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/MailboxNameExpression.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/MailboxNameExpression.java
index 04a26bc..2b9d4c8 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/MailboxNameExpression.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/MailboxNameExpression.java
@@ -19,7 +19,7 @@
 
 package org.apache.james.mailbox.model.search;
 
-interface MailboxNameExpression {
+public interface MailboxNameExpression {
     /**
      * Use this wildcard to match every char including the hierarchy delimiter
      */
@@ -30,9 +30,49 @@ interface MailboxNameExpression {
      */
     char LOCALWILDCARD = '%';
 
+    /**
+     * Is the given name a match for this expression?
+     *
+     * @param name
+     *            name to be matched
+     * @return true if the given name matches this expression, false otherwise
+     */
     boolean isExpressionMatch(String name);
 
+    /**
+     * Get combined name formed by adding the expression to the base using the
+     * given hierarchy delimiter. Note that the wildcards are retained in the
+     * combined name.
+     *
+     * @return {@link #getBase()} combined with {@link #getExpression()},
+     *         notnull
+     */
     String getCombinedName();
 
+    /**
+     * Is this expression wild?
+     *
+     * @return true if wildcard contained, false otherwise
+     */
     boolean isWild();
+
+    /**
+     * Gets wildcard character that matches any series of characters.
+     *
+     * @return the freeWildcard
+     */
+    default char getFreeWildcard() {
+        return FREEWILDCARD;
+    }
+
+    /**
+     * Gets wildcard character that matches any series of characters excluding
+     * hierarchy delimiters. Effectively, this means that it matches any
+     * sequence within a name part.
+     *
+     * @return the localWildcard
+     */
+    default char getLocalWildcard() {
+        return LOCALWILDCARD;
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/MailboxQuery.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/MailboxQuery.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/MailboxQuery.java
index 9d51b78..2afec92 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/MailboxQuery.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/MailboxQuery.java
@@ -20,8 +20,6 @@
 package org.apache.james.mailbox.model.search;
 
 import java.util.Optional;
-import java.util.StringTokenizer;
-import java.util.regex.Pattern;
 
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.model.MailboxConstants;
@@ -36,17 +34,6 @@ import com.google.common.base.Preconditions;
  * Expresses select criteria for mailboxes.
  */
 public final class MailboxQuery {
-    /**
-     * Use this wildcard to match every char including the hierarchy delimiter
-     */
-    public final static char FREEWILDCARD = '*';
-
-    /**
-     * Use this wildcard to match every char except the hierarchy delimiter
-     */
-    public final static char LOCALWILDCARD = '%';
-
-    private static final String EMPTY_PATH_NAME = "";
 
     public static Builder builder() {
         return new Builder();
@@ -54,76 +41,72 @@ public final class MailboxQuery {
 
     public static Builder privateMailboxesBuilder(MailboxSession session) {
         return builder()
-            .mailboxSession(session)
-            .username(session.getUser().getUserName());
+            .namespace(MailboxConstants.USER_NAMESPACE)
+            .username(session.getUser().getUserName())
+            .matchesAllMailboxNames();
     }
 
     public static class Builder {
-        private String expression;
-        @VisibleForTesting Optional<Character> pathDelimiter;
-        @VisibleForTesting Optional<String> username;
-        @VisibleForTesting Optional<String> pathName;
-        @VisibleForTesting Optional<String> namespace;
+        private static final Wildcard DEFAULT_WILDCARD = Wildcard.INSTANCE;
+
+        Optional<String> username;
+        Optional<String> namespace;
+        Optional<MailboxNameExpression> mailboxNameExpression;
         
         private Builder() {
-            this.pathName = Optional.empty();
             this.namespace = Optional.empty();
             this.username = Optional.empty();
-            this.pathDelimiter = Optional.empty();
+            this.mailboxNameExpression = Optional.empty();
         }
         
-        public Builder base(MailboxPath base) {
+        public Builder userAndNamespaceFrom(MailboxPath base) {
+            Preconditions.checkState(!this.namespace.isPresent());
+            Preconditions.checkState(!this.username.isPresent());
+
             this.namespace = Optional.ofNullable(base.getNamespace());
             this.username = Optional.ofNullable(base.getUser());
-            this.pathName = Optional.ofNullable(base.getName());
             return this;
         }
-        
+
         public Builder username(String username) {
+            Preconditions.checkState(!this.username.isPresent());
+
             this.username = Optional.of(username);
             return this;
         }
-        
-        public Builder privateMailboxes() {
-            Preconditions.checkState(!pathName.isPresent());
-            Preconditions.checkState(!namespace.isPresent());
-            this.namespace = Optional.of(MailboxConstants.USER_NAMESPACE);
-            this.pathName = Optional.of(EMPTY_PATH_NAME);
-            return matchesAll();
-        }
-        
-        public Builder expression(String expression) {
-            this.expression = expression;
+
+        public Builder namespace(String namespace) {
+            Preconditions.checkState(!this.namespace.isPresent());
+
+            this.namespace = Optional.of(namespace);
             return this;
         }
-        
-        public Builder matchesAll() {
-            this.expression = String.valueOf(FREEWILDCARD);
+
+        public Builder privateNamespace() {
+            Preconditions.checkState(!this.namespace.isPresent());
+
+            this.namespace = Optional.of(MailboxConstants.USER_NAMESPACE);
             return this;
         }
-
-        public Builder mailboxSession(MailboxSession session) {
-            this.pathDelimiter = Optional.of(session.getPathDelimiter());
+        
+        public Builder expression(MailboxNameExpression expression) {
+            this.mailboxNameExpression = Optional.of(expression);
             return this;
         }
-
-        public Builder pathDelimiter(char pathDelimiter) {
-            this.pathDelimiter = Optional.of(pathDelimiter);
+        
+        public Builder matchesAllMailboxNames() {
+            this.mailboxNameExpression = Optional.of(Wildcard.INSTANCE);
             return this;
         }
         
         public MailboxQuery build() {
-            Preconditions.checkState(pathDelimiter.isPresent());
-            return new MailboxQuery(namespace, username, pathName, expression, pathDelimiter.get());
+            return new MailboxQuery(namespace, username, mailboxNameExpression.orElse(DEFAULT_WILDCARD));
         }
     }
 
-    private final String expression;
-    private final char pathDelimiter;
-    private final Pattern pattern;
     private final Optional<String> namespace;
     private final Optional<String> user;
-    private final Optional<String> baseName;
+    private final MailboxNameExpression mailboxNameExpression;
 
     /**
      * Constructs an expression determining a set of mailbox names.
@@ -135,18 +118,10 @@ public final class MailboxQuery {
      * @param pathDelimiter
      *            path delimiter to use
      */
-    @VisibleForTesting MailboxQuery(Optional<String> namespace, Optional<String> user, Optional<String> baseName,
-                                    String expression, char pathDelimiter) {
+    @VisibleForTesting MailboxQuery(Optional<String> namespace, Optional<String> user, MailboxNameExpression mailboxNameExpression) {
         this.namespace = namespace;
         this.user = user;
-        this.baseName = baseName;
-        if (expression == null) {
-            this.expression = "";
-        } else {
-            this.expression = expression;
-        }
-        this.pathDelimiter = pathDelimiter;
-        pattern = constructEscapedRegex();
+        this.mailboxNameExpression = mailboxNameExpression;
     }
 
     public Optional<String> getNamespace() {
@@ -157,8 +132,8 @@ public final class MailboxQuery {
         return user;
     }
 
-    public Optional<String> getBaseName() {
-        return baseName;
+    public MailboxNameExpression getMailboxNameExpression() {
+        return mailboxNameExpression;
     }
 
     public boolean isPrivateMailboxes(MailboxSession session) {
@@ -167,7 +142,8 @@ public final class MailboxQuery {
             && user.map(sessionUser::isSameUser).orElse(false);
     }
 
-    public boolean belongsToRequestedNamespaceAndUser(MailboxPath mailboxPath) {
+    @VisibleForTesting
+    boolean belongsToRequestedNamespaceAndUser(MailboxPath mailboxPath) {
         boolean belongsToRequestedNamespace = namespace
             .map(value -> value.equals(mailboxPath.getNamespace()))
             .orElse(true);
@@ -178,141 +154,21 @@ public final class MailboxQuery {
         return belongsToRequestedNamespace && belongsToRequestedUser;
     }
 
-    /**
-     * Gets the name search expression. This may contain wildcards.
-     * 
-     * @return the expression
-     */
-    public final String getExpression() {
-        return expression;
-    }
-
-    /**
-     * Gets wildcard character that matches any series of characters.
-     * 
-     * @return the freeWildcard
-     */
-    public final char getFreeWildcard() {
-        return FREEWILDCARD;
-    }
-
-    /**
-     * Gets wildcard character that matches any series of characters excluding
-     * hierarchy delimiters. Effectively, this means that it matches any
-     * sequence within a name part.
-     * 
-     * @return the localWildcard
-     */
-    public final char getLocalWildcard() {
-        return LOCALWILDCARD;
-    }
-
-    /**
-     * Is the given name a match for {@link #getExpression()}?
-     * 
-     * @param name
-     *            name to be matched
-     * @return true if the given name matches this expression, false otherwise
-     */
     public boolean isExpressionMatch(String name) {
-        if (isWild()) {
-            return name != null
-                && pattern.matcher(name).matches();
-        } else {
-            return expression.equals(name);
-        }
+        return mailboxNameExpression.isExpressionMatch(name);
     }
 
     public boolean isPathMatch(MailboxPath mailboxPath) {
-        String baseName = this.baseName.orElse(EMPTY_PATH_NAME);
-        int baseNameLength = baseName.length();
-        String mailboxName = mailboxPath.getName();
-
         return belongsToRequestedNamespaceAndUser(mailboxPath)
-            && mailboxName.startsWith(baseName)
-            && isExpressionMatch(mailboxName.substring(baseNameLength));
-    }
-  
-    /**
-     * Get combined name formed by adding the expression to the base using the
-     * given hierarchy delimiter. Note that the wildcards are retained in the
-     * combined name.
-     * 
-     * @return {@link #getBase()} combined with {@link #getExpression()},
-     *         notnull
-     */
-    public String getCombinedName() {
-        String baseName = this.baseName.orElse(null);
-        if (baseName != null && baseName.length() > 0) {
-            final int baseLength = baseName.length();
-            if (baseName.charAt(baseLength - 1) == pathDelimiter) {
-                if (expression != null && expression.length() > 0) {
-                    if (expression.charAt(0) == pathDelimiter) {
-                        return baseName + expression.substring(1);
-                    } else {
-                        return baseName + expression;
-                    }
-                } else {
-                    return baseName;
-                }
-            } else {
-                if (expression != null && expression.length() > 0) {
-                    if (expression.charAt(0) == pathDelimiter) {
-                        return baseName + expression;
-                    } else {
-                        return baseName + pathDelimiter + expression;
-                    }
-                } else {
-                    return baseName;
-                }
-            }
-        } else {
-            return expression;
-        }
-    }
-
-    /**
-     * Is this expression wild?
-     * 
-     * @return true if wildcard contained, false otherwise
-     */
-    public boolean isWild() {
-        return expression != null
-            && (
-                expression.indexOf(getFreeWildcard()) >= 0
-                || expression.indexOf(getLocalWildcard()) >= 0);
+            && isExpressionMatch(mailboxPath.getName());
     }
 
     public String toString() {
         return MoreObjects.toStringHelper(this)
-            .add("expression", expression)
-            .add("pathDelimiter", pathDelimiter)
-            .add("pattern", pattern)
             .add("namespace", namespace)
             .add("user", user)
-            .add("baseName", baseName)
+            .add("mailboxNameExpression", mailboxNameExpression)
             .toString();
     }
 
-
-    private Pattern constructEscapedRegex() {
-        StringBuilder stringBuilder = new StringBuilder();
-        StringTokenizer tokenizer = new StringTokenizer(expression, "*%", true);
-        while (tokenizer.hasMoreTokens()) {
-            stringBuilder.append(getRegexPartAssociatedWithToken(tokenizer));
-        }
-        return Pattern.compile(stringBuilder.toString());
-    }
-
-    private String getRegexPartAssociatedWithToken(StringTokenizer tokenizer) {
-        String token = tokenizer.nextToken();
-        if (token.equals("*")) {
-            return ".*";
-        } else if (token.equals("%")) {
-            return "[^" + Pattern.quote(String.valueOf(pathDelimiter)) + "]*";
-        } else {
-            return Pattern.quote(token);
-        }
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/Wildcard.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/Wildcard.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/Wildcard.java
index 655b5c7..fa647cb 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/Wildcard.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/search/Wildcard.java
@@ -19,9 +19,17 @@
 
 package org.apache.james.mailbox.model.search;
 
+import java.util.Objects;
+
 import com.google.common.base.Preconditions;
 
 public class Wildcard implements MailboxNameExpression {
+
+    public static final Wildcard INSTANCE = new Wildcard();
+
+    private Wildcard() {
+    }
+
     @Override
     public boolean isExpressionMatch(String name) {
         Preconditions.checkNotNull(name);
@@ -37,4 +45,14 @@ public class Wildcard implements MailboxNameExpression {
     public boolean isWild() {
         return true;
     }
+
+    @Override
+    public final boolean equals(Object o) {
+        return o instanceof Wildcard;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hash();
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
index bc74a13..f04cfa5 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
@@ -243,12 +243,10 @@ public abstract class MailboxManagerTest {
         mailboxManager.createMailbox(new MailboxPath("other_namespace", USER_1, "Other"), session);
         mailboxManager.createMailbox(MailboxPath.inbox(session), session);
         List<MailboxMetaData> metaDatas = mailboxManager.search(
-                MailboxQuery.builder()
-                    .base(MailboxPath.forUser(USER_1, ""))
-                    .expression("*")
-                    .mailboxSession(session)
-                    .build(), 
-                session);
+            MailboxQuery.privateMailboxesBuilder(session)
+                .matchesAllMailboxNames()
+                .build(),
+            session);
         assertThat(metaDatas).hasSize(1);
         assertThat(metaDatas.get(0).getPath()).isEqualTo(MailboxPath.inbox(session));
     }
@@ -259,11 +257,9 @@ public abstract class MailboxManagerTest {
         mailboxManager.createMailbox(MailboxPath.forUser(USER_2, "Other"), session);
         mailboxManager.createMailbox(MailboxPath.inbox(session), session);
         List<MailboxMetaData> metaDatas = mailboxManager.search(
-                MailboxQuery.builder()
-                .base(MailboxPath.forUser(USER_1, ""))
-                .expression("*")
-                    .mailboxSession(session)
-                .build(), 
+            MailboxQuery.privateMailboxesBuilder(session)
+                .matchesAllMailboxNames()
+                .build(),
             session);
         assertThat(metaDatas).hasSize(1);
         assertThat(metaDatas.get(0).getPath()).isEqualTo(MailboxPath.inbox(session));
@@ -454,8 +450,7 @@ public abstract class MailboxManagerTest {
             session1);
 
         MailboxQuery mailboxQuery = MailboxQuery.builder()
-            .mailboxSession(session2)
-            .matchesAll()
+            .matchesAllMailboxNames()
             .build();
 
         assertThat(mailboxManager.search(mailboxQuery, session2))
@@ -480,7 +475,7 @@ public abstract class MailboxManagerTest {
             session1);
 
         MailboxQuery mailboxQuery = MailboxQuery.builder()
-            .matchesAll()
+            .matchesAllMailboxNames()
             .build();
 
         assertThat(mailboxManager.search(mailboxQuery, session2))
@@ -510,7 +505,7 @@ public abstract class MailboxManagerTest {
             session1);
 
         MailboxQuery mailboxQuery = MailboxQuery.builder()
-            .matchesAll()
+            .matchesAllMailboxNames()
             .build();
 
         assertThat(mailboxManager.search(mailboxQuery, session2))

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/MailboxQueryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/MailboxQueryTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/MailboxQueryTest.java
index 7f59c12..5159209 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/MailboxQueryTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/MailboxQueryTest.java
@@ -21,12 +21,7 @@
 package org.apache.james.mailbox.model.search;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MailboxSession.User;
-import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.search.MailboxQuery.Builder;
 import org.junit.Before;
@@ -36,127 +31,98 @@ public class MailboxQueryTest {
     private static final String CURRENT_USER = "user";
 
     private MailboxPath mailboxPath;
-    private MailboxSession mailboxSession;
 
     @Before
     public void setUp() {
         mailboxPath = new MailboxPath("namespace", "user", "name");
-        mailboxSession = new MockMailboxSession("user");
     }
 
     @Test
     public void buildShouldMatchAllValuesWhenMatchesAll() throws Exception {
-        //When
+
         MailboxQuery actual = MailboxQuery.builder()
-                .base(mailboxPath)
-                .matchesAll()
-                .mailboxSession(mailboxSession)
+                .userAndNamespaceFrom(mailboxPath)
+                .matchesAllMailboxNames()
                 .build();
-        //Then
+
         assertThat(actual.isExpressionMatch("folder")).isTrue();
     }
 
     @Test
     public void buildShouldConstructMailboxPathWhenPrivateUserMailboxes() throws Exception {
-        //Given
         MailboxPath expected = MailboxPath.forUser("user", "");
-        //When
+
         MailboxQuery actual = MailboxQuery.builder()
                 .username("user")
-                .privateMailboxes()
-                .mailboxSession(mailboxSession)
+                .privateNamespace()
                 .build();
-        //Then
+
         assertThat(actual.getNamespace()).contains(expected.getNamespace());
         assertThat(actual.getUser()).contains(expected.getUser());
-        assertThat(actual.getBaseName()).contains(expected.getName());
+        assertThat(actual.getMailboxNameExpression()).isEqualTo(Wildcard.INSTANCE);
     }
 
     @Test
     public void buildShouldMatchAllValuesWhenPrivateUserMailboxes() throws Exception {
-        //Given
         Builder testee = MailboxQuery.builder()
                 .username("user")
-                .privateMailboxes()
-            .mailboxSession(mailboxSession);
-        //When
+                .privateNamespace();
+
         MailboxQuery actual = testee.build();
-        //Then
-        assertThat(actual.isExpressionMatch("folder")).isTrue();
-    }
 
-    @Test
-    public void builderShouldInitFromSessionWhenGiven() throws Exception {
-        //Given
-        MailboxSession mailboxSession = mock(MailboxSession.class);
-        when(mailboxSession.getPathDelimiter()).thenReturn('#');
-        User user = mock(User.class);
-        when(user.getUserName()).thenReturn("little bobby table");
-        when(mailboxSession.getUser()).thenReturn(user);
-        // When
-        Builder query = MailboxQuery.privateMailboxesBuilder(mailboxSession);
-        //Then
-        assertThat(query.pathDelimiter).contains('#');
-        assertThat(query.username).contains("little bobby table");
+        assertThat(actual.isExpressionMatch("folder")).isTrue();
     }
 
     @Test
     public void builderShouldNotThrowWhenNoBaseDefined() throws Exception {
-        //Given
         Builder testee = MailboxQuery.builder()
-                .expression("abc")
-                .mailboxSession(mailboxSession);
-        //When
+                .expression(new ExactName("abc"));
+
         testee.build();
     }
 
     @Test(expected=IllegalStateException.class)
     public void builderShouldThrowWhenBaseAndUsernameGiven() throws Exception {
-        //Given
         Builder testee = MailboxQuery.builder()
-                .base(mailboxPath)
+                .userAndNamespaceFrom(mailboxPath)
                 .username("user");
-        //When
+
         testee.build();
     }
 
     @Test(expected=IllegalStateException.class)
     public void builderShouldThrowWhenBaseGiven() throws Exception {
-        //Given
         Builder testee = MailboxQuery.builder()
-                .base(mailboxPath)
-                .privateMailboxes();
-        //When
+                .userAndNamespaceFrom(mailboxPath)
+                .privateNamespace();
+
         testee.build();
     } 
 
-    @Test(expected=IllegalStateException.class)
-    public void builderShouldThrowWhenMissingUsername() throws Exception {
-        //Given
+    @Test
+    public void builderShouldNotThrowWhenMissingUsername() throws Exception {
         Builder testee = MailboxQuery.builder()
-                .privateMailboxes();
-        //When
+                .privateNamespace();
+
         testee.build();
     }
 
     @Test
     public void builderShouldUseBaseWhenGiven() throws Exception {
-        //When
+
         MailboxQuery actual = MailboxQuery.builder()
-                .base(mailboxPath)
-                .mailboxSession(mailboxSession)
+                .userAndNamespaceFrom(mailboxPath)
                 .build();
-        //Then
+
         assertThat(actual.getNamespace()).contains(mailboxPath.getNamespace());
         assertThat(actual.getUser()).contains(mailboxPath.getUser());
-        assertThat(actual.getBaseName()).contains(mailboxPath.getName());
+        assertThat(actual.getMailboxNameExpression()).isEqualTo(Wildcard.INSTANCE);
     }
 
     @Test
     public void belongsToNamespaceAndUserShouldReturnTrueWithIdenticalMailboxes() {
         MailboxQuery mailboxQuery = MailboxQuery.builder()
-            .base(mailboxPath)
-            .mailboxSession(mailboxSession)
+            .userAndNamespaceFrom(mailboxPath)
             .build();
 
         assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(mailboxPath))
@@ -168,8 +134,7 @@ public class MailboxQueryTest {
         MailboxPath base = new MailboxPath("namespace", null, "name");
 
         MailboxQuery mailboxQuery = MailboxQuery.builder()
-            .base(base)
-            .mailboxSession(mailboxSession)
+            .userAndNamespaceFrom(base)
             .build();
 
         assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(mailboxPath))
@@ -181,8 +146,7 @@ public class MailboxQueryTest {
         MailboxPath mailboxPath = new MailboxPath(null, "user", "name");
 
         MailboxQuery mailboxQuery = MailboxQuery.builder()
-            .base(mailboxPath)
-            .mailboxSession(mailboxSession)
+            .userAndNamespaceFrom(mailboxPath)
             .build();
 
         assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(mailboxPath))
@@ -192,8 +156,7 @@ public class MailboxQueryTest {
     @Test
     public void belongsToNamespaceAndUserShouldReturnTrueWithMailboxWithSameNamespaceAndUserWithNullUser() {
         MailboxQuery mailboxQuery = MailboxQuery.builder()
-            .base(new MailboxPath("namespace", null, "name"))
-            .mailboxSession(mailboxSession)
+            .userAndNamespaceFrom(new MailboxPath("namespace", null, "name"))
             .build();
 
         assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace", null, "name")))
@@ -203,8 +166,7 @@ public class MailboxQueryTest {
     @Test
     public void belongsToNamespaceAndUserShouldReturnTrueWithMailboxWithSameNamespaceAndUser() {
         MailboxQuery mailboxQuery = MailboxQuery.builder()
-            .base(new MailboxPath("namespace", CURRENT_USER, "name"))
-            .mailboxSession(mailboxSession)
+            .userAndNamespaceFrom(new MailboxPath("namespace", CURRENT_USER, "name"))
             .build();
 
         assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace", CURRENT_USER, "name2")))
@@ -214,8 +176,7 @@ public class MailboxQueryTest {
     @Test
     public void belongsToNamespaceAndUserShouldReturnFalseWithDifferentNamespace() {
         MailboxQuery mailboxQuery = MailboxQuery.builder()
-            .base(new MailboxPath("namespace", CURRENT_USER, "name"))
-            .mailboxSession(mailboxSession)
+            .userAndNamespaceFrom(new MailboxPath("namespace", CURRENT_USER, "name"))
             .build();
 
         assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace2", CURRENT_USER, "name")))
@@ -225,8 +186,7 @@ public class MailboxQueryTest {
     @Test
     public void belongsToNamespaceAndUserShouldReturnFalseWithDifferentUser() {
         MailboxQuery mailboxQuery = MailboxQuery.builder()
-            .base(new MailboxPath("namespace", CURRENT_USER, "name"))
-            .mailboxSession(mailboxSession)
+            .userAndNamespaceFrom(new MailboxPath("namespace", CURRENT_USER, "name"))
             .build();
 
         assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace", CURRENT_USER + "2", "name")))
@@ -235,8 +195,7 @@ public class MailboxQueryTest {
     @Test
     public void belongsToNamespaceAndUserShouldReturnFalseWithOneOfTheUserNull() {
         MailboxQuery mailboxQuery = MailboxQuery.builder()
-            .base(new MailboxPath("namespace", CURRENT_USER, "name"))
-            .mailboxSession(mailboxSession)
+            .userAndNamespaceFrom(new MailboxPath("namespace", CURRENT_USER, "name"))
             .build();
 
         assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace", null, "name")))
@@ -246,8 +205,7 @@ public class MailboxQueryTest {
     @Test
     public void belongsToNamespaceAndUserShouldReturnFalseWhenDifferentUser() {
         MailboxQuery mailboxQuery = MailboxQuery.builder()
-            .base(new MailboxPath("namespace", CURRENT_USER, "name"))
-            .mailboxSession(mailboxSession)
+            .userAndNamespaceFrom(new MailboxPath("namespace", CURRENT_USER, "name"))
             .build();
 
         assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace", "other", "name")))
@@ -257,8 +215,7 @@ public class MailboxQueryTest {
     @Test
     public void belongsToNamespaceAndUserShouldReturnFalseIfNamespaceAreDifferentWithNullUser() {
         MailboxQuery mailboxQuery = MailboxQuery.builder()
-            .base(new MailboxPath("namespace", null, "name"))
-            .mailboxSession(mailboxSession)
+            .userAndNamespaceFrom(new MailboxPath("namespace", null, "name"))
             .build();
 
         assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace2", null, "name")))

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/WildcardTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/WildcardTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/WildcardTest.java
index a607164..1290a39 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/WildcardTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/search/WildcardTest.java
@@ -28,31 +28,31 @@ public class WildcardTest {
 
     @Test
     public void isWildShouldBeTrue() {
-        assertThat(new Wildcard().isWild())
+        assertThat(Wildcard.INSTANCE.isWild())
             .isTrue();
     }
 
     @Test
     public void getCombinedNameShouldReturnWildcard() {
-        assertThat(new Wildcard().getCombinedName())
+        assertThat(Wildcard.INSTANCE.getCombinedName())
             .isEqualTo(String.valueOf(MailboxNameExpression.FREEWILDCARD));
     }
 
     @Test
     public void isExpressionMatchShouldMatchAnyValue() {
-        assertThat(new Wildcard().isExpressionMatch("any"))
+        assertThat(Wildcard.INSTANCE.isExpressionMatch("any"))
             .isTrue();
     }
 
     @Test
     public void isExpressionMatchShouldMatchEmptyValue() {
-        assertThat(new Wildcard().isExpressionMatch(""))
+        assertThat(Wildcard.INSTANCE.isExpressionMatch(""))
             .isTrue();
     }
 
     @Test
     public void isExpressionMatchShouldThrowOnNullValue() {
-        assertThatThrownBy(() -> new Wildcard().isExpressionMatch(null))
+        assertThatThrownBy(() -> Wildcard.INSTANCE.isExpressionMatch(null))
             .isInstanceOf(NullPointerException.class);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManager.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManager.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManager.java
index 566a284..e009c84 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManager.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManager.java
@@ -87,7 +87,7 @@ public class InMemoryMessageIdManager implements MessageIdManager {
 
 
     @Override
-    public List<MessageResult> getMessages(List<MessageId> messages, FetchGroup fetchGroup, final MailboxSession mailboxSession) throws MailboxException {
+    public List<MessageResult> getMessages(List<MessageId> messages, FetchGroup fetchGroup, MailboxSession mailboxSession) throws MailboxException {
         return getUsersMailboxIds(mailboxSession)
             .stream()
             .flatMap(Throwing.function(mailboxId -> retrieveMailboxMessages(mailboxId, messages, FetchGroupImpl.MINIMAL, mailboxSession)))
@@ -136,7 +136,7 @@ public class InMemoryMessageIdManager implements MessageIdManager {
         }
     }
 
-    private List<MailboxId> getUsersMailboxIds(final MailboxSession mailboxSession) throws MailboxException {
+    private List<MailboxId> getUsersMailboxIds(MailboxSession mailboxSession) throws MailboxException {
         return mailboxManager.search(userMailboxes(mailboxSession), mailboxSession)
             .stream()
             .map(MailboxMetaData::getId)
@@ -144,10 +144,8 @@ public class InMemoryMessageIdManager implements MessageIdManager {
     }
 
     private MailboxQuery userMailboxes(MailboxSession mailboxSession) {
-        return MailboxQuery.builder()
-                .matchesAll()
-                .username(mailboxSession.getUser().getUserName())
-                .mailboxSession(mailboxSession)
+        return MailboxQuery.privateMailboxesBuilder(mailboxSession)
+                .matchesAllMailboxNames()
                 .build();
     }
 
@@ -166,7 +164,7 @@ public class InMemoryMessageIdManager implements MessageIdManager {
         }
     }
 
-    private Predicate<MailboxId> findMailboxBelongsToAnotherSession(final MailboxSession mailboxSession) {
+    private Predicate<MailboxId> findMailboxBelongsToAnotherSession(MailboxSession mailboxSession) {
         return input -> {
             try {
                 MailboxPath currentMailbox = mailboxManager.getMailbox(input, mailboxSession).getMailboxPath();
@@ -184,7 +182,7 @@ public class InMemoryMessageIdManager implements MessageIdManager {
             .findFirst();
     }
 
-    private Predicate<MessageResult> filterByMessageId(final MessageId messageId) {
+    private Predicate<MessageResult> filterByMessageId(MessageId messageId) {
         return messageResult -> messageResult.getMessageId().equals(messageId);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerTestSystem.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerTestSystem.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerTestSystem.java
index 5a35ae9..4cb2c60 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerTestSystem.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerTestSystem.java
@@ -95,7 +95,9 @@ public class InMemoryMessageIdManagerTestSystem extends MessageIdManagerTestSyst
     }
 
     private Optional<MailboxMetaData> retrieveMailbox(MailboxId mailboxId, MailboxSession mailboxSession) throws MailboxException {
-        MailboxQuery userMailboxesQuery = MailboxQuery.privateMailboxesBuilder(mailboxSession).expression("*").build();
+        MailboxQuery userMailboxesQuery = MailboxQuery.privateMailboxesBuilder(mailboxSession)
+            .matchesAllMailboxNames()
+            .build();
         return mailboxManager.search(userMailboxesQuery, mailboxSession)
             .stream()
             .filter(mailboxMetaData -> mailboxMetaData.getId().equals(mailboxId))

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageManagerTestSystem.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageManagerTestSystem.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageManagerTestSystem.java
index 273df14..31dc491 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageManagerTestSystem.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageManagerTestSystem.java
@@ -34,6 +34,7 @@ import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.search.MailboxQuery;
+import org.apache.james.mailbox.model.search.Wildcard;
 import org.apache.james.mailbox.store.MessageManagerTestSystem;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
@@ -95,7 +96,9 @@ public class InMemoryMessageManagerTestSystem extends MessageManagerTestSystem {
     }
 
     private Optional<MailboxMetaData> retrieveMailbox(final MailboxId mailboxId, MailboxSession mailboxSession) throws MailboxException {
-        MailboxQuery userMailboxesQuery = MailboxQuery.privateMailboxesBuilder(mailboxSession).expression("*").build();
+        MailboxQuery userMailboxesQuery = MailboxQuery.privateMailboxesBuilder(mailboxSession)
+            .expression(Wildcard.INSTANCE)
+            .build();
         return mailboxManager.search(userMailboxesQuery, mailboxSession)
             .stream()
             .filter(mailboxMetaData -> mailboxMetaData.getId().equals(mailboxId))

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
index 5ee075f..a125646 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
@@ -63,6 +63,7 @@ import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MessageId.Factory;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
+import org.apache.james.mailbox.model.search.MailboxNameExpression;
 import org.apache.james.mailbox.model.search.MailboxQuery;
 import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
@@ -696,14 +697,15 @@ public class StoreMailboxManager implements MailboxManager {
 
     @VisibleForTesting
     public static MailboxPath getPathLike(MailboxQuery mailboxQuery, MailboxSession mailboxSession) {
-        String combinedName = mailboxQuery.getCombinedName()
-            .replace(mailboxQuery.getFreeWildcard(), SQL_WILDCARD_CHAR)
-            .replace(mailboxQuery.getLocalWildcard(), SQL_WILDCARD_CHAR)
+        MailboxNameExpression nameExpression = mailboxQuery.getMailboxNameExpression();
+        String combinedName = nameExpression.getCombinedName()
+            .replace(nameExpression.getFreeWildcard(), SQL_WILDCARD_CHAR)
+            .replace(nameExpression.getLocalWildcard(), SQL_WILDCARD_CHAR)
             + SQL_WILDCARD_CHAR;
         MailboxPath base = new MailboxPath(
             mailboxQuery.getNamespace().orElse(MailboxConstants.USER_NAMESPACE),
             mailboxQuery.getUser().orElse(mailboxSession.getUser().getUserName()),
-            mailboxQuery.getBaseName().orElse(""));
+            combinedName);
         return new MailboxPath(base, combinedName);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java
index 530a0fd..8f74c76 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java
@@ -48,6 +48,7 @@ import org.apache.james.mailbox.model.MessageResult;
 import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.model.search.MailboxQuery;
+import org.apache.james.mailbox.model.search.PrefixedWildcard;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.junit.Test;
 
@@ -115,9 +116,8 @@ public abstract class AbstractCombinationManagerTest {
         SearchQuery query = new SearchQuery();
         query.andCriteria(SearchQuery.all());
 
-        MailboxQuery mailboxQuery = MailboxQuery.builder()
-            .base(MailboxFixture.MAILBOX_PATH1)
-            .mailboxSession(session)
+        MailboxQuery mailboxQuery = MailboxQuery.privateMailboxesBuilder(session)
+            .expression(new PrefixedWildcard(MailboxFixture.MAILBOX_PATH1.getName()))
             .build();
         MessageId messageId = messageManager1.appendMessage(new ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, FLAGS).getMessageId();
 
@@ -133,10 +133,8 @@ public abstract class AbstractCombinationManagerTest {
         SearchQuery query = new SearchQuery();
         query.andCriteria(SearchQuery.all());
 
-        MailboxQuery mailboxQuery = MailboxQuery.builder()
-            .username(MailboxFixture.USER)
-            .expression(String.valueOf(MailboxQuery.FREEWILDCARD))
-            .mailboxSession(session)
+        MailboxQuery mailboxQuery = MailboxQuery.privateMailboxesBuilder(session)
+            .matchesAllMailboxNames()
             .build();
         MessageId messageId = messageManager1.appendMessage(new ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, FLAGS).getMessageId();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java
index ed736ac..656fdd3 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxManagerTest.java
@@ -40,7 +40,10 @@ import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MessageId.Factory;
 import org.apache.james.mailbox.model.TestId;
+import org.apache.james.mailbox.model.search.MailboxNameExpression;
 import org.apache.james.mailbox.model.search.MailboxQuery;
+import org.apache.james.mailbox.model.search.PrefixedRegex;
+import org.apache.james.mailbox.model.search.PrefixedWildcard;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
@@ -177,8 +180,7 @@ public class StoreMailboxManagerTest {
         //Given
         MailboxSession session = new MockMailboxSession("user");
         MailboxQuery.Builder testee = MailboxQuery.builder()
-            .expression("abc")
-            .mailboxSession(session);
+            .expression(new PrefixedRegex(EMPTY_PREFIX, "abc", session.getPathDelimiter()));
         //When
         MailboxQuery mailboxQuery = testee.build();
 
@@ -191,9 +193,8 @@ public class StoreMailboxManagerTest {
         //Given
         MailboxSession session = new MockMailboxSession("user");
         MailboxQuery.Builder testee = MailboxQuery.builder()
-            .base(MailboxPath.forUser("user", "prefix."))
-            .expression("abc")
-            .mailboxSession(session);
+            .expression(new PrefixedRegex("prefix.", "abc", session.getPathDelimiter()));
+
         //When
         MailboxQuery mailboxQuery = testee.build();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/protocols/imap/src/main/java/org/apache/james/imap/processor/LSubProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/LSubProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/LSubProcessor.java
index cfe604c..62b7d29 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/LSubProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/LSubProcessor.java
@@ -41,6 +41,7 @@ import org.apache.james.mailbox.exception.SubscriptionException;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.search.MailboxQuery;
+import org.apache.james.mailbox.model.search.PrefixedRegex;
 import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.util.MDCBuilder;
 import org.slf4j.Logger;
@@ -74,10 +75,12 @@ public class LSubProcessor extends AbstractSubscriptionProcessor<LsubRequest> {
         }
 
         final MailboxQuery expression = MailboxQuery.builder()
-                .base(basePath)
-                .expression(CharsetUtil.decodeModifiedUTF7(mailboxName))
-                .mailboxSession(mailboxSession)
-                .build();
+            .userAndNamespaceFrom(basePath)
+            .expression(new PrefixedRegex(
+                basePath.getName(),
+                CharsetUtil.decodeModifiedUTF7(mailboxName),
+                mailboxSession.getPathDelimiter()))
+            .build();
         final Collection<String> mailboxResponses = new ArrayList<>();
         for (String mailbox : mailboxes) {
             respond(responder, expression, mailbox, true, mailboxes, mailboxResponses, mailboxSession.getPathDelimiter());

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
index 7d4bd31..b91ad75 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
@@ -46,6 +46,7 @@ import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxMetaData.Children;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.search.MailboxQuery;
+import org.apache.james.mailbox.model.search.PrefixedRegex;
 import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.util.MDCBuilder;
 import org.slf4j.Logger;
@@ -173,9 +174,11 @@ public class ListProcessor extends AbstractMailboxProcessor<ListRequest> {
 
                 results = getMailboxManager().search(
                         MailboxQuery.builder()
-                            .base(basePath)
-                            .expression(CharsetUtil.decodeModifiedUTF7(mailboxName))
-                            .mailboxSession(mailboxSession)
+                            .userAndNamespaceFrom(basePath)
+                            .expression(new PrefixedRegex(
+                                basePath.getName(),
+                                CharsetUtil.decodeModifiedUTF7(mailboxName),
+                                mailboxSession.getPathDelimiter()))
                             .build()
                         , mailboxSession);
             }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
----------------------------------------------------------------------
diff --git a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
index 32cebbd..77f0ba1 100644
--- a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
+++ b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
@@ -40,6 +40,7 @@ import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.search.MailboxQuery;
+import org.apache.james.mailbox.model.search.Wildcard;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -109,7 +110,7 @@ public class MailboxProbeImpl implements GuiceProbe, MailboxProbe {
         try {
             mailboxSession = mailboxManager.createSystemSession(user);
             mailboxManager.startProcessingRequest(mailboxSession);
-            return searchUserMailboxes(user, mailboxSession)
+            return searchUserMailboxes(mailboxSession)
                     .stream()
                     .map(MailboxMetaData::getPath)
                     .map(MailboxPath::getName)
@@ -121,12 +122,10 @@ public class MailboxProbeImpl implements GuiceProbe, MailboxProbe {
         }
     }
 
-    private List<MailboxMetaData> searchUserMailboxes(String username, MailboxSession session) throws MailboxException {
+    private List<MailboxMetaData> searchUserMailboxes(MailboxSession session) throws MailboxException {
         return mailboxManager.search(
-            MailboxQuery.builder()
-                .base(MailboxPath.forUser(username, ""))
-                .expression("*")
-                .mailboxSession(session)
+            MailboxQuery.privateMailboxesBuilder(session)
+                .expression(Wildcard.INSTANCE)
                 .build(),
             session);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
----------------------------------------------------------------------
diff --git a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
index 151ab62..30c01ac 100644
--- a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
+++ b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
@@ -81,7 +81,7 @@ public class MailboxManagerManagement extends StandardMBean implements MailboxMa
                      .build()) {
             session = mailboxManager.createSystemSession(username);
             mailboxManager.startProcessingRequest(session);
-            List<MailboxMetaData> mList = retrieveAllUserMailboxes(username, session);
+            List<MailboxMetaData> mList = retrieveAllUserMailboxes(session);
             for (MailboxMetaData aMList : mList) {
                 mailboxManager.deleteMailbox(aMList.getPath(), session);
             }
@@ -114,7 +114,7 @@ public class MailboxManagerManagement extends StandardMBean implements MailboxMa
                      .build()) {
             session = mailboxManager.createSystemSession(username);
             mailboxManager.startProcessingRequest(session);
-            List<MailboxMetaData> mList = retrieveAllUserMailboxes(username, session);
+            List<MailboxMetaData> mList = retrieveAllUserMailboxes(session);
             boxes = mList.stream()
                 .map(aMList -> aMList.getPath().getName())
                 .sorted()
@@ -211,12 +211,10 @@ public class MailboxManagerManagement extends StandardMBean implements MailboxMa
         }
     }
 
-    private List<MailboxMetaData> retrieveAllUserMailboxes(String username, MailboxSession session) throws MailboxException {
+    private List<MailboxMetaData> retrieveAllUserMailboxes(MailboxSession session) throws MailboxException {
         return mailboxManager.search(
-            MailboxQuery.builder()
-                .base(MailboxPath.forUser(username, ""))
-                .expression("*")
-                .mailboxSession(session)
+            MailboxQuery.privateMailboxesBuilder(session)
+                .matchesAllMailboxNames()
                 .build(),
             session);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/AbstractStorageQuota.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/AbstractStorageQuota.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/AbstractStorageQuota.java
index 816e83d..146e0c3 100755
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/AbstractStorageQuota.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/matchers/AbstractStorageQuota.java
@@ -35,10 +35,10 @@ import org.apache.james.mailbox.exception.BadCredentialsException;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.FetchGroupImpl;
 import org.apache.james.mailbox.model.MailboxMetaData;
-import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.MessageResult;
 import org.apache.james.mailbox.model.search.MailboxQuery;
+import org.apache.james.mailbox.model.search.Wildcard;
 import org.apache.james.user.api.UsersRepository;
 import org.apache.james.user.api.UsersRepositoryException;
 import org.apache.mailet.Experimental;
@@ -125,9 +125,8 @@ abstract public class AbstractStorageQuota extends AbstractQuotaMatcher {
             // get all mailboxes for the user to calculate the size
             // TODO: See JAMES-1198
             List<MailboxMetaData> mList = manager.search(
-                    MailboxQuery.builder()
-                        .base(MailboxPath.inbox(session))
-                        .mailboxSession(session)
+                    MailboxQuery.privateMailboxesBuilder(session)
+                        .expression(Wildcard.INSTANCE)
                         .build(),
                     session);
             for (MailboxMetaData aMList : mList) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
index 1354c20..eae7e13 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
@@ -139,7 +139,9 @@ public class GetMailboxesMethod implements Method {
 
     private Stream<Mailbox> retrieveAllMailboxes(MailboxSession mailboxSession) throws MailboxException {
         List<MailboxMetaData> userMailboxes = mailboxManager.search(
-            MailboxQuery.privateMailboxesBuilder(mailboxSession).privateMailboxes().build(),
+            MailboxQuery.privateMailboxesBuilder(mailboxSession)
+                .matchesAllMailboxNames()
+                .build(),
             mailboxSession);
         return userMailboxes
             .stream()

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java
index c51d6ad..500f9ab 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java
@@ -32,6 +32,7 @@ import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.search.MailboxQuery;
+import org.apache.james.mailbox.model.search.PrefixedWildcard;
 
 import com.github.fge.lambdas.Throwing;
 import com.github.fge.lambdas.functions.ThrowingFunction;
@@ -66,8 +67,7 @@ public class SystemMailboxesProviderImpl implements SystemMailboxesProvider {
     private Stream<MessageManager> searchMessageManagerByMailboxRole(Role aRole, MailboxSession session) throws MailboxException {
         ThrowingFunction<MailboxPath, MessageManager> loadMailbox = path -> mailboxManager.getMailbox(path, session);
         MailboxQuery mailboxQuery = MailboxQuery.privateMailboxesBuilder(session)
-            .privateMailboxes()
-            .expression(aRole.getDefaultMailbox())
+            .expression(new PrefixedWildcard(aRole.getDefaultMailbox()))
             .build();
         return mailboxManager.search(mailboxQuery, session)
             .stream()

http://git-wip-us.apache.org/repos/asf/james-project/blob/d1030584/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 be9713d..225d0bf 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
@@ -75,7 +75,7 @@ public class UserMailboxesService {
     public void deleteMailboxes(String username) throws MailboxException, UsersRepositoryException {
         usernamePreconditions(username);
         MailboxSession mailboxSession = mailboxManager.createSystemSession(USER_NAME);
-        listUserMailboxes(username, mailboxSession)
+        listUserMailboxes(mailboxSession)
             .map(MailboxMetaData::getPath)
             .forEach(Throwing.consumer(mailboxPath -> deleteMailbox(mailboxSession, mailboxPath)));
     }
@@ -83,7 +83,7 @@ public class UserMailboxesService {
     public List<MailboxResponse> listMailboxes(String username) throws MailboxException, UsersRepositoryException {
         usernamePreconditions(username);
         MailboxSession mailboxSession = mailboxManager.createSystemSession(USER_NAME);
-        return listUserMailboxes(username, mailboxSession)
+        return listUserMailboxes(mailboxSession)
             .map(mailboxMetaData -> new MailboxResponse(mailboxMetaData.getPath().getName()))
             .collect(Guavate.toImmutableList());
     }
@@ -105,7 +105,7 @@ public class UserMailboxesService {
     }
 
     private Stream<MailboxPath> listChildren(MailboxPath mailboxPath, MailboxSession mailboxSession) throws MailboxException {
-        return mailboxManager.search(createUserMailboxesQuery(mailboxPath.getUser()), mailboxSession)
+        return mailboxManager.search(createUserMailboxesQuery(mailboxSession), mailboxSession)
             .stream()
             .map(MailboxMetaData::getPath)
             .filter(path -> path.getHierarchyLevels(mailboxSession.getPathDelimiter()).contains(mailboxPath));
@@ -128,15 +128,13 @@ public class UserMailboxesService {
         return new MailboxPath(mailboxSession.getPersonalSpace(), username, mailboxName);
     }
 
-    private Stream<MailboxMetaData> listUserMailboxes(String username, MailboxSession mailboxSession) throws MailboxException {
-        return mailboxManager.search(createUserMailboxesQuery(username), mailboxSession)
+    private Stream<MailboxMetaData> listUserMailboxes(MailboxSession mailboxSession) throws MailboxException {
+        return mailboxManager.search(createUserMailboxesQuery(mailboxSession), mailboxSession)
             .stream();
     }
 
-    private MailboxQuery createUserMailboxesQuery(String username) {
-        return MailboxQuery.builder()
-            .username(username)
-            .privateMailboxes()
+    private MailboxQuery createUserMailboxesQuery(MailboxSession mailboxSession) {
+        return MailboxQuery.privateMailboxesBuilder(mailboxSession)
             .build();
     }
 


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


Mime
View raw message