james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject svn commit: r1683057 - in /james/mailbox/trunk: api/src/test/java/org/apache/james/mailbox/ memory/ memory/src/main/java/org/apache/james/mailbox/inmemory/mail/ memory/src/test/java/org/apache/james/mailbox/inmemory/ store/src/main/java/org/apache/jame...
Date Tue, 02 Jun 2015 08:11:56 GMT
Author: eric
Date: Tue Jun  2 08:11:56 2015
New Revision: 1683057

URL: http://svn.apache.org/r1683057
Log:
MailboxQuery ignore namespace, patch contributed by Benoit Tellier (MAILBOX-11)

Modified:
    james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/AbstractMailboxManagerTest.java
    james/mailbox/trunk/memory/pom.xml
    james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
    james/mailbox/trunk/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java
    james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java

Modified: james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/AbstractMailboxManagerTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/AbstractMailboxManagerTest.java?rev=1683057&r1=1683056&r2=1683057&view=diff
==============================================================================
--- james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/AbstractMailboxManagerTest.java
(original)
+++ james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/AbstractMailboxManagerTest.java
Tue Jun  2 08:11:56 2015
@@ -45,8 +45,8 @@ import org.slf4j.LoggerFactory;
  */
 public abstract class AbstractMailboxManagerTest {
     
-    private final static String USER_1 = "USER_1";
-    private final static String USER_2 = "USER_2";
+    public final static String USER_1 = "USER_1";
+    public final static String USER_2 = "USER_2";
 
     /**
      * The mailboxManager that needs to get instanciated

Modified: james/mailbox/trunk/memory/pom.xml
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/memory/pom.xml?rev=1683057&r1=1683056&r2=1683057&view=diff
==============================================================================
--- james/mailbox/trunk/memory/pom.xml (original)
+++ james/mailbox/trunk/memory/pom.xml Tue Jun  2 08:11:56 2015
@@ -70,5 +70,10 @@
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>

Modified: james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java?rev=1683057&r1=1683056&r2=1683057&view=diff
==============================================================================
--- james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
(original)
+++ james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java
Tue Jun  2 08:11:56 2015
@@ -79,13 +79,19 @@ public class InMemoryMailboxMapper imple
         final String regex = path.getName().replace("%", ".*");
         List<Mailbox<Long>> results = new ArrayList<Mailbox<Long>>();
         for (final Mailbox<Long> mailbox:mailboxesById.values()) {
-            if (mailbox.getName().matches(regex)) {
+            if (mailboxMatchesRegex(mailbox, path, regex)) {
                 results.add(mailbox);
             }
         }
         return results;
     }
 
+    private boolean mailboxMatchesRegex(Mailbox<Long> mailbox, MailboxPath path, String
regex) {
+        return mailbox.getNamespace().equals(path.getNamespace())
+            && mailbox.getUser().equals(path.getUser())
+            && mailbox.getName().matches(regex);
+    }
+
     /**
      * @see org.apache.james.mailbox.store.mail.MailboxMapper#save(org.apache.james.mailbox.store.mail.model.Mailbox)
      */

Modified: james/mailbox/trunk/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java?rev=1683057&r1=1683056&r2=1683057&view=diff
==============================================================================
--- james/mailbox/trunk/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java
(original)
+++ james/mailbox/trunk/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManagerTest.java
Tue Jun  2 08:11:56 2015
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.james.mailbox.inmemory;
 
+import static org.assertj.core.api.Assertions.assertThat;
+
 import org.apache.james.mailbox.AbstractMailboxManagerTest;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.acl.GroupMembershipResolver;
@@ -26,17 +28,25 @@ import org.apache.james.mailbox.acl.Simp
 import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
 import org.apache.james.mailbox.exception.BadCredentialsException;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxMetaData;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MailboxQuery;
 import org.apache.james.mailbox.store.MockAuthenticator;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Test;
 import org.slf4j.LoggerFactory;
 
+import java.util.List;
+
 /**
  * InMemoryMailboxManagerTest that extends the MailboxManagerTest.
  */
 public class InMemoryMailboxManagerTest extends AbstractMailboxManagerTest {
-    
+
+    private MailboxSession session;
+
     /**
      * Setup the mailboxManager.
      * 
@@ -45,6 +55,9 @@ public class InMemoryMailboxManagerTest
     @Before
     public void setup() throws Exception {
         createMailboxManager();
+
+        session = getMailboxManager().createSystemSession(USER_1, LoggerFactory.getLogger("Test"));
+        getMailboxManager().startProcessingRequest(session);
     }
     
     /**
@@ -55,8 +68,9 @@ public class InMemoryMailboxManagerTest
      */
     @After
     public void tearDown() throws BadCredentialsException, MailboxException {
-        MailboxSession session = getMailboxManager().createSystemSession("test", LoggerFactory.getLogger("Test"));
-        session.close();
+        getMailboxManager().logout(session, true);
+        getMailboxManager().endProcessingRequest(session);
+        getMailboxManager().createSystemSession("test", LoggerFactory.getLogger("Test")).close();
     }
 
     /* (non-Javadoc)
@@ -75,5 +89,23 @@ public class InMemoryMailboxManagerTest
         setMailboxManager(mailboxManager);
 
     }
+
+    @Test
+    public void searchShouldNotReturnResultsFromOtherNamespaces() throws Exception {
+        getMailboxManager().createMailbox(new MailboxPath("#namespace", USER_1, "Other"),
session);
+        getMailboxManager().createMailbox(MailboxPath.inbox(session), session);
+        List<MailboxMetaData> metaDatas = getMailboxManager().search(new MailboxQuery(new
MailboxPath("#private", USER_1, ""), "*", '.'), session);
+        assertThat(metaDatas).hasSize(1);
+        assertThat(metaDatas.get(0).getPath()).isEqualTo(MailboxPath.inbox(session));
+    }
+
+    @Test
+    public void searchShouldNotReturnResultsFromOtherUsers() throws Exception {
+        getMailboxManager().createMailbox(new MailboxPath("#namespace", USER_2, "Other"),
session);
+        getMailboxManager().createMailbox(MailboxPath.inbox(session), session);
+        List<MailboxMetaData> metaDatas = getMailboxManager().search(new MailboxQuery(new
MailboxPath("#private", USER_1, ""), "*", '.'), session);
+        assertThat(metaDatas).hasSize(1);
+        assertThat(metaDatas.get(0).getPath()).isEqualTo(MailboxPath.inbox(session));
+    }
     
 }

Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java?rev=1683057&r1=1683056&r2=1683057&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
(original)
+++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
Tue Jun  2 08:11:56 2015
@@ -512,17 +512,19 @@ public class StoreMailboxManager<Id> imp
         final List<MailboxMetaData> results = new ArrayList<MailboxMetaData>(mailboxes.size());
         for (Mailbox<Id> mailbox : mailboxes) {
             final String name = mailbox.getName();
-            if (name.startsWith(baseName)) {
-                final String match = name.substring(baseLength);
-                if (mailboxExpression.isExpressionMatch(match)) {
-                    final MailboxMetaData.Children inferiors;
-                    if (mapper.hasChildren(mailbox, session.getPathDelimiter())) {
-                        inferiors = MailboxMetaData.Children.HAS_CHILDREN;
-                    } else {
-                        inferiors = MailboxMetaData.Children.HAS_NO_CHILDREN;
+            if(belongsToNamespaceAndUser(mailboxExpression.getBase(), mailbox)) {
+                if (name.startsWith(baseName)) {
+                    final String match = name.substring(baseLength);
+                    if (mailboxExpression.isExpressionMatch(match)) {
+                        final MailboxMetaData.Children inferiors;
+                        if (mapper.hasChildren(mailbox, session.getPathDelimiter())) {
+                            inferiors = MailboxMetaData.Children.HAS_CHILDREN;
+                        } else {
+                            inferiors = MailboxMetaData.Children.HAS_NO_CHILDREN;
+                        }
+                        MailboxPath mailboxPath = new MailboxPath(mailbox.getNamespace(),
mailbox.getUser(), name);
+                        results.add(new SimpleMailboxMetaData(mailboxPath, getDelimiter(),
inferiors, Selectability.NONE));
                     }
-                    MailboxPath mailboxPath = new MailboxPath(mailbox.getNamespace(), mailbox.getUser(),
name);
-                    results.add(new SimpleMailboxMetaData(mailboxPath, getDelimiter(), inferiors,
Selectability.NONE));
                 }
             }
         }
@@ -530,6 +532,15 @@ public class StoreMailboxManager<Id> imp
         return results;
     }
 
+    public boolean belongsToNamespaceAndUser(MailboxPath base, Mailbox<Id> mailbox)
{
+        if (mailbox.getUser() == null) {
+            return  base.getUser() == null
+                && mailbox.getNamespace().equals(base.getNamespace());
+        }
+        return mailbox.getNamespace().equals(base.getNamespace())
+            && mailbox.getUser().equals(base.getUser());
+    }
+
     @Override
     public boolean mailboxExists(MailboxPath mailboxPath, MailboxSession session) throws
MailboxException {
         try {



---------------------------------------------------------------------
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