james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r965270 [4/4] - in /james/imap/trunk: ./ api/src/main/java/org/apache/james/imap/api/ api/src/main/java/org/apache/james/imap/api/process/ deployment/src/test/java/org/apache/james/imap/functional/ jcr/src/main/java/org/apache/james/imap/jc...
Date Sun, 18 Jul 2010 18:18:10 GMT
Modified: james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java?rev=965270&r1=965269&r2=965270&view=diff
==============================================================================
--- james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
(original)
+++ james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
Sun Jul 18 18:18:08 2010
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
+import org.apache.james.imap.api.MailboxPath;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.mailbox.Mailbox;
 import org.apache.james.imap.mailbox.MailboxConstants;
@@ -64,11 +65,23 @@ public class TorqueMailboxManager extend
         mailboxes = new HashMap<String, TorqueMailbox>();
     }
 
-    public Mailbox getMailbox(String mailboxName, MailboxSession session)
+    public Mailbox getMailbox(MailboxPath path, MailboxSession session)
             throws MailboxException {
-        return doGetMailbox(mailboxName);
+        return doGetMailbox(getName(path));
     }
 
+    private String getName(MailboxPath path) {
+        StringBuffer sb = new StringBuffer();
+        sb.append(path.getNamespace());
+        sb.append(MailboxConstants.DEFAULT_DELIMITER);
+
+        if (path.getUser() != null) {
+            sb.append(path.getUser());
+            sb.append(MailboxConstants.DEFAULT_DELIMITER);
+        }
+        sb.append(path.getName());
+        return sb.toString();
+    }
     private TorqueMailbox doGetMailbox(String mailboxName)
             throws MailboxException {
         try {
@@ -97,8 +110,14 @@ public class TorqueMailboxManager extend
         }
     }
 
-    public void createMailbox(String namespaceName, MailboxSession mailboxSession)
+    public void createMailbox(MailboxPath path, MailboxSession mailboxSession)
             throws MailboxException {
+        String namespaceName = getName(path);
+        createMailbox(namespaceName, mailboxSession);
+        
+    }
+    
+    private void createMailbox(String namespaceName, MailboxSession mailboxSession) throws
MailboxException {
         getLog().debug("createMailbox " + namespaceName);
         final int length = namespaceName.length();
         if (length == 0) {
@@ -120,13 +139,13 @@ public class TorqueMailboxManager extend
                     if (index > 0 && count++ > 1) {
                         final String mailbox = namespaceName
                                 .substring(0, index);
-                        if (!mailboxExists(mailbox, mailboxSession)) {
+                        if (!mailboxExists(getMailboxPath(mailbox), mailboxSession)) {
                             doCreate(mailbox);
                         }
                     }
                     index = namespaceName.indexOf(MailboxConstants.DEFAULT_DELIMITER, ++index);
                 }
-                if (mailboxExists(namespaceName, mailboxSession)) {
+                if (mailboxExists(getMailboxPath(namespaceName), mailboxSession)) {
                     throw new MailboxExistsException(namespaceName); 
                 } else {
                     doCreate(namespaceName);
@@ -147,8 +166,10 @@ public class TorqueMailboxManager extend
         }
     }
 
-    public void deleteMailbox(String mailboxName, MailboxSession session)
+    public void deleteMailbox(MailboxPath path, MailboxSession session)
             throws MailboxException {
+        String mailboxName = getName(path);
+
         getLog().info("deleteMailbox " + mailboxName);
         synchronized (mailboxes) {
             try {
@@ -170,12 +191,15 @@ public class TorqueMailboxManager extend
     }
 
     @SuppressWarnings("unchecked")
-    public void renameMailbox(String from, String to, MailboxSession session)
+    public void renameMailbox(MailboxPath fromPath, MailboxPath toPath, MailboxSession session)
             throws MailboxException {
+        String from = getName(fromPath);
+        String to = getName(toPath);
+
         getLog().debug("renameMailbox " + from + " to " + to);
         try {
             synchronized (mailboxes) {
-                if (mailboxExists(to, session)) {
+                if (mailboxExists(toPath, session)) {
                     throw new MailboxExistsException(to);
                 }
                 // TODO put this into a serilizable transaction
@@ -222,10 +246,10 @@ public class TorqueMailboxManager extend
         }
     }
 
-    public void copyMessages(MessageRange set, String from, String to,
+    public void copyMessages(MessageRange set, MailboxPath from, MailboxPath to,
             MailboxSession session) throws MailboxException {
-        TorqueMailbox toMailbox = doGetMailbox(to);
-        TorqueMailbox fromMailbox = doGetMailbox(from);
+        TorqueMailbox toMailbox = doGetMailbox(getName(to));
+        TorqueMailbox fromMailbox = doGetMailbox(getName(from));
         fromMailbox.copyTo(set, toMailbox, session);
     }
 
@@ -234,36 +258,37 @@ public class TorqueMailboxManager extend
             throws MailboxException {
         final char localWildcard = mailboxExpression.getLocalWildcard();
         final char freeWildcard = mailboxExpression.getFreeWildcard();
-        final String base = mailboxExpression.getBase();
+        final String baseName = mailboxExpression.getBase().getName();
         final int baseLength;
-        if (base == null) {
+        if (baseName == null) {
             baseLength = 0;
         } else {
-            baseLength = base.length();
+            baseLength = baseName.length();
         }
-
-        final String search = mailboxExpression.getCombinedName(
-                MailboxConstants.DEFAULT_DELIMITER).replace(freeWildcard, SQL_WILDCARD_CHAR)
-                .replace(localWildcard, SQL_WILDCARD_CHAR);
+        final String combinedName = mailboxExpression.getCombinedName()
+                                    .replace(freeWildcard, SQL_WILDCARD_CHAR)
+                                    .replace(localWildcard, SQL_WILDCARD_CHAR);
+        final MailboxPath search = new MailboxPath(mailboxExpression.getBase(), combinedName);
 
         Criteria criteria = new Criteria();
-        criteria.add(MailboxRowPeer.NAME, (Object) (search), Criteria.LIKE);
+        criteria.add(MailboxRowPeer.NAME, (Object) getName(search), Criteria.LIKE);
         try {
             List mailboxRows = MailboxRowPeer.doSelect(criteria);
             List<MailboxMetaData> results = new ArrayList<MailboxMetaData>(mailboxRows.size());
             for (Iterator iter = mailboxRows.iterator(); iter.hasNext();) {
                 final MailboxRow mailboxRow = (MailboxRow) iter.next();
-                final String name = mailboxRow.getName();
-                if (name.startsWith(base)) {
+                final MailboxPath sPath = getMailboxPath(mailboxRow.getName());
+                final String name = sPath.getName();
+                if (name.startsWith(baseName)) {
                     final String match = name.substring(baseLength);
-                    if (mailboxExpression.isExpressionMatch(match, MailboxConstants.DEFAULT_DELIMITER))
{
+                    if (mailboxExpression.isExpressionMatch(match)) {
                         final MailboxMetaData.Children inferiors; 
-                        if (hasChildren(name)) {
+                        if (hasChildren(mailboxRow.getName())) {
                             inferiors = MailboxMetaData.Children.HAS_CHILDREN;
                         } else {
                             inferiors = MailboxMetaData.Children.HAS_NO_CHILDREN;
                         }
-                        results.add(new SimpleMailboxMetaData(name, ".", inferiors, Selectability.NONE));
+                        results.add(new SimpleMailboxMetaData(sPath, MailboxConstants.DEFAULT_DELIMITER_STRING,
inferiors, Selectability.NONE));
                     }
                 }
             }
@@ -289,9 +314,10 @@ public class TorqueMailboxManager extend
         return !mailboxes.isEmpty();
     }
     
-    public boolean mailboxExists(String mailboxName, MailboxSession session)
+    public boolean mailboxExists(MailboxPath path, MailboxSession session)
             throws MailboxException {
         Criteria c = new Criteria();
+        String mailboxName = getName(path);
         c.add(MailboxRowPeer.NAME, mailboxName);
         CountHelper countHelper = new CountHelper();
         int count;
@@ -315,6 +341,14 @@ public class TorqueMailboxManager extend
         }
     }
 
+    public MailboxPath getMailboxPath(String name) {
+        String nameParts[] = name.split("\\" +MailboxConstants.DEFAULT_DELIMITER_STRING,3);
+        if (nameParts.length < 3) {
+            return new MailboxPath(nameParts[0], null, nameParts[1]);
+        }
+        return new MailboxPath(nameParts[0], nameParts[1], nameParts[2]);
+
+    }
     public void deleteEverything() throws MailboxException {
         try {
             MailboxRowPeer.doDelete(new Criteria().and(
@@ -326,8 +360,8 @@ public class TorqueMailboxManager extend
         }
     }
 
-    public void addListener(String mailboxName, MailboxListener listener, MailboxSession
session) throws MailboxException {
-        final TorqueMailbox mailbox = doGetMailbox(mailboxName);
+    public void addListener(MailboxPath path, MailboxListener listener, MailboxSession session)
throws MailboxException {
+        final TorqueMailbox mailbox = doGetMailbox(getName(path));
         mailbox.addListener(listener);
     }
 

Modified: james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/UidChangeTracker.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/UidChangeTracker.java?rev=965270&r1=965269&r2=965270&view=diff
==============================================================================
--- james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/UidChangeTracker.java
(original)
+++ james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/UidChangeTracker.java
Sun Jul 18 18:18:08 2010
@@ -30,6 +30,7 @@ import java.util.TreeSet;
 
 import javax.mail.Flags;
 
+import org.apache.james.imap.api.MailboxPath;
 import org.apache.james.imap.mailbox.MailboxConstants;
 import org.apache.james.imap.mailbox.Mailbox;
 import org.apache.james.imap.mailbox.MailboxListener;
@@ -44,19 +45,19 @@ public class UidChangeTracker implements
 
     private long lastUid;
 
-    private String name;
+    private MailboxPath path;
 
-    public UidChangeTracker(long lastUid, String name) {
+    public UidChangeTracker(long lastUid, MailboxPath path) {
         this.lastUid = lastUid;
         eventDispatcher = new MailboxEventDispatcher();
         cache = new TreeMap<Long, Flags>();
-        this.name = name;
+        this.path = path;
     }
 
     public synchronized void expunged(final Collection<Long> uidsExpunged) {
         for (Long uid:uidsExpunged) {
             cache.remove(uid);
-            eventDispatcher.expunged(uid, 0, name);
+            eventDispatcher.expunged(uid, 0, path);
         }
     }
 
@@ -81,7 +82,7 @@ public class UidChangeTracker implements
                     lastFlags = cachedFlags;
                 }
                 if (!newFlags.equals(lastFlags)) {
-                    eventDispatcher.flagsUpdated(uid, sessionId, name, lastFlags, newFlags);
+                    eventDispatcher.flagsUpdated(uid, sessionId, path, lastFlags, newFlags);
                 }
                 cache.put(uid, newFlags);
             }
@@ -101,7 +102,7 @@ public class UidChangeTracker implements
 
         for (Iterator<Long> iter = expectedSet.iterator(); iter.hasNext();) {
             long uid = ((Long) iter.next()).longValue();
-            eventDispatcher.expunged(uid, Mailbox.ANONYMOUS_SESSION, name);
+            eventDispatcher.expunged(uid, Mailbox.ANONYMOUS_SESSION, path);
         }
     }
 
@@ -109,11 +110,11 @@ public class UidChangeTracker implements
         if (flags != null) {
             final Flags cachedFlags = cache.get(uid);
             if (cachedFlags == null || !flags.equals(cachedFlags)) {
-                eventDispatcher.flagsUpdated(uid, Mailbox.ANONYMOUS_SESSION, name, cachedFlags,
flags);
+                eventDispatcher.flagsUpdated(uid, Mailbox.ANONYMOUS_SESSION, path, cachedFlags,
flags);
             }
         }
         if (uid > lastUid) {
-            eventDispatcher.added(uid, Mailbox.ANONYMOUS_SESSION, name);
+            eventDispatcher.added(uid, Mailbox.ANONYMOUS_SESSION, path);
             lastUid = uid;
         }
         cache.put(uid, flags);
@@ -138,11 +139,11 @@ public class UidChangeTracker implements
     }
     
     public void mailboxDeleted(long sessionId) {
-        eventDispatcher.mailboxDeleted(sessionId, name);
+        eventDispatcher.mailboxDeleted(sessionId, path);
     }
 
-    public void reportRenamed(String to) {
-        eventDispatcher.mailboxRenamed(name, to, Mailbox.ANONYMOUS_SESSION);
-        name = to;
+    public void reportRenamed(MailboxPath to) {
+        eventDispatcher.mailboxRenamed(path, to, Mailbox.ANONYMOUS_SESSION);
+        path = to;
     }
 }



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