james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1102863 - in /james/mailbox/trunk: api/src/main/java/org/apache/james/mailbox/ api/src/test/java/org/apache/james/mailbox/ maildir/src/main/java/org/apache/james/mailbox/maildir/ maildir/src/main/java/org/apache/james/mailbox/maildir/mail/...
Date Fri, 13 May 2011 18:56:29 GMT
Author: norman
Date: Fri May 13 18:56:28 2011
New Revision: 1102863

URL: http://svn.apache.org/viewvc?rev=1102863&view=rev
Log:
start some work related to namespace handling. See MAILBOX-11

Modified:
    james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxPath.java
    james/mailbox/trunk/api/src/test/java/org/apache/james/mailbox/AbstractMailboxManagerTest.java
    james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMailboxSessionMapperFactory.java
    james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
    james/mailbox/trunk/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerTest.java

Modified: james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxPath.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxPath.java?rev=1102863&r1=1102862&r2=1102863&view=diff
==============================================================================
--- james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxPath.java (original)
+++ james/mailbox/trunk/api/src/main/java/org/apache/james/mailbox/MailboxPath.java Fri May
13 18:56:28 2011
@@ -31,6 +31,8 @@ public class MailboxPath {
     private String user;
     private String name;
 
+
+    
     public MailboxPath(String namespace, String user, String name) {
         this.namespace = namespace;
         this.user = user;
@@ -178,16 +180,49 @@ public class MailboxPath {
             result = PRIME * result + getNamespace().hashCode();
         return result;
     }
+    
+    /**
+     * Return the full name of the {@link MailboxPath}, which is constructed via the {@link
#namespace} and {@link #name}
+     * 
+     * @param delimiter
+     * @return fullName
+     */
+    public String getFullName(char delimiter) {
+        return namespace + delimiter + name;
+    }
 
     /**
      * Return a {@link MailboxPath} which represent the INBOX of the given
-     * username
+     * session
      * 
-     * @param username
+     * @param session
      * @return inbox
      */
-    public static MailboxPath inbox(String username) {
-        return new MailboxPath(MailboxConstants.USER_NAMESPACE, username, MailboxConstants.INBOX);
+    public static MailboxPath inbox(MailboxSession session) {
+        return new MailboxPath(session.getPersonalSpace(), session.getUser().getUserName(),
MailboxConstants.INBOX);
+    }
+    
+    /**
+     * Create a {@link MailboxPath} by parsing the given full mailboxname (which included
the namespace)
+     * 
+     * @param session
+     * @param fullmailboxname
+     * @return path
+     */
+    public static MailboxPath parse(MailboxSession session, String fullmailboxname) {
+        char delimiter = session.getPathDelimiter();
+        int i = fullmailboxname.indexOf(delimiter);
+        String namespace = fullmailboxname.substring(0, i);
+        String mailbox = fullmailboxname.substring(i + 1, fullmailboxname.length());
+        String username = null;
+        if (namespace == null || namespace.trim().equals("")) {
+            namespace = MailboxConstants.USER_NAMESPACE;
+        } 
+        if (namespace.equals(session.getPersonalSpace())) {
+            username = session.getUser().getUserName();
+        }
+        return new MailboxPath(namespace, username, mailbox);
+
     }
 
 }

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=1102863&r1=1102862&r2=1102863&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
Fri May 13 18:56:28 2011
@@ -43,7 +43,7 @@ public abstract class AbstractMailboxMan
         manager.startProcessingRequest(session);
         
         
-        MailboxPath inbox = MailboxPath.inbox(USER1);
+        MailboxPath inbox = MailboxPath.inbox(session);
         Assert.assertFalse(manager.mailboxExists(inbox, session));
         
         manager.createMailbox(inbox, session);

Modified: james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMailboxSessionMapperFactory.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMailboxSessionMapperFactory.java?rev=1102863&r1=1102862&r2=1102863&view=diff
==============================================================================
--- james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMailboxSessionMapperFactory.java
(original)
+++ james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMailboxSessionMapperFactory.java
Fri May 13 18:56:28 2011
@@ -41,7 +41,7 @@ public class MaildirMailboxSessionMapper
     @Override
     protected MailboxMapper<Integer> createMailboxMapper(MailboxSession session)
             throws MailboxException {
-        return new MaildirMailboxMapper(store);
+        return new MaildirMailboxMapper(store, session);
     }
 
     @Override

Modified: james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java?rev=1102863&r1=1102862&r2=1102863&view=diff
==============================================================================
--- james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
(original)
+++ james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java
Fri May 13 18:56:28 2011
@@ -32,6 +32,7 @@ import org.apache.james.mailbox.MailboxE
 import org.apache.james.mailbox.MailboxExistsException;
 import org.apache.james.mailbox.MailboxNotFoundException;
 import org.apache.james.mailbox.MailboxPath;
+import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.maildir.MaildirFolder;
 import org.apache.james.mailbox.maildir.MaildirMessageName;
 import org.apache.james.mailbox.maildir.MaildirStore;
@@ -51,9 +52,12 @@ public class MaildirMailboxMapper extend
      * A request-scoped list of mailboxes in order to refer to them via id
      */
     private ArrayList<Mailbox<Integer>> mailboxCache = new ArrayList<Mailbox<Integer>>();
+
+    private final MailboxSession session;
     
-    public MaildirMailboxMapper(MaildirStore maildirStore) {
+    public MaildirMailboxMapper(MaildirStore maildirStore, MailboxSession session) {
         this.maildirStore = maildirStore;
+        this.session = session;
     }
 
     /*
@@ -259,7 +263,7 @@ public class MaildirMailboxMapper extend
             }
             
             // Special case for INBOX: Let's use the user's folder.
-            MailboxPath inboxMailboxPath = MailboxPath.inbox(userName);
+            MailboxPath inboxMailboxPath = MailboxPath.inbox(session);
             mailboxList.add(maildirStore.loadMailbox(inboxMailboxPath));
             
             // List all INBOX sub folders.

Modified: james/mailbox/trunk/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerTest.java?rev=1102863&r1=1102862&r2=1102863&view=diff
==============================================================================
--- james/mailbox/trunk/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerTest.java
(original)
+++ james/mailbox/trunk/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxManagerTest.java
Fri May 13 18:56:28 2011
@@ -121,7 +121,7 @@ public class MaildirMailboxManagerTest e
             manager.createMailbox(new MailboxPath(MailboxConstants.USER_NAMESPACE, user,
"INBOX.testfolder"), session);
             
             // this threw NPE
-            manager.getMailbox(MailboxPath.inbox(user), session).appendMessage(new ByteArrayInputStream("Subject:
test\r\n\r\ntestmail".getBytes()), new Date(), session, false, new Flags());
+            manager.getMailbox(MailboxPath.inbox(session), session).appendMessage(new ByteArrayInputStream("Subject:
test\r\n\r\ntestmail".getBytes()), new Date(), session, false, new Flags());
 
         }
 



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