james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joac...@apache.org
Subject svn commit: r481374 - in /james/server/trunk/src: java/org/apache/james/mailboxmanager/ java/org/apache/james/mailboxmanager/impl/ java/org/apache/james/mailboxmanager/mailbox/ java/org/apache/james/mailboxmanager/repository/ java/org/apache/james/mail...
Date Fri, 01 Dec 2006 20:18:49 GMT
Author: joachim
Date: Fri Dec  1 12:18:48 2006
New Revision: 481374

URL: http://svn.apache.org/viewvc?view=rev&rev=481374
Log:
 - added explicit GeneralMailbox.remove(set) method
 - TorqueMailbox works with MessageResult.KEY now
 - MailboxManagerMailRepository works with internal keys now instead of uids
 - AbstractGeneralMailbox forwards Mailbox methods to GeneralMailbox with keys

Added:
    james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/KeyBidiMap.java
      - copied, changed from r477670, james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMap.java
    james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/KeyBidiMapImpl.java
      - copied, changed from r477670, james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMapImpl.java
    james/server/trunk/src/java/org/apache/james/mailboxmanager/util/AbstractLogFactoryAware.java
      - copied, changed from r477670, james/server/trunk/src/java/org/apache/james/mailboxmanager/util/AbstractLogEnabled.java
    james/server/trunk/src/java/org/apache/james/mailboxmanager/util/AvalonLogFactory.java
    james/server/trunk/src/java/org/apache/james/mailboxmanager/util/LogAware.java
    james/server/trunk/src/java/org/apache/james/mailboxmanager/util/LogFactoryAware.java
    james/server/trunk/src/java/org/apache/james/mailboxmanager/util/MyLogFactory.java
    james/server/trunk/src/java/org/apache/james/mailboxmanager/util/UidToKeyConverter.java
    james/server/trunk/src/java/org/apache/james/mailboxmanager/util/UidToKeyConverterImpl.java
    james/server/trunk/src/test/org/apache/james/mailboxmanager/util/UidToKeyConverterTest.java
Removed:
    james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMap.java
    james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMapImpl.java
    james/server/trunk/src/java/org/apache/james/mailboxmanager/util/AbstractLogEnabled.java
Modified:
    james/server/trunk/src/java/org/apache/james/mailboxmanager/GeneralMessageSet.java
    james/server/trunk/src/java/org/apache/james/mailboxmanager/impl/GeneralMessageSetImpl.java
    james/server/trunk/src/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java
    james/server/trunk/src/java/org/apache/james/mailboxmanager/mailbox/AbstractGeneralMailbox.java
    james/server/trunk/src/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java
    james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java
    james/server/trunk/src/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
    james/server/trunk/src/java/org/apache/james/mailboxmanager/wrapper/SessionMailboxWrapper.java

Modified: james/server/trunk/src/java/org/apache/james/mailboxmanager/GeneralMessageSet.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailboxmanager/GeneralMessageSet.java?view=diff&rev=481374&r1=481373&r2=481374
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailboxmanager/GeneralMessageSet.java (original)
+++ james/server/trunk/src/java/org/apache/james/mailboxmanager/GeneralMessageSet.java Fri Dec  1 12:18:48 2006
@@ -10,7 +10,7 @@
 
 public interface GeneralMessageSet {
     
-    public static int TYPE_NONE=0;
+    public static int TYPE_NOTHING=0;
     public static int TYPE_MSN=1;
     public static int TYPE_UID=2;
     public static int TYPE_KEY=4;

Modified: james/server/trunk/src/java/org/apache/james/mailboxmanager/impl/GeneralMessageSetImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailboxmanager/impl/GeneralMessageSetImpl.java?view=diff&rev=481374&r1=481373&r2=481374
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailboxmanager/impl/GeneralMessageSetImpl.java (original)
+++ james/server/trunk/src/java/org/apache/james/mailboxmanager/impl/GeneralMessageSetImpl.java Fri Dec  1 12:18:48 2006
@@ -15,6 +15,8 @@
 
     private int msnTo;
 
+    private String key;
+
     private GeneralMessageSetImpl() {
     }
 
@@ -43,8 +45,7 @@
     }
 
     public String getKey() throws IllegalStateException {
-        // TODO Auto-generated method stub
-        return null;
+        return key;
     }
 
     public Message getMessage() throws IllegalStateException {
@@ -130,6 +131,19 @@
         gms.type = TYPE_MSN;
         gms.msnFrom = msn;
         gms.msnTo = msn;
+        return gms;
+    }
+
+    public static GeneralMessageSet oneKey(String key) {
+        GeneralMessageSetImpl gms = new GeneralMessageSetImpl();
+        gms.type = TYPE_KEY;
+        gms.key=key;
+        return gms; 
+    }
+
+    public static GeneralMessageSet nothing() {
+        GeneralMessageSetImpl gms = new GeneralMessageSetImpl();
+        gms.type = TYPE_NOTHING;
         return gms;
     }
 }

Modified: james/server/trunk/src/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java?view=diff&rev=481374&r1=481373&r2=481374
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java (original)
+++ james/server/trunk/src/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java Fri Dec  1 12:18:48 2006
@@ -17,6 +17,7 @@
     private Flags flags;
     private int size;
     private Date internalDate;
+    private String key;
     
 
     public MessageResultImpl(long uid) {
@@ -83,8 +84,7 @@
     }
 
     public String getKey() {
-        // TODO Auto-generated method stub
-        return null;
+        return key;
     }
 
     public void setUid(long uid) {
@@ -159,6 +159,10 @@
         }
         throw new IllegalArgumentException("unknown Flag: "+flag);
 
+    }
+
+    public void setKey(String key) {
+        this.key=key;
     }
 
 }

Modified: james/server/trunk/src/java/org/apache/james/mailboxmanager/mailbox/AbstractGeneralMailbox.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailboxmanager/mailbox/AbstractGeneralMailbox.java?view=diff&rev=481374&r1=481373&r2=481374
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailboxmanager/mailbox/AbstractGeneralMailbox.java (original)
+++ james/server/trunk/src/java/org/apache/james/mailboxmanager/mailbox/AbstractGeneralMailbox.java Fri Dec  1 12:18:48 2006
@@ -19,38 +19,53 @@
 
 package org.apache.james.mailboxmanager.mailbox;
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
 
 import javax.mail.internet.MimeMessage;
 
 import org.apache.james.mailboxmanager.MailboxManagerException;
-import org.apache.james.mailboxmanager.util.AbstractLogEnabled;
-
-public abstract class AbstractGeneralMailbox extends AbstractLogEnabled implements Mailbox {
+import org.apache.james.mailboxmanager.MessageResult;
+import org.apache.james.mailboxmanager.impl.GeneralMessageSetImpl;
+import org.apache.james.mailboxmanager.util.AbstractLogFactoryAware;
 
+public abstract class AbstractGeneralMailbox extends AbstractLogFactoryAware implements GeneralMailbox {
+    
     public Collection list() throws MailboxManagerException {
-        // TODO Auto-generated method stub
-        return null;
+        MessageResult[] messageResult=getMessages(GeneralMessageSetImpl.all(), MessageResult.KEY);
+        Collection result=new ArrayList(messageResult.length);
+        for (int i = 0; i < messageResult.length; i++) {
+            result.add(messageResult[i].getKey());
+        }
+        return result;
     }
 
     public void remove(String key) throws MailboxManagerException {
-        // TODO Auto-generated method stub
-        
+        remove(GeneralMessageSetImpl.oneKey(key));
     }
 
     public MimeMessage retrieve(String key) throws MailboxManagerException {
-        // TODO Auto-generated method stub
-        return null;
+        MessageResult[] result = getMessages(GeneralMessageSetImpl.oneKey(key),
+                MessageResult.MIME_MESSAGE);
+        if (result != null && result.length == 1) {
+            return result[0].getMimeMessage();
+        } else {
+            return null;
+        }
     }
 
     public String store(MimeMessage message) throws MailboxManagerException {
-        // TODO Auto-generated method stub
-        return null;
+        MessageResult result=appendMessage(message, new Date(), MessageResult.KEY);
+        return result.getKey();
     }
 
     public String update(String key, MimeMessage message) throws MailboxManagerException {
-        // TODO Auto-generated method stub
-        return null;
+        MessageResult result=updateMessage(GeneralMessageSetImpl.oneKey(key),message, MessageResult.KEY);
+        return result.getKey();
     }
+    
+    
 
 }

Modified: james/server/trunk/src/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java?view=diff&rev=481374&r1=481373&r2=481374
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java (original)
+++ james/server/trunk/src/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java Fri Dec  1 12:18:48 2006
@@ -89,6 +89,9 @@
      */
 
     MessageResult[] getMessages(GeneralMessageSet set, int result) throws MailboxManagerException;
+    
+    void remove(GeneralMessageSet set)
+            throws MailboxManagerException;
 
 
 }

Copied: james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/KeyBidiMap.java (from r477670, james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMap.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/KeyBidiMap.java?view=diff&rev=481374&p1=james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMap.java&r1=477670&p2=james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/KeyBidiMap.java&r2=481374
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMap.java (original)
+++ james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/KeyBidiMap.java Fri Dec  1 12:18:48 2006
@@ -26,20 +26,20 @@
  *
  */
 
-public interface UidToKeyBidiMap {
+public interface KeyBidiMap {
 
-    boolean containsKey(String key);
+    boolean containsExternalKey(String externalKey);
 
-    void put(String key, long uid);
+    void put(String externalKey, String internalKey);
 
-    void removeByKey(String key);
+    void removeByExternalKey(String key);
 
-    String[] getKeys();
+    String[] getExternalKeys();
 
-    String getByUid(long uid);
+    String getByInternalKey(String internalKey);
 
-    void retainAllListedAndAddedByKeys(String[] keysBefore, Collection keys);
+    void retainAllListedAndAddedByExternalKeys(String[] externalKeysBefore, Collection externalKeys);
 
-    long getByKey(String key);
+    String getByExternalKey(String externalKey);
 
 }

Copied: james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/KeyBidiMapImpl.java (from r477670, james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMapImpl.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/KeyBidiMapImpl.java?view=diff&rev=481374&p1=james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMapImpl.java&r1=477670&p2=james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/KeyBidiMapImpl.java&r2=481374
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMapImpl.java (original)
+++ james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/KeyBidiMapImpl.java Fri Dec  1 12:18:48 2006
@@ -1,3 +1,22 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
 package org.apache.james.mailboxmanager.repository;
 
 import java.util.ArrayList;
@@ -7,62 +26,53 @@
 import java.util.HashSet;
 import java.util.Map;
 
-public class UidToKeyBidiMapImpl  implements UidToKeyBidiMap {
+public class KeyBidiMapImpl  implements KeyBidiMap {
 
-        private Map keyToUid;
+        private Map externalToInternal;
 
-        private Map uidToKey;
+        private Map internalToExternal;
 
-        public UidToKeyBidiMapImpl() {
-            keyToUid = new HashMap();
-            uidToKey = new HashMap();
+        public KeyBidiMapImpl() {
+            externalToInternal = new HashMap();
+            internalToExternal = new HashMap();
         }
 
-        public synchronized String[] getKeys() {
-            final ArrayList al = new ArrayList(keyToUid.keySet());
+        public synchronized String[] getExternalKeys() {
+            final ArrayList al = new ArrayList(externalToInternal.keySet());
             final String[] keys = (String[]) al.toArray(new String[0]);
             return keys;
         }
 
-        public synchronized void retainAllListedAndAddedByKeys(
-                final String[] before, final Collection listed) {
-            Collection added = new HashSet(keyToUid.keySet());
-            added.removeAll(Arrays.asList(before));
-            Collection retain = new HashSet(listed);
+        public synchronized void retainAllListedAndAddedByExternalKeys(String[] externalKeysBefore, Collection externalKeys) {
+            Collection added = new HashSet(externalToInternal.keySet());
+            added.removeAll(Arrays.asList(externalKeysBefore));
+            Collection retain = new HashSet(externalKeys);
             retain.addAll(added);
-            keyToUid.keySet().retainAll(retain);
-            uidToKey.keySet().retainAll(keyToUid.values());
+            externalToInternal.keySet().retainAll(retain);
+            internalToExternal.keySet().retainAll(externalToInternal.values());
         }
 
-        public synchronized void removeByKey(String key) {
-            long uid = getByKey(key);
-            if (uid > -1) {
-                uidToKey.remove(new Long(uid));
-            }
-            keyToUid.remove(key);
+        public synchronized void removeByExternalKey(String externalKey) {
+            String internalKey = getByExternalKey(externalKey);
+            internalToExternal.remove(internalKey);
+            externalToInternal.remove(externalKey);
         }
 
-        public synchronized long getByKey(String key) {
-            Long lo = (Long) keyToUid.get(key);
-            long l = -1;
-            if (lo != null) {
-                l = lo.longValue();
-            }
-            return l;
+        public synchronized String getByExternalKey(String externalKey) {
+            return (String) externalToInternal.get(externalKey);
         }
 
-        public synchronized String getByUid(long uid) {
-
-            return (String) uidToKey.get(new Long(uid));
+        public synchronized String getByInternalKey(String internalKey) { 
+            return (String) internalToExternal.get(internalKey);
         }
 
-        public synchronized boolean containsKey(String key) {
-            return keyToUid.containsKey(key);
+        public synchronized boolean containsExternalKey(String externalKey) {
+            return externalToInternal.containsKey(externalKey);
         }
 
-        public synchronized void put(String key, long uid) {
-            keyToUid.put(key, new Long(uid));
-            uidToKey.put(new Long(uid), key);
+        public synchronized void put(String externalKey, String internalKey) {
+            externalToInternal.put(externalKey, internalKey);
+            internalToExternal.put(internalKey, externalKey);
         }
 
 

Modified: james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java?view=diff&rev=481374&r1=481373&r2=481374
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java (original)
+++ james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java Fri Dec  1 12:18:48 2006
@@ -21,12 +21,9 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Date;
 import java.util.Iterator;
 
-import javax.mail.Flags;
 import javax.mail.MessagingException;
-import javax.mail.Flags.Flag;
 import javax.mail.internet.MimeMessage;
 
 import org.apache.avalon.framework.activity.Initializable;
@@ -40,12 +37,9 @@
 import org.apache.commons.logging.impl.SimpleLog;
 import org.apache.james.core.MailImpl;
 import org.apache.james.mailboxmanager.MailboxManagerException;
-import org.apache.james.mailboxmanager.MessageResult;
 import org.apache.james.mailboxmanager.Namespace;
-import org.apache.james.mailboxmanager.impl.GeneralMessageSetImpl;
-import org.apache.james.mailboxmanager.mailbox.FlaggedMailbox;
+import org.apache.james.mailboxmanager.mailbox.Mailbox;
 import org.apache.james.mailboxmanager.mailbox.MailboxSession;
-import org.apache.james.mailboxmanager.mailbox.UidMailbox;
 import org.apache.james.mailboxmanager.manager.MailboxManager;
 import org.apache.james.mailboxmanager.manager.MailboxManagerProvider;
 import org.apache.james.services.User;
@@ -64,7 +58,7 @@
     /**
      * used to map keys to uid and vice versa
      */
-    private UidToKeyBidiMap uidToKeyBidiMap = null;
+    private KeyBidiMap keyBidiMap = null;
 
     private MailboxManager mailboxManager;
 
@@ -74,15 +68,13 @@
 
     private User user;
 
-    protected long addUIDMessage(MimeMessage message) throws MessagingException {
+    protected String addMessage(MimeMessage message) throws MessagingException {
         try {
-            MessageResult mr = getMailboxGateKeeper().getMailbox().appendMessage(message,
-                    new Date(), MessageResult.UID);
-            return mr.getUid();
+            String myKey = getMailboxGateKeeper().getMailbox().store(message);
+            return myKey;
         } catch (MailboxManagerException e) {
             throw new MessagingException(e.getMessage(), e);
         }
-
     }
 
     /**
@@ -103,40 +95,39 @@
      */
     public synchronized void store(Mail mc) throws MessagingException {
         MimeMessage message = mc.getMessage();
-        String key = mc.getName();
-        
+        String externalKey = mc.getName();
+
         getLogger().debug("store key:" + mc.getName());
-        if (!message.isSet(Flag.RECENT)) {
-            getLogger().debug("Message didn't have RECENT flag");
-            message.setFlag(Flag.RECENT, true);
-        }
 
         boolean wasLocked = true;
         try {
             getMailboxGateKeeper().use();
-            
+
             synchronized (this) {
-                wasLocked = getLock().isLocked(key);
+                wasLocked = getLock().isLocked(externalKey);
                 if (!wasLocked) {
                     // If it wasn't locked, we want a lock during the store
-                    lock(key);
+                    lock(externalKey);
                 }
             }
 
             // insert or update, don't call remove(key) because of locking
-            if (getUidToKeyBidiMap().containsKey(key)) {
-                getLogger().info("remove message because of update Key:" + mc.getName());
-                doRemove(key,true);
-            }
-            long uid = addUIDMessage(message);
-            getUidToKeyBidiMap().put(key, uid);
-
-            getLogger().info("message stored: UID: " + uid + " Key:" + mc.getName());
+            if (getKeyBidiMap().containsExternalKey(externalKey)) {
+                getLogger().info(
+                        "remove message because of update Key:" + mc.getName());
+                doRemove(externalKey);
+            }
+            String internalKey = addMessage(message);
+            getKeyBidiMap().put(externalKey, internalKey);
+
+            getLogger().info(
+                    "message stored: externalKey: " + externalKey
+                            + " internalKey:" + internalKey);
         } finally {
 
             if (!wasLocked) {
                 // If it wasn't locked, we need to unlock now
-                unlock(key);
+                unlock(externalKey);
                 synchronized (this) {
                     notify();
                 }
@@ -150,20 +141,20 @@
      * 
      * @return
      */
-    protected UidToKeyBidiMap getUidToKeyBidiMap() {
-        if (uidToKeyBidiMap == null) {
-            uidToKeyBidiMap = new UidToKeyBidiMapImpl();
+    protected KeyBidiMap getKeyBidiMap() {
+        if (keyBidiMap == null) {
+            keyBidiMap = new KeyBidiMapImpl();
         }
-        return uidToKeyBidiMap;
+        return keyBidiMap;
     }
 
     /**
      * Used for testing
      * 
-     * @param uidToKeyBidiMap
+     * @param keyBidiMap
      */
-    void setUidToKeyBidiMap(UidToKeyBidiMap uidToKeyBidiMap) {
-        this.uidToKeyBidiMap = uidToKeyBidiMap;
+    void setKeyBidiMap(KeyBidiMap keyBidiMap) {
+        this.keyBidiMap = keyBidiMap;
     }
 
     /**
@@ -194,13 +185,14 @@
      */
     public synchronized void remove(String key) throws MessagingException {
         getLogger().info(" remove key:" + key);
-        doLockedRemove(key,true);
+        doLockedRemove(key, true);
     }
 
-    protected void doLockedRemove(String key,boolean expunge) throws MessagingException {
+    protected void doLockedRemove(String key, boolean expunge)
+            throws MessagingException {
         if (lock(key)) {
             try {
-                doRemove(key,expunge);
+                doRemove(key);
             } finally {
                 unlock(key);
             }
@@ -209,18 +201,15 @@
             throw new MessagingException("could not optain lock for remove");
         }
     }
-    protected void doRemove(String key,boolean expunge) throws MessagingException {
+
+    protected void doRemove(String externalKey) throws MessagingException {
         try {
             getMailboxGateKeeper().use();
-            if (getUidToKeyBidiMap().containsKey(key)) {
-                long uid = getUidToKeyBidiMap().getByKey(key);
-                getMailboxGateKeeper().getMailbox().setFlags(
-                        new Flags(Flags.Flag.DELETED), true, false,
-                        GeneralMessageSetImpl.oneUid(uid), null);
-                getUidToKeyBidiMap().removeByKey(key);
-                if (expunge) {
-                    doExpunge();
-                }
+            if (getKeyBidiMap().containsExternalKey(externalKey)) {
+                String internalKey = getKeyBidiMap().getByExternalKey(
+                        externalKey);
+                getMailboxGateKeeper().getMailbox().remove(internalKey);
+                getKeyBidiMap().removeByExternalKey(externalKey);
             }
         } catch (MailboxManagerException e) {
             throw new MessagingException(e.getMessage(), e);
@@ -229,18 +218,6 @@
         }
     }
 
-    protected void doExpunge() {
-        try {
-            getLogger().debug("Expunge");
-            getMailboxGateKeeper().getMailbox().expunge(
-                    GeneralMessageSetImpl.all(), MessageResult.NOTHING);
-        } catch (MailboxManagerException e) {
-            getLogger().error("Error expunging mailbox",e);
-        } catch (MessagingException e) {
-            getLogger().error("Error expunging mailbox",e);
-        }       
-    }
-    
     /**
      * List string keys of messages in repository.
      * 
@@ -250,50 +227,42 @@
      * 
      */
     public Iterator list() throws MessagingException {
-        getLogger().debug("UIDPlusFolder list");
+        getLogger().debug("MailboxManagerMailRepository list");
         try {
             getMailboxGateKeeper().use();
-            FlaggedMailbox mailbox = getMailboxGateKeeper().getMailbox();
-            
+            Mailbox mailbox = getMailboxGateKeeper().getMailbox();
+
             // needed for retainAllListedAndAddedByKeys(String[], Collection)
-            String[] keysBefore = getUidToKeyBidiMap().getKeys();
-            
+            String[] externalKeysBefore = getKeyBidiMap().getExternalKeys();
+
             // get the messages
-            MessageResult[] messageResults = mailbox.getMessages(
-                    GeneralMessageSetImpl.all(), MessageResult.UID
-                            + MessageResult.FLAGS);
-            Collection keys = new ArrayList(messageResults.length);
-            for (int i = 0; i < messageResults.length; i++) {
-                
-                long uid = messageResults[i].getUid();
-                
-                if (!messageResults[i].getFlags().contains(Flags.Flag.DELETED)) {
-
-                    long uidvalidity = ((UidMailbox) mailbox).getUidValidity();
-                    // lookup uid
-
-                    String key = getUidToKeyBidiMap().getByUid(uid);
-                    if (key == null) {
-                        // generate new key
-                        key = "james-uid:" + uidvalidity + ";" + uid + ";"
-                                + System.currentTimeMillis() + ";"
-                                + getRandom().nextLong();
-                        getUidToKeyBidiMap().put(key, uid);
-                    }
-                    keys.add(key);
-                    getLogger().debug("list: UID: " + uid + " Key:" + key);
-                } else {
-                    getLogger().debug("don't list deleted UID:" + uid); 
+            Collection internalKeys = mailbox.list();
+            Collection externalKeys = new ArrayList(internalKeys.size());
+            for (Iterator iter = internalKeys.iterator(); iter.hasNext();) {
+                String internalKey = (String) iter.next();
+                String externalKey = getKeyBidiMap().getByInternalKey(
+                        internalKey);
+
+                if (externalKey == null) {
+                    // generate new key
+                    externalKey = "james-mailboxmanager:" + internalKey + ";"
+                            + System.currentTimeMillis() + ";"
+                            + getRandom().nextLong();
+                    getKeyBidiMap().put(externalKey, internalKey);
                 }
+                externalKeys.add(externalKey);
+                getLogger().debug(
+                        "list: externalKey: " + externalKey + " internalKey:"
+                                + internalKey);
             }
             // retain only listed keys, and keys added in the meantime (it would
             // be fatal to loose those)
             // I don't care about meanwhile removed, those will fail on next
             // access
             // it's a good idea to keep count of cached small
-            getUidToKeyBidiMap()
-                    .retainAllListedAndAddedByKeys(keysBefore, keys);
-            return keys.iterator();
+            getKeyBidiMap().retainAllListedAndAddedByExternalKeys(
+                    externalKeysBefore, externalKeys);
+            return externalKeys.iterator();
         } catch (MailboxManagerException e) {
             throw new MessagingException(e.getMessage(), e);
         } finally {
@@ -301,46 +270,30 @@
         }
     }
 
-    private MimeMessage getMessageFromInbox(String key)
+    private MimeMessage getMessageFromInbox(String externalKey)
             throws MessagingException {
-
-        long uid = getUidToKeyBidiMap().getByKey(key);
-        if (uid < 1) {
-            return null;
-        }
-        MessageResult[] messageResults;
+        String internalKey=getKeyBidiMap().getByExternalKey(externalKey);
+        MimeMessage mimeMessage = null;
         try {
             getMailboxGateKeeper().use();
-            messageResults = getMailboxGateKeeper().getMailbox().getMessages(
-                    GeneralMessageSetImpl.oneUid(uid),
-                    MessageResult.MIME_MESSAGE);
+            mimeMessage = getMailboxGateKeeper().getMailbox().retrieve(internalKey);
         } catch (MailboxManagerException e) {
             throw new MessagingException(e.getMessage(), e);
         } finally {
             getMailboxGateKeeper().free();
         }
 
-        MimeMessage mm = null;
-        if (messageResults.length == 1) {
-            mm = messageResults[0].getMimeMessage();
-        }
-        getLogger().debug("getMessageFromInbox: UID: " + uid + " Key:" + key);
-        if (mm == null) {
-            getUidToKeyBidiMap().removeByKey(key);
-            getLogger().info("Message not Found");
-        }
-        return mm;
+        return mimeMessage;
     }
 
     public void remove(Collection mails) throws MessagingException {
-        getLogger().debug("Remove by Collection KEYS:"+mails);
+        getLogger().debug("Remove by Collection KEYS:" + mails);
         try {
             getMailboxGateKeeper().use();
             for (Iterator iter = mails.iterator(); iter.hasNext();) {
                 Mail mail = (Mail) iter.next();
-                doRemove(mail.getName(), false);
+                doRemove(mail.getName());
             }
-            doExpunge();
         } finally {
             getMailboxGateKeeper().free();
         }
@@ -357,22 +310,22 @@
     class MailboxGateKeeper {
         int open = 0;
 
-        FlaggedMailbox mailbox = null;
+        MailboxSession mailboxSession = null;
 
         synchronized void use() {
             open++;
         }
 
-        synchronized void  free() {
+        synchronized void free() {
             if (open < 1) {
                 throw new RuntimeException("use<1 !");
             }
             open--;
             if (open < 1) {
                 if (open == 0) {
-                    if (mailbox != null) {
-                        ((MailboxSession) mailbox).close();
-                        mailbox=null;
+                    if (mailboxSession != null) {
+                        mailboxSession.close();
+                        mailboxSession = null;
                     }
                 } else {
                     throw new RuntimeException("use<0 !");
@@ -380,20 +333,21 @@
             }
         }
 
-        synchronized FlaggedMailbox getMailbox()
-                throws MailboxManagerException, MessagingException {
+        synchronized Mailbox getMailbox() throws MailboxManagerException,
+                MessagingException {
             if (open < 1) {
                 throw new RuntimeException("use<1 !");
             }
-            if (mailbox == null) {
+            if (mailboxSession == null) {
                 Namespace ns = getMailboxManager().getPersonalDefaultNamespace(
                         user);
 
-                String inbox=ns.getName() + ns.getHierarchyDelimter()+ "INBOX";
-                mailbox = getMailboxManager()
-                        .getImapMailboxSession(inbox);
+                String inbox = ns.getName() + ns.getHierarchyDelimter()
+                        + "INBOX";
+                mailboxSession = getMailboxManager().getImapMailboxSession(
+                        inbox);
             }
-            return mailbox;
+            return mailboxSession;
         }
     }
 
@@ -401,7 +355,7 @@
      * lazy loads a MailboxManager from MailboxManagerProvider
      * 
      */
-    
+
     protected MailboxManager getMailboxManager() throws MessagingException,
             MailboxManagerException {
         if (mailboxManager == null) {
@@ -424,9 +378,9 @@
     }
 
     public void configure(Configuration conf) throws ConfigurationException {
-        
+
         // fetch user name
-        
+
         String destinationUrl = conf.getAttribute("destinationURL");
         if (destinationUrl.endsWith("/")) {
             destinationUrl = destinationUrl.substring(0, destinationUrl
@@ -434,25 +388,28 @@
         }
         String userName = destinationUrl.substring(destinationUrl
                 .lastIndexOf('/') + 1);
-        getLogger().info("Configured for user: '"+userName+"' URL: '"+destinationUrl+"'");
-        setUser(new DefaultJamesUser(userName,"none"));
+        getLogger().info(
+                "Configured for user: '" + userName + "' URL: '"
+                        + destinationUrl + "'");
+        setUser(new DefaultJamesUser(userName, "none"));
     }
 
-
     public void setUser(User user) {
-        this.user=user;
+        this.user = user;
     }
 
     public void service(ServiceManager serviceManager) throws ServiceException {
-        MailboxManagerProvider mailboxManagerProvider =(MailboxManagerProvider) serviceManager.lookup("org.apache.james.mailboxmanager.manager.MailboxManagerProvider");
-        getLogger().debug("MailboxManagerMailRepository uses service "+mailboxManagerProvider);
+        MailboxManagerProvider mailboxManagerProvider = (MailboxManagerProvider) serviceManager
+                .lookup("org.apache.james.mailboxmanager.manager.MailboxManagerProvider");
+        getLogger().debug(
+                "MailboxManagerMailRepository uses service "
+                        + mailboxManagerProvider);
         setMailboxManagerProvider(mailboxManagerProvider);
     }
-    
-    
+
     protected Log getLogger() {
-        if (log==null) {
-            log=new SimpleLog("MailboxManagerMailRepository");
+        if (log == null) {
+            log = new SimpleLog("MailboxManagerMailRepository");
         }
         return log;
     }

Modified: james/server/trunk/src/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java?view=diff&rev=481374&r1=481373&r2=481374
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java (original)
+++ james/server/trunk/src/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java Fri Dec  1 12:18:48 2006
@@ -52,6 +52,8 @@
 import org.apache.james.mailboxmanager.torque.om.MessageRowPeer;
 import org.apache.james.mailboxmanager.tracking.UidChangeTracker;
 import org.apache.james.mailboxmanager.tracking.UidRange;
+import org.apache.james.mailboxmanager.util.UidToKeyConverter;
+import org.apache.james.mailboxmanager.util.UidToKeyConverterImpl;
 import org.apache.torque.NoRowsException;
 import org.apache.torque.TooManyRowsException;
 import org.apache.torque.TorqueException;
@@ -71,12 +73,15 @@
     private UidChangeTracker tracker;
 
     private MailboxEventDispatcher eventDispatcher = new MailboxEventDispatcher();
+
+    private UidToKeyConverter uidToKeyConverter;
     
     TorqueMailbox(MailboxRow mailboxRow, UidChangeTracker tracker, Log log) {
         setLog(log);
         this.mailboxRow = mailboxRow;
         this.tracker = tracker;
         tracker.addMailboxListener(getEventDispatcher());
+        getUidToKeyConverter().setUidValidity(mailboxRow.getUidValidity());
     }
 
     public int getMessageResultTypes() {
@@ -236,7 +241,8 @@
     public MessageResult[] getMessages(GeneralMessageSet set, int result)
             throws MailboxManagerException {
         checkAccess();
-        if (!set.isValid()) {
+        set=toUidSet(set);
+        if (!set.isValid() || set.getType()==GeneralMessageSet.TYPE_NOTHING) {
             return new MessageResult[0];
         }
         Criteria c = criteriaForMessageSet(set);
@@ -307,6 +313,12 @@
             messageResult.setInternalDate(messageRow.getInternalDate());
             result -= MessageResult.INTERNAL_DATE;
         }
+        if ((result & MessageResult.KEY) > 0) {
+            messageResult.setKey(getUidToKeyConverter().toKey(messageRow.getUid()));
+            result -= MessageResult.KEY;
+        }
+        
+        
         if (result != 0) {
             throw new RuntimeException("Unsupportet result: " + result);
         }
@@ -394,6 +406,10 @@
     public MessageResult[] expunge(GeneralMessageSet set, int result)
             throws MailboxManagerException {
         checkAccess();
+        set=toUidSet(set);  
+        if (!set.isValid() || set.getType()==GeneralMessageSet.TYPE_NOTHING) {
+            return new MessageResult[0];
+        }
         try {
             // TODO put this into a serializable transaction
             final Criteria c = criteriaForMessageSet(set);
@@ -424,6 +440,10 @@
             GeneralMessageSet set, MailboxListener silentListener)
             throws MailboxManagerException {
         checkAccess();
+        set=toUidSet(set);  
+        if (!set.isValid() || set.getType()==GeneralMessageSet.TYPE_NOTHING) {
+            return;
+        }        
         try {
             // TODO put this into a serializeable transaction
             final List messageRows = getMailboxRow()
@@ -531,7 +551,13 @@
         this.mailboxRow = mailboxRow;
     }
 
-    public MessageResult[] search(GeneralMessageSet set, SearchTerm searchTerm, int result) {
+    public MessageResult[] search(GeneralMessageSet set, SearchTerm searchTerm,
+            int result) throws MailboxManagerException {
+        checkAccess();
+        set=toUidSet(set);
+        if (!set.isValid() || set.getType()==GeneralMessageSet.TYPE_NOTHING) {
+            return new MessageResult[0];
+        }
         final Log log = getLog();
         // TODO implementation
         if (log.isWarnEnabled()) {
@@ -540,5 +566,29 @@
         MessageResult[] results = {};
         return results;
     }
+    
+    protected UidToKeyConverter getUidToKeyConverter() {
+        if (uidToKeyConverter == null) {
+            uidToKeyConverter = new UidToKeyConverterImpl();
+        }
+        return uidToKeyConverter;
+    }
+
+    public void remove(GeneralMessageSet set) throws MailboxManagerException {
+        setFlags(new Flags(Flags.Flag.DELETED), true, false, set, null);
+        expunge(set, MessageResult.NOTHING);
+    }
 
+    private GeneralMessageSet toUidSet(GeneralMessageSet set) {
+        if (set.getType()==GeneralMessageSet.TYPE_KEY) {
+            Long uid=getUidToKeyConverter().toUid(set.getKey());
+            if (uid!=null) {
+                set=GeneralMessageSetImpl.oneUid(uid.longValue());
+            } else {
+                set=GeneralMessageSetImpl.nothing();
+            }
+        }
+        return set;
+    }
+    
 }

Copied: james/server/trunk/src/java/org/apache/james/mailboxmanager/util/AbstractLogFactoryAware.java (from r477670, james/server/trunk/src/java/org/apache/james/mailboxmanager/util/AbstractLogEnabled.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailboxmanager/util/AbstractLogFactoryAware.java?view=diff&rev=481374&p1=james/server/trunk/src/java/org/apache/james/mailboxmanager/util/AbstractLogEnabled.java&r1=477670&p2=james/server/trunk/src/java/org/apache/james/mailboxmanager/util/AbstractLogFactoryAware.java&r2=481374
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailboxmanager/util/AbstractLogEnabled.java (original)
+++ james/server/trunk/src/java/org/apache/james/mailboxmanager/util/AbstractLogFactoryAware.java Fri Dec  1 12:18:48 2006
@@ -1,15 +1,39 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
 package org.apache.james.mailboxmanager.util;
 
+import org.apache.avalon.framework.logger.LogEnabled;
+import org.apache.avalon.framework.logger.Logger;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.impl.SimpleLog;
 
-public abstract class AbstractLogEnabled {
+public abstract class AbstractLogFactoryAware implements LogFactoryAware, LogEnabled {
     
     private Log log;
+    private MyLogFactory logFactory;
 
     protected Log getLog() {
         if (log==null) {
-            log=new SimpleLog(this.getClass().getName());
+            SimpleLog simpleLog=new SimpleLog(this.getClass().getName());
+            simpleLog.setLevel(SimpleLog.LOG_LEVEL_ALL);
+            log=simpleLog;
         }
         return log;
     }
@@ -17,5 +41,30 @@
     public void setLog(Log log) {
         this.log=log;
     }
+
+    public void setLogFactory(MyLogFactory logFactory) {
+        this.logFactory=logFactory;
+    }
+    
+    protected MyLogFactory getLogFacory() {
+        return logFactory;
+    }
+    
+    protected void setupChildLog(Object object, String childName) {
+        MyLogFactory childFactory=logFactory.getChildFactory(childName);
+        if (object instanceof LogFactoryAware) {
+            ((LogFactoryAware)object).setLogFactory(childFactory);
+        }
+        if (object instanceof LogAware) {
+            ((LogAware)object).setLog(childFactory.getLog());
+        }    
+    }
+
+    public void enableLogging(Logger logger) {
+        this.logFactory=new AvalonLogFactory(logger);
+        this.log=logFactory.getLog();
+    }
+    
+    
 
 }

Added: james/server/trunk/src/java/org/apache/james/mailboxmanager/util/AvalonLogFactory.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailboxmanager/util/AvalonLogFactory.java?view=auto&rev=481374
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailboxmanager/util/AvalonLogFactory.java (added)
+++ james/server/trunk/src/java/org/apache/james/mailboxmanager/util/AvalonLogFactory.java Fri Dec  1 12:18:48 2006
@@ -0,0 +1,54 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailboxmanager.util;
+
+import org.apache.avalon.framework.logger.LogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.impl.AvalonLogger;
+
+public class AvalonLogFactory implements MyLogFactory, LogEnabled {
+
+    private Logger logger;
+    
+    public AvalonLogFactory() {
+    }
+    
+    public AvalonLogFactory(Logger logger) {
+        this.logger=logger;
+    }
+    
+    public MyLogFactory getChildFactory(String childName) {
+        return new AvalonLogFactory(logger.getChildLogger(childName));
+    }
+
+    public Log getChildLog(String childName) {
+        return new AvalonLogger(logger.getChildLogger(childName));
+    }
+
+    public Log getLog() {
+        return new AvalonLogger(logger);
+    }
+
+    public void enableLogging(Logger logger) {
+        this.logger=logger;
+    }
+
+}

Added: james/server/trunk/src/java/org/apache/james/mailboxmanager/util/LogAware.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailboxmanager/util/LogAware.java?view=auto&rev=481374
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailboxmanager/util/LogAware.java (added)
+++ james/server/trunk/src/java/org/apache/james/mailboxmanager/util/LogAware.java Fri Dec  1 12:18:48 2006
@@ -0,0 +1,28 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailboxmanager.util;
+
+import org.apache.commons.logging.Log;
+
+public interface LogAware {
+    
+    public void setLog(Log log);
+
+}

Added: james/server/trunk/src/java/org/apache/james/mailboxmanager/util/LogFactoryAware.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailboxmanager/util/LogFactoryAware.java?view=auto&rev=481374
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailboxmanager/util/LogFactoryAware.java (added)
+++ james/server/trunk/src/java/org/apache/james/mailboxmanager/util/LogFactoryAware.java Fri Dec  1 12:18:48 2006
@@ -0,0 +1,26 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailboxmanager.util;
+
+public interface LogFactoryAware {
+    
+    public void setLogFactory(MyLogFactory logFactory);
+
+}

Added: james/server/trunk/src/java/org/apache/james/mailboxmanager/util/MyLogFactory.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailboxmanager/util/MyLogFactory.java?view=auto&rev=481374
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailboxmanager/util/MyLogFactory.java (added)
+++ james/server/trunk/src/java/org/apache/james/mailboxmanager/util/MyLogFactory.java Fri Dec  1 12:18:48 2006
@@ -0,0 +1,33 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailboxmanager.util;
+
+import org.apache.commons.logging.Log;
+
+interface MyLogFactory {
+    
+    Log getChildLog(String childName);
+    
+    Log getLog();
+    
+    MyLogFactory getChildFactory(String childName);
+    
+    
+}

Added: james/server/trunk/src/java/org/apache/james/mailboxmanager/util/UidToKeyConverter.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailboxmanager/util/UidToKeyConverter.java?view=auto&rev=481374
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailboxmanager/util/UidToKeyConverter.java (added)
+++ james/server/trunk/src/java/org/apache/james/mailboxmanager/util/UidToKeyConverter.java Fri Dec  1 12:18:48 2006
@@ -0,0 +1,30 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailboxmanager.util;
+
+public interface UidToKeyConverter {
+
+    void setUidValidity(long uidValidity);
+
+    String toKey(long uid);
+
+    Long toUid(String key);
+
+}

Added: james/server/trunk/src/java/org/apache/james/mailboxmanager/util/UidToKeyConverterImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailboxmanager/util/UidToKeyConverterImpl.java?view=auto&rev=481374
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailboxmanager/util/UidToKeyConverterImpl.java (added)
+++ james/server/trunk/src/java/org/apache/james/mailboxmanager/util/UidToKeyConverterImpl.java Fri Dec  1 12:18:48 2006
@@ -0,0 +1,77 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailboxmanager.util;
+
+public class UidToKeyConverterImpl extends AbstractLogFactoryAware implements
+        UidToKeyConverter {
+
+    public static final String PREFIX = "JAMES-UID-KEY-";
+
+    private long uidValidity;
+
+    public void setUidValidity(long uidValidity) {
+        this.uidValidity = uidValidity;
+    }
+
+    public String toKey(long uid) {
+        return PREFIX + "(" + uid + ";" + uidValidity + ")";
+    }
+
+    public Long toUid(String key) {
+        if (key != null) {
+            if (key.startsWith(PREFIX + "(")) {
+                key = key.substring(PREFIX.length() + 1);
+                if (key.endsWith(")")) {
+                    key = key.substring(0, key.length() - 1);
+                    int pos = key.indexOf(';');
+                    if (pos > 0 && pos < key.length() - 1) {
+                        try {
+                            long theUid = Long.parseLong(key.substring(0, pos));
+                            long theUidValidity = Long.parseLong(key
+                                    .substring(pos + 1));
+                            if (theUidValidity == uidValidity) {
+                                return new Long(theUid);
+                            } else {
+                                getLog().debug(
+                                        "toUid: uidValidity mismatch. Expected: "
+                                                + uidValidity + " was "
+                                                + theUidValidity);
+                            }
+                        } catch (NumberFormatException e) {
+                            getLog().debug("toUid", e);
+                        }
+                    } else {
+                        getLog().debug(
+                                "toUid: failed. pos=" + pos + " length="
+                                        + key.length());
+                    }
+                } else {
+                    getLog().debug("toUid: failed. did not end with ')'");
+                }
+            } else {
+                getLog().debug("toUid: failed. did not start with PREFIX");
+            }
+        } else {
+            getLog().debug("toUid: failed. key is null");
+        }
+        return null;
+    }
+
+}

Modified: james/server/trunk/src/java/org/apache/james/mailboxmanager/wrapper/SessionMailboxWrapper.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailboxmanager/wrapper/SessionMailboxWrapper.java?view=diff&rev=481374&r1=481373&r2=481374
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailboxmanager/wrapper/SessionMailboxWrapper.java (original)
+++ james/server/trunk/src/java/org/apache/james/mailboxmanager/wrapper/SessionMailboxWrapper.java Fri Dec  1 12:18:48 2006
@@ -73,4 +73,8 @@
         return true;
     }
 
+    public void remove(GeneralMessageSet set) throws MailboxManagerException {
+        mailbox.remove(toUidSet(set));
+    }
+
 }

Added: james/server/trunk/src/test/org/apache/james/mailboxmanager/util/UidToKeyConverterTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/mailboxmanager/util/UidToKeyConverterTest.java?view=auto&rev=481374
==============================================================================
--- james/server/trunk/src/test/org/apache/james/mailboxmanager/util/UidToKeyConverterTest.java (added)
+++ james/server/trunk/src/test/org/apache/james/mailboxmanager/util/UidToKeyConverterTest.java Fri Dec  1 12:18:48 2006
@@ -0,0 +1,63 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailboxmanager.util;
+
+import junit.framework.TestCase;
+
+public class UidToKeyConverterTest extends TestCase {
+    
+    UidToKeyConverterImpl uidToKeyConverterImpl;
+    
+    long uidValidity=123;
+    
+    public void setUp(){
+        uidToKeyConverterImpl=new UidToKeyConverterImpl();
+        uidToKeyConverterImpl.setUidValidity(uidValidity);
+    }
+
+    
+    public void testUidToKey() {
+        assertEquals("JAMES-UID-KEY-(345;123)",uidToKeyConverterImpl.toKey(345));
+    }
+    
+    public void testKeyToUidValid() {
+        assertEquals(Long.valueOf(3454),uidToKeyConverterImpl.toUid("JAMES-UID-KEY-(3454;123)"));
+        uidToKeyConverterImpl.setUidValidity(1);
+        assertEquals(Long.valueOf(2),uidToKeyConverterImpl.toUid("JAMES-UID-KEY-(2;1)"));
+    }
+    
+    public void testKeyToUidWrongUidValidity() {
+        assertNull(uidToKeyConverterImpl.toUid("JAMES-UID-KEY-(3454;1234)"));
+    }
+    
+    public void testKeyToUidWrongFormat() {
+        assertNull(uidToKeyConverterImpl.toUid(null));
+        assertNull(uidToKeyConverterImpl.toUid(""));
+        assertNull(uidToKeyConverterImpl.toUid("JMES-UID-KEY-("));
+        assertNull(uidToKeyConverterImpl.toUid("JAMES-UID-KEY-(;123)"));
+        assertNull(uidToKeyConverterImpl.toUid("JAMES-UID-KEY-(3454;)"));
+        assertNull(uidToKeyConverterImpl.toUid("JAMES-UID-KEY-(3454;123"));
+        assertNull(uidToKeyConverterImpl.toUid("JAMES-UID-KEY-(345d4;123)"));
+        assertNull(uidToKeyConverterImpl.toUid("JAMES-UID-KEY-(34;54;123)"));
+        
+    }
+    
+    
+}



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