Author: norman
Date: Mon Sep 25 12:55:02 2006
New Revision: 449795

URL: http://svn.apache.org/viewvc?view=rev&rev=449795
Log:
Start to merge new version of javamailstore repository. See JAMES-637

Also start to merge javadocs to this version

Added:
    james/server/trunk/src/java/org/apache/james/mailrepository/javamail/
    
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/AbstractJavamailStoreMailRepository.java
      - copied, changed from r449235, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/AbstractJavamailStoreMailRepository.java
    
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderAdapter.java
      - copied, changed from r449235, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderAdapter.java
    
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderAdapterFactory.java
    
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderGateKeeper.java
      - copied, changed from r447388, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderGateKeeper.java
    
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderGateKeeperImpl.java
      - copied, changed from r449235, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderGateKeeperImpl.java
    
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderInterface.java
      - copied, changed from r449235, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderInterface.java
    
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/HashJavamailStoreMailRepository.java
      - copied, changed from r449269, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/HashJavamailStoreMailRepository.java
    
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/LockAdapter.java
      - copied, changed from r449235, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/LockAdapter.java
    
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/LockInterface.java
      - copied, changed from r447388, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/LockInterface.java
    
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/StoreGateKeeper.java
    
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/StoreGateKeeperAware.java
    
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/StoreGateKeeperImpl.java
    
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolder.java
      - copied, changed from r447388, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolder.java
    
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolderAdapter.java
      - copied, changed from r449235, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolderAdapter.java
    
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolderMailRepository.java
      - copied, changed from r449269, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolderMailRepository.java
    
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UidToKeyBidiMap.java
      - copied, changed from r449269, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UidToKeyBidiMap.java

Copied: 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/AbstractJavamailStoreMailRepository.java
 (from r449235, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/AbstractJavamailStoreMailRepository.java)
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailrepository/javamail/AbstractJavamailStoreMailRepository.java?view=diff&rev=449795&p1=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/AbstractJavamailStoreMailRepository.java&r1=449235&p2=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/AbstractJavamailStoreMailRepository.java&r2=449795
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/AbstractJavamailStoreMailRepository.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/AbstractJavamailStoreMailRepository.java
 Mon Sep 25 12:55:02 2006
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
+
 package org.apache.james.mailrepository.javamail;
 
 import java.io.File;
@@ -54,7 +55,7 @@
  */
 
 public abstract class AbstractJavamailStoreMailRepository extends
-        AbstractLogEnabled implements MailRepository, StoreAware, Configurable,
+        AbstractLogEnabled implements MailRepository, StoreGateKeeperAware, 
FolderAdapterFactory, Configurable,
         Initializable,Contextualizable {
 
     /**
@@ -76,7 +77,7 @@
      * The underlaying Store can be used externaly via the 
StoreAware.getStore()
      * Method
      */
-    private javax.mail.Store mailStore = null;
+    private StoreGateKeeper storeGateKeeper = null;
 
     /** 
      * used internally to generate keys 
@@ -157,6 +158,7 @@
             throw new ConfigurationException("Invalid url: " + destination);
         }
     
+
         destination = protocol + withoutProtocol;
         log.debug("destination: " + destination);
         Properties mailSessionProps  = new Properties();
@@ -165,10 +167,16 @@
         // mailSessionProps.put("mail.store.maildir.autocreatedir", "true");
         Session mailSession = Session.getDefaultInstance(mailSessionProps);
         try {
-            mailStore = mailSession.getStore(new URLName(destination));
+            Store store=mailSession.getStore(new URLName(destination));
+            store.connect();
+            storeGateKeeper = new StoreGateKeeperImpl(store);
+            storeGateKeeper.setFolderAdapterFactory(this);
         } catch (NoSuchProviderException e) {
             throw new ConfigurationException("cannot find store provider for "
                     + destination, e);
+        } catch (MessagingException e) {
+            throw new ConfigurationException("Error connecting store: "
+                    + destination, e);
         }
 
         String checkType = conf.getAttribute("type");
@@ -180,14 +188,12 @@
         }
         log.debug("JavaMailStoreMailRepository configured");
     }
-    
+
     /**
-     * connect the mailStore
-     * 
+     * Does nothing
      * @see Initializable#initialize()
      */
     public void initialize() throws Exception {
-        mailStore.connect();              
         log.debug("JavaMailStoreMailRepository initialized");
     }
     
@@ -298,8 +304,8 @@
      * Remove a list of messages from disk The collection is simply a list of
      * mails to delete
      * 
-     * @param mails a Collection of mails which should removed
-     * @throws MessagingException 
+     * @param mails
+     * @throws MessagingException
      */
     public void remove(final Collection mails) throws MessagingException {
         log.debug("UIDPlusFolder remove by Collection " + mails.size());
@@ -325,8 +331,8 @@
      * 
      * @return the Store 
      */
-    public Store getStore() {
-        return mailStore;
+    public StoreGateKeeper getStore() {
+        return storeGateKeeper;
     }
 
     /**
@@ -352,52 +358,39 @@
         this.log=log;
         
     }
+    
     /**
      * possibility to replace FolderGateKeeper implementation. Only used for
      * testing
      * 
      * @param folderGateKeeper the FolgerGateKeeper to use
      */
-    void setFolderGateKeeper(FolderGateKeeper folderGateKeeper) {
-        this.folderGateKeeper=folderGateKeeper;
+    void setFolderGateKeeper(FolderGateKeeper gk) {
+        this.folderGateKeeper=gk;
         
     }
     
     /**
-     * used by getFolderGateKeeper to get the right FolderInterface 
implementation
-     * 
-     * @param folder JavaMail folder
-     * @return folderInterface the FolderInterface
-     * @throws NoSuchMethodException if the Folder is not suitable
-     */
-    protected  abstract FolderInterface createAdapter(Folder folder) throws 
NoSuchMethodException;
-    
-    /**
      * Lazy-load FolderGateKeeper with inbox folder. Inbox folder is created if
      * not present
-     * 
      * @return FolderGateKeeper offering inbox folder for this mail repository
      */
     protected FolderGateKeeper getFolderGateKeeper() {
         if (folderGateKeeper == null) {
             try {
-                Folder inbox = getStore().getFolder("INBOX");
-                FolderInterface myInbox=createAdapter(inbox);
-                folderGateKeeper = new FolderGateKeeperImpl(myInbox);
-
+                folderGateKeeper = getStore().getFolder("INBOX");
                 /*
                  * Check whether the folder exists, if not create it
                  */
-                if (inbox.exists() == false) {
-                    inbox.create(Folder.HOLDS_MESSAGES);
+                folderGateKeeper.use();
+                if (folderGateKeeper.getFolder().exists() == false) {
+                    folderGateKeeper.getFolder().create(Folder.HOLDS_MESSAGES);
                 }
+                folderGateKeeper.free();
             } catch (MessagingException e) {
                 throw new RuntimeException(
                         "cannot retrieve inbox for this repository", e);
-            } catch (NoSuchMethodException e) {
-                throw new RuntimeException(
-                        "Folder implementation is not suitable", e);
-            }
+            } 
         }
         return folderGateKeeper;
     }

Copied: 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderAdapter.java
 (from r449235, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderAdapter.java)
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderAdapter.java?view=diff&rev=449795&p1=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderAdapter.java&r1=449235&p2=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderAdapter.java&r2=449795
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderAdapter.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderAdapter.java
 Mon Sep 25 12:55:02 2006
@@ -100,14 +100,14 @@
     }
 
     /**
-     * @see javax.mail.Folder#create(int)
+     * @see 
org.apache.james.mailrepository.javamail.FolderInterface#create(int)
      */
     public boolean create(int arg0) throws MessagingException {
         return folder.create(arg0);
     }
 
     /**
-     * @see javax.mail.Folder#delete(boolean)
+     * @see 
org.apache.james.mailrepository.javamail.FolderInterface#delete(boolean)
      */
     public boolean delete(boolean arg0) throws MessagingException {
         return folder.delete(arg0);
@@ -121,14 +121,14 @@
     }
 
     /**
-     * @see javax.mail.Folder#exists()
+     * @see org.apache.james.mailrepository.javamail.FolderInterface#exists()
      */
     public boolean exists() throws MessagingException {
         return folder.exists();
     }
 
     /**
-     * @see javax.mail.Folder#expunge()
+     * @see org.apache.james.mailrepository.javamail.FolderInterface#expunge()
      */
     public Message[] expunge() throws MessagingException {
         return folder.expunge();
@@ -156,10 +156,17 @@
     }
 
     /**
-     * @see javax.mail.Folder#getFullName()
+     * @see 
org.apache.james.mailrepository.javamail.FolderInterface#getFullName()
      */
     public String getFullName() {
-        return folder.getFullName();
+        // FIXME ugly workaroung for buggy getFullName in javamaildir
+        String fn=folder.getFullName();
+        if (fn.length()>1) {
+            if (fn.charAt(0)=='.') {
+                fn=fn.substring(1);
+            }
+        }
+        return fn;
     }
 
     /**
@@ -205,19 +212,20 @@
     }
 
     /**
-     * @see javax.mail.Folder#getName()
+     * @see org.apache.james.mailrepository.javamail.FolderInterface#getName()
      */
     public String getName() {
         return folder.getName();
     }
 
     /**
-     * @see javax.mail.Folder#getNewMessageCount()
+     * @see 
org.apache.james.mailrepository.javamail.FolderInterface#getNewMessageCount()
      */
     public int getNewMessageCount() throws MessagingException {
         return folder.getNewMessageCount();
     }
 
+    
     /**
      * @see javax.mail.Folder#getParent()
      */
@@ -226,7 +234,7 @@
     }
 
     /**
-     * @see javax.mail.Folder#getPermanentFlags()
+     * @see 
org.apache.james.mailrepository.javamail.FolderInterface#getPermanentFlags()
      */
     public Flags getPermanentFlags() {
         return folder.getPermanentFlags();
@@ -247,14 +255,14 @@
     }
 
     /**
-     * @see javax.mail.Folder#getType()
+     * @see org.apache.james.mailrepository.javamail.FolderInterface#getType()
      */
     public int getType() throws MessagingException {
         return folder.getType();
     }
 
     /**
-     * @see javax.mail.Folder#getUnreadMessageCount()
+     * @see 
org.apache.james.mailrepository.javamail.FolderInterface#getUnreadMessageCount()
      */
     public int getUnreadMessageCount() throws MessagingException {
         return folder.getUnreadMessageCount();
@@ -303,10 +311,10 @@
     }
 
     /**
-     * @see javax.mail.Folder#list(String)
+     * @see 
org.apache.james.mailrepository.javamail.FolderInterface#list(java.lang.String)
      */
-    public Folder[] list(String arg0) throws MessagingException {
-        return folder.list(arg0);
+    public FolderInterface[] list(String arg0) throws MessagingException {
+        return wrapFolders(folder.list(arg0));
     }
 
     /**
@@ -336,7 +344,7 @@
     public void removeConnectionListener(ConnectionListener arg0) {
         folder.removeConnectionListener(arg0);
     }
-
+    
     /**
      * @see javax.mail.Folder#removeFolderListener(FolderListener)
      */
@@ -359,7 +367,7 @@
     }
 
     /**
-     * @see javax.mail.Folder#renameTo(Folder)
+     * @see 
org.apache.james.mailrepository.javamail.FolderInterface#renameTo(javax.mail.Folder)
      */
     public boolean renameTo(Folder arg0) throws MessagingException {
         return folder.renameTo(arg0);
@@ -414,4 +422,25 @@
         return folder.toString();
     }
 
+    /**
+     * Wrap Folder in this class 
+     * 
+     * @param folder the folder to wrap
+     * @return new instance of this class wrapped 
+     */
+    protected FolderInterface wrapFolder(Folder folder) {
+        return new FolderAdapter(folder);
+    }
+    
+    /**
+     * @see #wrapFolder(Folder)
+     */
+    protected FolderInterface[] wrapFolders(Folder[] folders) {
+        FolderInterface[] fis=new FolderInterface[folders.length];
+        for (int i = 0; i < folders.length; i++) {
+            fis[i]=wrapFolder(folders[i]);
+            
+        }
+        return fis;
+    }
 }

Added: 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderAdapterFactory.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderAdapterFactory.java?view=auto&rev=449795
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderAdapterFactory.java
 (added)
+++ 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderAdapterFactory.java
 Mon Sep 25 12:55:02 2006
@@ -0,0 +1,35 @@
+/****************************************************************
+ * 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.mailrepository.javamail;
+
+import javax.mail.Folder;
+
+public interface FolderAdapterFactory {
+    
+    /**
+     * used by StoreGateKeeper to get the right FolderInterface implementation
+     * 
+     * @param folder JavaMail folder
+     * @return 
+     * @throws NoSuchMethodException if the Folder is not suitable
+     */
+    FolderInterface createAdapter(Folder folder);
+
+}

Copied: 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderGateKeeper.java
 (from r447388, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderGateKeeper.java)
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderGateKeeper.java?view=diff&rev=449795&p1=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderGateKeeper.java&r1=447388&p2=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderGateKeeper.java&r2=449795
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderGateKeeper.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderGateKeeper.java
 Mon Sep 25 12:55:02 2006
@@ -16,8 +16,10 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
+
 package org.apache.james.mailrepository.javamail;
 
+import javax.mail.Folder;
 import javax.mail.MessagingException;
 
 /**
@@ -90,5 +92,30 @@
      *             if there are only 0 users
      */
     public FolderInterface getFolder();
+
+    /**
+     * @see javax.mail.Folder#getFullName()
+     */
+    public String getFullName() throws MessagingException;
+
+    /**
+     * @see javax.mail.Folder
+     */
+    public void create(int holds_folders) throws MessagingException;
+
+    /**
+     * @see javax.mail.Folder#exists()
+     */
+    public boolean exists() throws MessagingException;
+    
+    /**
+     * @see javax.mail.Folder#renameTo(Folder)
+     */
+    void renameTo(Folder folder) throws MessagingException;
+
+    /**
+     * @see javax.mail.Folder#renameTo(Folder)
+     */
+    public void renameTo(String newName) throws MessagingException;;
 
 }

Copied: 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderGateKeeperImpl.java
 (from r449235, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderGateKeeperImpl.java)
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderGateKeeperImpl.java?view=diff&rev=449795&p1=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderGateKeeperImpl.java&r1=449235&p2=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderGateKeeperImpl.java&r2=449795
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderGateKeeperImpl.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderGateKeeperImpl.java
 Mon Sep 25 12:55:02 2006
@@ -17,8 +17,6 @@
  * under the License.                                           *
  ****************************************************************/
 
-
-
 package org.apache.james.mailrepository.javamail;
 
 import javax.mail.Folder;
@@ -29,28 +27,26 @@
  * offers access to an underlaying Folder and manages open/close 
operations.<br>
  * The FolderGateKeeper can be handed over to different threads.
  * 
- * @see org.apache.james.mailrepository.javamail.FolderGateKeeper
+ * @sse FolderGateKeeper
  *
  */
 public class FolderGateKeeperImpl implements FolderGateKeeper {
 
-    private FolderInterface folder;
+    private final FolderInterface folder;
 
     private int inUse = 0;
 
     boolean open = false;
 
-    /**
-     * Construct new FolderGateKeeperImpl
-     * 
-     * @param folder the FolderInterface
-     */
-    public FolderGateKeeperImpl(FolderInterface folder) {
+    private final StoreGateKeeper storeGateKeeper;
+
+    public FolderGateKeeperImpl(FolderInterface folder,StoreGateKeeper 
storeGateKeeper) {
         if (folder.isOpen()) {
             throw new IllegalStateException(
                     "FolderGateKeeper: initial state must be closed");
         }
         this.folder = folder;
+        this.storeGateKeeper=storeGateKeeper;
     }
 
     /**
@@ -89,6 +85,9 @@
      * @see 
org.apache.james.mailrepository.javamail.FolderGateKeeper#getOpenFolder()
      */
     public synchronized FolderInterface getOpenFolder() throws 
MessagingException {
+        if ((folder.getType() & Folder.HOLDS_MESSAGES)==0) {
+            throw new RuntimeException("cannot open a Folder that does not 
hold messages");
+        }
         if (inUse < 1) {
             throw new IllegalStateException(
                     "called getFolder() but folder is not in use");
@@ -127,6 +126,55 @@
                             + open);
         }
         return folder;
+    }
+
+    /**
+     * @see 
org.apache.james.mailrepository.javamail.FolderGateKeeper#getFullName()
+     */
+    public String getFullName() throws MessagingException {
+        use();
+        String fn=getFolder().getFullName();
+        free();
+        return fn;
+    }
+
+    /**
+     * @see 
org.apache.james.mailrepository.javamail.FolderGateKeeper#create(int)
+     */
+    public void create(int holds_folders) throws MessagingException {
+        use();
+        getFolder().create(holds_folders);
+        free();
+    }
+
+    /**
+     * @see org.apache.james.mailrepository.javamail.FolderGateKeeper#exists()
+     */
+    public boolean exists() throws MessagingException {
+        use();
+        boolean e=getFolder().exists();
+        free();
+        return e;
+    }
+
+
+    /**
+     * @see 
org.apache.james.mailrepository.javamail.FolderGateKeeper#renameTo(javax.mail.Folder)
+     */
+    public synchronized void renameTo(Folder destination) throws 
MessagingException {
+        if (inUse!=0) {
+            throw new IllegalStateException("cannot operate of folder that is 
in use");
+        } else {
+            folder.renameTo(destination);
+        }
+        
+    }
+
+    /**
+     * @see 
org.apache.james.mailrepository.javamail.FolderGateKeeper#renameTo(java.lang.String)
+     */
+    public synchronized void renameTo(String newName) throws 
MessagingException {
+        storeGateKeeper.renameTo(this,newName);
     }
 
 }

Copied: 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderInterface.java
 (from r449235, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderInterface.java)
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderInterface.java?view=diff&rev=449795&p1=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderInterface.java&r1=449235&p2=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderInterface.java&r2=449795
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderInterface.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/FolderInterface.java
 Mon Sep 25 12:55:02 2006
@@ -17,13 +17,12 @@
  * under the License.                                           *
  ****************************************************************/
 
-
-
 package org.apache.james.mailrepository.javamail;
 
+import javax.mail.Flags;
+import javax.mail.Folder;
 import javax.mail.Message;
 import javax.mail.MessagingException;
-import javax.mail.event.MessageChangedListener;
 
 /**
  * Interface to javax.mail.Folder functionality to be able to replace 
@@ -66,5 +65,65 @@
      * @see javax.mail.Folder#close(boolean)
      */
     public void close(boolean b) throws MessagingException;
+
+    /**
+     * @see javax.mail.Folder#exists()
+     */
+    public boolean exists() throws MessagingException;
+
+    /**
+     * @see javax.mail.Folder#create(int)
+     */
+    public boolean create(int holds_messages) throws MessagingException;
+
+    /**
+     * @see javax.mail.Folder#getType()
+     */
+    public int getType() throws MessagingException;
+
+    /**
+     * @see javax.mail.Folder#getFullName()
+     */
+    public String getFullName();
+
+    /**
+     * @see javax.mail.Folder#expunge()
+     */
+    public Message[] expunge() throws MessagingException;
+
+    /**
+     * @see javax.mail.Folder#getUnreadMessageCount()
+     */
+    public int getUnreadMessageCount() throws MessagingException;
+
+    /**
+     * @see javax.mail.Folder#getNewMessageCount()
+     */
+    public int getNewMessageCount() throws MessagingException;
+
+    /**
+     * @see javax.mail.Folder#getPermanentFlags()
+     */
+    public Flags getPermanentFlags();
+
+    /**
+     * @see javax.mail.Folder#getName()
+     */
+    public String getName();
+
+    /**
+     * @see javax.mail.Folder#list(String)
+     */
+    public FolderInterface[] list(String string) throws MessagingException;
+    
+    /**
+     * @see javax.mail.Folder#delete(boolean)
+     */
+    public boolean delete(boolean recurse) throws MessagingException;
+
+    /**
+     * @see javax.mail.Folder#renameTo(Folder)
+     */
+    public boolean renameTo(Folder destination) throws MessagingException;;
 
 }

Copied: 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/HashJavamailStoreMailRepository.java
 (from r449269, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/HashJavamailStoreMailRepository.java)
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailrepository/javamail/HashJavamailStoreMailRepository.java?view=diff&rev=449795&p1=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/HashJavamailStoreMailRepository.java&r1=449269&p2=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/HashJavamailStoreMailRepository.java&r2=449795
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/HashJavamailStoreMailRepository.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/HashJavamailStoreMailRepository.java
 Mon Sep 25 12:55:02 2006
@@ -17,12 +17,8 @@
  * under the License.                                           *
  ****************************************************************/
 
-
-
 package org.apache.james.mailrepository.javamail;
 
-import java.io.ByteArrayOutputStream;
-import java.io.FilterOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Arrays;
@@ -70,13 +66,7 @@
     
     private boolean getMessageCountOnClosed =true;
     
-    /**
-     * get the count of messages 
-     * 
-     * @return the count of messages
-     * 
-     * @throws MessagingException
-     */
+    
     protected int getMessageCount() throws MessagingException {
         try {
             getFolderGateKeeper().use();
@@ -304,6 +294,7 @@
     protected MimeMessage getMessageFromInbox(String key)
             throws MessagingException {
         MsgObj mo = getKeyToMsgMap().getByKey(key);
+        log.debug("getMessageFromInbox: Looking for hash "+mo.hash);
         if (mo == null) {
             log.debug("Key not found");
             return null;
@@ -357,35 +348,12 @@
         }
         return keyToMsgMap;
     }
-
-    private static final class HasherOutputStream extends FilterOutputStream {
-        int hashCode = 0;
-
-        public HasherOutputStream(OutputStream out) {
-            super(out);
-        }
-
-        // TODO verify this method (off/len usage)
-        public void write(byte[] b, int off, int len) throws IOException {
-            for (int i = off; i < b.length && i < len+off; i++) {
-                hashCode += 77;
-                hashCode ^= b[i];
-            }
-            super.write(b, off, len);
-        }
-
-        public void write(byte[] b) throws IOException {
-            for (int i = 0; i < b.length; i++) {
-                hashCode += 77;
-                hashCode ^= b[i];
-            }
-            super.write(b);
-        }
-
+    
+    public static final class HasherOutputStream extends OutputStream {
+        int hashCode = 1;
+        
         public void write(int b) throws IOException {
-            hashCode += 77;
-            hashCode ^= b;
-            super.write(b);
+            hashCode = 41 * hashCode + b;
         }
 
         public int getHash() {
@@ -393,6 +361,8 @@
         }
     }
 
+
+
     protected class KeyToMsgMap {
         protected SortedMap noToMsgObj;
 
@@ -462,25 +432,28 @@
          * 
          * @param key
          *            key of message
-         * @param decrement
+         * @param decrease
          *            if true, all message number greater than this are
          *            decremented
          */
         public synchronized void removeByKey(String key, boolean decrement) {
             MsgObj mo = getByKey(key);
-            keyToMsgObj.remove(mo.key);
-            noToMsgObj.remove(new Integer(mo.no));
-            hashToMsgObj.remove(mo.hash);
-            if (decrement) {
-                // tailMap finds all entries that have message number greater
-                // than removed one and decrements them
-                MsgObj[] dmos = (MsgObj[]) noToMsgObj.tailMap(
-                        new Integer(mo.no)).values().toArray(new MsgObj[0]);
-                for (int i = 0; i < dmos.length; i++) {
-                    MsgObj dmo = dmos[i];
-                    noToMsgObj.remove(new Integer(dmo.no));
-                    dmo.no--;
-                    noToMsgObj.put(new Integer(dmo.no), dmo);
+            if (mo != null) {
+                keyToMsgObj.remove(mo.key);
+                noToMsgObj.remove(new Integer(mo.no));
+                hashToMsgObj.remove(mo.hash);
+                if (decrement) {
+                    // tailMap finds all entries that have message number
+                    // greater
+                    // than removed one and decrements them
+                    MsgObj[] dmos = (MsgObj[]) noToMsgObj.tailMap(
+                            new Integer(mo.no)).values().toArray(new 
MsgObj[0]);
+                    for (int i = 0; i < dmos.length; i++) {
+                        MsgObj dmo = dmos[i];
+                        noToMsgObj.remove(new Integer(dmo.no));
+                        dmo.no--;
+                        noToMsgObj.put(new Integer(dmo.no), dmo);
+                    }
                 }
             }
         }
@@ -517,6 +490,7 @@
          * @return fetched/created MsgObj
          * @throws MessagingException
          */
+
         public synchronized MsgObj put(final MimeMessage mm, String key,
                 final int no) throws MessagingException {
             final Object hash = calcMessageHash(mm);
@@ -588,20 +562,16 @@
      *            message to hash
      * @return an Object provides and correct equals method.
      * @throws MessagingException
-     */
+     */  
     protected static Object calcMessageHash(MimeMessage mm)
             throws MessagingException {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        // This nested class has been created because Java 2 v1.4 has 
-        // no Arrays.hashCode() method.
-        // We can remove this as soon as we'll require Java 5.
-        HasherOutputStream hos = new HasherOutputStream(new 
CRLFOutputStream(baos));
+        HasherOutputStream hos = new HasherOutputStream();
         try {
-            mm.writeTo(hos);
+            mm.writeTo(new CRLFOutputStream(hos));
         } catch (IOException e) {
-            throw new MessagingException("error while calculating hash ", e);
+            throw new MessagingException("error while calculating hash", e);
         }
-        
+
         Integer i = new Integer(hos.getHash());
         return i;
     }
@@ -621,10 +591,9 @@
     /**
      * just uses a FolderAdapter to wrap around folder
      * 
-     * @see 
org.apache.james.mailrepository.javamail.AbstractJavamailStoreMailRepository#createAdapter(Folder)
+     * @see 
org.apache.james.mailrepository.javamailOLD.AbstractJavamailStoreMailRepository#createAdapter(Folder)
      */
-    protected FolderInterface createAdapter(Folder folder)
-            throws NoSuchMethodException {
+    public FolderInterface createAdapter(Folder folder) {
         return new FolderAdapter(folder);
     }
 

Copied: 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/LockAdapter.java
 (from r449235, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/LockAdapter.java)
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailrepository/javamail/LockAdapter.java?view=diff&rev=449795&p1=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/LockAdapter.java&r1=449235&p2=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/LockAdapter.java&r2=449795
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/LockAdapter.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/LockAdapter.java
 Mon Sep 25 12:55:02 2006
@@ -17,8 +17,6 @@
  * under the License.                                           *
  ****************************************************************/
 
-
-
 package org.apache.james.mailrepository.javamail;
 
 import org.apache.james.util.Lock;

Copied: 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/LockInterface.java
 (from r447388, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/LockInterface.java)
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailrepository/javamail/LockInterface.java?view=diff&rev=449795&p1=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/LockInterface.java&r1=447388&p2=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/LockInterface.java&r2=449795
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/LockInterface.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/LockInterface.java
 Mon Sep 25 12:55:02 2006
@@ -17,8 +17,6 @@
  * under the License.                                           *
  ****************************************************************/
 
-
-
 package org.apache.james.mailrepository.javamail;
 
 /**

Added: 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/StoreGateKeeper.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailrepository/javamail/StoreGateKeeper.java?view=auto&rev=449795
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/StoreGateKeeper.java
 (added)
+++ 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/StoreGateKeeper.java
 Mon Sep 25 12:55:02 2006
@@ -0,0 +1,36 @@
+/****************************************************************
+ * 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.mailrepository.javamail;
+
+import javax.mail.MessagingException;
+
+public interface StoreGateKeeper {
+
+    public FolderGateKeeper getFolder(String string) throws MessagingException;
+
+    public void setFolderAdapterFactory(FolderAdapterFactory folderFactory);
+    
+    public  FolderGateKeeper getDefaultFolder() throws MessagingException;
+
+    public FolderGateKeeper[] list(String string) throws MessagingException;
+    
+    public void renameTo(FolderGateKeeper from, String to) throws 
MessagingException;
+
+}

Added: 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/StoreGateKeeperAware.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailrepository/javamail/StoreGateKeeperAware.java?view=auto&rev=449795
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/StoreGateKeeperAware.java
 (added)
+++ 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/StoreGateKeeperAware.java
 Mon Sep 25 12:55:02 2006
@@ -0,0 +1,35 @@
+/****************************************************************
+ * 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.mailrepository.javamail;
+
+
+
+/**
+ * Bridge, that allows JavamailStoreMailRepository implementations to offer the
+ * underlaying Javamail Store
+ * 
+ * @author Joachim Draeger <jd at joachim-draeger.de>
+ */
+
+public interface StoreGateKeeperAware {
+
+    public StoreGateKeeper getStore();
+
+}

Added: 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/StoreGateKeeperImpl.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailrepository/javamail/StoreGateKeeperImpl.java?view=auto&rev=449795
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/StoreGateKeeperImpl.java
 (added)
+++ 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/StoreGateKeeperImpl.java
 Mon Sep 25 12:55:02 2006
@@ -0,0 +1,114 @@
+/****************************************************************
+ * 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.mailrepository.javamail;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.mail.Folder;
+import javax.mail.MessagingException;
+import javax.mail.Store;
+
+public class StoreGateKeeperImpl implements StoreGateKeeper {
+    
+    private Store store;
+    
+    Map folderGateKeeperMap = new HashMap();
+    FolderGateKeeper defaultFolder = null;
+
+    private FolderAdapterFactory folderFactory;
+    
+    public StoreGateKeeperImpl(Store store) {
+        this.store=store;
+    }
+
+    /**
+     * @see 
org.apache.james.mailrepository.javamail.StoreGateKeeper#getFolder(java.lang.String)
+     */
+    public synchronized FolderGateKeeper getFolder(String name) throws 
MessagingException {
+        if (name.length()==0) {
+            return null;
+        }
+        if (name.equalsIgnoreCase("INBOX")) {
+            name="INBOX";
+        }
+        FolderGateKeeper fgk=(FolderGateKeeper) folderGateKeeperMap.get(name);
+        if (fgk==null) {
+            Folder f = store.getFolder(name);
+            fgk=new FolderGateKeeperImpl(folderFactory.createAdapter(f),this);
+            folderGateKeeperMap.put(name,fgk);
+        }
+        
+        return fgk;
+    }
+    
+    /**
+     * @see 
org.apache.james.mailrepository.javamail.StoreGateKeeper#getDefaultFolder()
+     */
+    public synchronized FolderGateKeeper getDefaultFolder() throws 
MessagingException {
+        if (defaultFolder==null) {
+            Folder f = store.getDefaultFolder();
+            defaultFolder=new 
FolderGateKeeperImpl(folderFactory.createAdapter(f),this);
+        }
+        return defaultFolder;
+    }
+
+    /**
+     * @see 
org.apache.james.mailrepository.javamail.StoreGateKeeper#setFolderAdapterFactory(org.apache.james.mailrepository.javamail.FolderAdapterFactory)
+     */
+    public void setFolderAdapterFactory(FolderAdapterFactory folderFactory) {
+        this.folderFactory=folderFactory;
+        
+    }
+
+    /**
+     * @see 
org.apache.james.mailrepository.javamail.StoreGateKeeper#list(java.lang.String)
+     */
+    public FolderGateKeeper[] list(String string) throws MessagingException {
+        getDefaultFolder().use();
+        FolderInterface[] folders = 
getDefaultFolder().getFolder().list(string);
+        FolderGateKeeper[] keepers =new FolderGateKeeper[folders.length];
+        for (int i = 0; i < keepers.length; i++) {
+            keepers[i]=getFolder(folders[i].getFullName());
+        }
+        getDefaultFolder().free();
+        
+        return keepers;
+    }
+    
+    /**
+     * @see 
org.apache.james.mailrepository.javamail.StoreGateKeeper#renameTo(org.apache.james.mailrepository.javamail.FolderGateKeeper,
 java.lang.String)
+     */
+    public void renameTo(FolderGateKeeper from,String to) throws 
MessagingException {
+        String fromName=from.getFullName();
+        FolderGateKeeper[] subFolders = list(from.getFullName()+".*");
+        for (int i = 0; i < subFolders.length; i++) {
+            FolderGateKeeper subFolder=subFolders[i];
+            String subFolderName=subFolder.getFullName();
+            String 
newSubFolderName=to+subFolderName.substring(fromName.length());
+            Folder subDestination=store.getFolder(newSubFolderName);
+            subFolder.renameTo(subDestination);
+        }
+        Folder destination=store.getFolder(to);
+        from.renameTo(destination);
+    
+    }
+
+}

Copied: 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolder.java
 (from r447388, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolder.java)
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolder.java?view=diff&rev=449795&p1=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolder.java&r1=447388&p2=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolder.java&r2=449795
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolder.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolder.java
 Mon Sep 25 12:55:02 2006
@@ -17,8 +17,6 @@
  * under the License.                                           *
  ****************************************************************/
 
-
-
 package org.apache.james.mailrepository.javamail;
 
 import javax.mail.Message;

Copied: 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolderAdapter.java
 (from r449235, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolderAdapter.java)
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolderAdapter.java?view=diff&rev=449795&p1=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolderAdapter.java&r1=449235&p2=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolderAdapter.java&r2=449795
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolderAdapter.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolderAdapter.java
 Mon Sep 25 12:55:02 2006
@@ -17,8 +17,6 @@
  * under the License.                                           *
  ****************************************************************/
 
-
-
 package org.apache.james.mailrepository.javamail;
 
 import java.lang.reflect.InvocationTargetException;
@@ -36,20 +34,19 @@
 public class UIDPlusFolderAdapter extends FolderAdapter implements 
UIDPlusFolder {
     
     private Method addUIDMessagesMethod;
+    private Method addMessagesMethod;
     
-    /**
-     * Wrap the Folder 
-     * 
-     * @param folder the Folder
-     * @throws NoSuchMethodException
-     */
-    public UIDPlusFolderAdapter(Folder folder) throws NoSuchMethodException {
+    public UIDPlusFolderAdapter(Folder folder) {
         super(folder);
         try {
             addUIDMessagesMethod=folder.getClass().getMethod("addUIDMessages",
                     new Class[] { Message[].class });
+            addMessagesMethod=folder.getClass().getMethod("addMessages",
+                    new Class[] { Message[].class });
         } catch (SecurityException e) {
             throw new RuntimeException(e);
+        } catch (NoSuchMethodException e) {
+            throw new RuntimeException(e);
         } 
     }
 
@@ -76,7 +73,19 @@
      * @see 
org.apache.james.mailrepository.javamail.UIDPlusFolder#addMessages(javax.mail.Message[])
      */
     public Message[] addMessages(Message[] msgs) throws MessagingException {
-       throw new RuntimeException("Method addMessages(Message[] msgs) not 
implemented");
+        try {
+            return (Message[]) addMessagesMethod.invoke(folder, new Object[] { 
msgs });
+        } catch (IllegalArgumentException e) {
+            throw new RuntimeException(e);
+        } catch (IllegalAccessException e) {
+            throw new RuntimeException(e);
+        } catch (InvocationTargetException e) {
+            Throwable cause=e.getCause();
+            if (cause instanceof RuntimeException) {
+                throw (RuntimeException)cause;
+            }
+            throw new RuntimeException(e);
+        }
     }
 
     /**

Copied: 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolderMailRepository.java
 (from r449269, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolderMailRepository.java)
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolderMailRepository.java?view=diff&rev=449795&p1=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolderMailRepository.java&r1=449269&p2=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolderMailRepository.java&r2=449795
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolderMailRepository.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UIDPlusFolderMailRepository.java
 Mon Sep 25 12:55:02 2006
@@ -17,8 +17,6 @@
  * under the License.                                           *
  ****************************************************************/
 
-
-
 package org.apache.james.mailrepository.javamail;
 
 import java.util.ArrayList;
@@ -102,7 +100,11 @@
 
 
     /**
-     * @see 
org.apache.james.services.MailRepository#store(org.apache.mailet.Mail)
+     * Stores a message in this repository.
+     * 
+     * @param mc
+     *            the mail message to store
+     * @throws MessagingException
      */
     public void store(Mail mc) throws MessagingException {
         
@@ -153,8 +155,7 @@
 
     /**
      * lazy loads UidToKeyBidiMap
-     * 
-     * @return uidToKeyBidiMap the UidToKeyBidiMap
+     * @return
      */
     protected UidToKeyBidiMap getUidToKeyBidiMap() {
         if (uidToKeyBidiMap == null) {
@@ -166,7 +167,7 @@
     /**
      * Used for testing
      * 
-     * @param uidToKeyBidiMap the UidToKeyBidMap
+     * @param uidToKeyBidiMap
      */
     void setUidToKeyBidiMap(UidToKeyBidiMap uidToKeyBidiMap) {
         this.uidToKeyBidiMap = uidToKeyBidiMap;
@@ -176,8 +177,12 @@
      * Retrieves a message given a key. At the moment, keys can be obtained 
from
      * list() in superinterface Store.Repository
      * 
-     * @see org.apache.james.services.MailRepository#retrieve(String)
+     * @param key
+     *            the key of the message to retrieve
+     * @return the mail corresponding to this key, null if none exists
+     * @throws MessagingException 
      */
+
     public Mail retrieve(String key) throws MessagingException {
         log.debug("UIDPlusFolder retrieve " + key);
         try {
@@ -195,7 +200,10 @@
     }
 
     /**
-     * @see org.apache.james.services.MailRepository#remove(java.lang.String)
+     * Removes a message identified by key.
+     * 
+     * @param key
+     *            the key of the message to be removed from the repository
      */
     public void remove(String key) throws MessagingException {
 
@@ -220,7 +228,12 @@
     }
 
     /**
-     * @see org.apache.james.services.MailRepository#list()
+     * List string keys of messages in repository.
+     * 
+     * @return an <code>Iterator</code> over the list of keys in the
+     *         repository
+     * @throws MessagingException 
+     * 
      */
     public Iterator list() throws MessagingException {
         log.debug("UIDPlusFolder list");
@@ -289,6 +302,7 @@
      * 
      * maybe it could be replaced by BidiMap from commons-collections 3.0+
      * 
+     * @author Joachim Draeger <jd at joachim-draeger.de>
      */
     private class UidToKeyBidiMapImpl implements UidToKeyBidiMap {
 
@@ -301,18 +315,12 @@
             uidToKey = new HashMap();
         }
 
-        /**
-         * @see 
org.apache.james.mailrepository.javamail.UidToKeyBidiMap#getKeys()
-         */
         public synchronized String[] getKeys() {
             final ArrayList al = new ArrayList(keyToUid.keySet());
             final String[] keys = (String[]) al.toArray(new String[0]);
             return keys;
         }
 
-        /**
-         * @see 
org.apache.james.mailrepository.javamail.UidToKeyBidiMap#retainAllListedAndAddedByKeys(java.lang.String[],
 java.util.Collection)
-         */
         public synchronized void retainAllListedAndAddedByKeys(
                 final String[] before, final Collection listed) {
             Collection added = new HashSet(keyToUid.keySet());
@@ -323,9 +331,6 @@
             uidToKey.keySet().retainAll(keyToUid.values());
         }
 
-        /**
-         * @see 
org.apache.james.mailrepository.javamail.UidToKeyBidiMap#removeByKey(java.lang.String)
-         */
         public synchronized void removeByKey(String key) {
             long uid = getByKey(key);
             if (uid > -1) {
@@ -334,9 +339,6 @@
             keyToUid.remove(key);
         }
 
-        /**
-         * @see 
org.apache.james.mailrepository.javamail.UidToKeyBidiMap#getByKey(java.lang.String)
-         */
         public synchronized long getByKey(String key) {
             Long lo = (Long) keyToUid.get(key);
             long l = -1;
@@ -346,24 +348,15 @@
             return l;
         }
 
-        /**
-         * @see 
org.apache.james.mailrepository.javamail.UidToKeyBidiMap#getByUid(long)
-         */
         public synchronized String getByUid(long uid) {
 
             return (String) uidToKey.get(new Long(uid));
         }
 
-        /**
-         * @see 
org.apache.james.mailrepository.javamail.UidToKeyBidiMap#containsKey(java.lang.String)
-         */
         public synchronized boolean containsKey(String key) {
             return keyToUid.containsKey(key);
         }
 
-        /**
-         * @see 
org.apache.james.mailrepository.javamail.UidToKeyBidiMap#put(java.lang.String, 
long)
-         */
         public synchronized void put(String key, long uid) {
             keyToUid.put(key, new Long(uid));
             uidToKey.put(new Long(uid), key);
@@ -374,9 +367,9 @@
     /**
      * returns a UIDPlusFolderAdapter wrapper
      * 
-     * @see 
org.apache.james.mailrepository.javamail.UIDPlusFolderAdapter#UIDPlusFolderAdapter(Folder)
+     * @see UIDPlusFolderAdapter
      */
-    protected FolderInterface createAdapter(Folder folder) throws 
NoSuchMethodException {
+    public FolderInterface createAdapter(Folder folder) {
         return new UIDPlusFolderAdapter(folder);
     }
 

Copied: 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UidToKeyBidiMap.java
 (from r449269, 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UidToKeyBidiMap.java)
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UidToKeyBidiMap.java?view=diff&rev=449795&p1=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UidToKeyBidiMap.java&r1=449269&p2=james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UidToKeyBidiMap.java&r2=449795
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UidToKeyBidiMap.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/mailrepository/javamail/UidToKeyBidiMap.java
 Mon Sep 25 12:55:02 2006
@@ -17,8 +17,6 @@
  * under the License.                                           *
  ****************************************************************/
 
-
-
 package org.apache.james.mailrepository.javamail;
 
 import java.util.Collection;
@@ -27,59 +25,21 @@
  * Used to map uids to keys and keys to uids 
  *
  */
+
 public interface UidToKeyBidiMap {
 
-    /**
-     * Return true if an uid is stored under the given key 
-     * 
-     * @param key the key
-     * @return true if an uid is stored under the given key
-     */
     boolean containsKey(String key);
 
-    /**
-     * Store the given uid with the given key
-     * 
-     * @param key the key to store the given uid with 
-     * @param uid the uid
-     */
     void put(String key, long uid);
 
-    /**
-     * Remove the uid stored under the given key
-     * 
-     * @param key the key
-     */
     void removeByKey(String key);
 
-    /**
-     * Return a String[] holding all stored keys
-     * 
-     * @return keys a String[] holding all keys
-     */
     String[] getKeys();
 
-    /**
-     * Return the key for the given uid 
-     * 
-     * @param uid the uid 
-     * @return key the key for the given uid
-     */
     String getByUid(long uid);
 
-    /**
-     * 
-     * @param keysBefore
-     * @param keys
-     */
     void retainAllListedAndAddedByKeys(String[] keysBefore, Collection keys);
 
-    /**
-     * Get uid for the given key
-     * 
-     * @param key the key
-     * @return uid the uid for the given key
-     */
     long getByKey(String key);
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to