james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joac...@apache.org
Subject svn commit: r481519 - in /james/server/sandbox/mailbox-namespaces/src/java/org/apache/james: imapserver/commands/ mailboxmanager/ mailboxmanager/impl/ mailboxmanager/mailbox/ mailboxmanager/repository/ mailboxmanager/torque/ mailboxmanager/util/ mailbo...
Date Sat, 02 Dec 2006 08:43:02 GMT
Author: joachim
Date: Sat Dec  2 00:42:59 2006
New Revision: 481519

URL: http://svn.apache.org/viewvc?view=rev&rev=481519
Log:
merged in 481327:481374 from trunk

Added:
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/KeyBidiMap.java
      - copied unchanged from r481374, james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/KeyBidiMap.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/KeyBidiMapImpl.java
      - copied unchanged from r481374, james/server/trunk/src/java/org/apache/james/mailboxmanager/repository/KeyBidiMapImpl.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/util/AbstractLogFactoryAware.java
      - copied unchanged from r481374, james/server/trunk/src/java/org/apache/james/mailboxmanager/util/AbstractLogFactoryAware.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/util/AvalonLogFactory.java
      - copied unchanged from r481374, james/server/trunk/src/java/org/apache/james/mailboxmanager/util/AvalonLogFactory.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/util/LogAware.java
      - copied unchanged from r481374, james/server/trunk/src/java/org/apache/james/mailboxmanager/util/LogAware.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/util/LogFactoryAware.java
      - copied unchanged from r481374, james/server/trunk/src/java/org/apache/james/mailboxmanager/util/LogFactoryAware.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/util/MyLogFactory.java
      - copied unchanged from r481374, james/server/trunk/src/java/org/apache/james/mailboxmanager/util/MyLogFactory.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/util/UidToKeyConverter.java
      - copied unchanged from r481374, james/server/trunk/src/java/org/apache/james/mailboxmanager/util/UidToKeyConverter.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/util/UidToKeyConverterImpl.java
      - copied unchanged from r481374, james/server/trunk/src/java/org/apache/james/mailboxmanager/util/UidToKeyConverterImpl.java
Removed:
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMap.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMapImpl.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/util/AbstractLogEnabled.java
Modified:
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/commands/CloseCommand.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/commands/ExpungeCommand.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/GeneralMessageSet.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/GeneralMessageSetImpl.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailbox/AbstractGeneralMailbox.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
    james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/wrapper/SessionMailboxWrapper.java

Modified: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/commands/CloseCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/commands/CloseCommand.java?view=diff&rev=481519&r1=481518&r2=481519
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/commands/CloseCommand.java
(original)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/commands/CloseCommand.java
Sat Dec  2 00:42:59 2006
@@ -24,8 +24,8 @@
 import org.apache.james.imapserver.ImapSession;
 import org.apache.james.imapserver.ProtocolException;
 import org.apache.james.imapserver.store.MailboxException;
-import org.apache.james.mailboxmanager.GeneralMessageSet;
 import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.MessageResult;
 import org.apache.james.mailboxmanager.impl.GeneralMessageSetImpl;
 import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
 
@@ -49,7 +49,7 @@
         ImapMailboxSession mailbox = session.getSelected().getMailbox();
         if ( session.getSelected().getMailbox().isWriteable() ) {
             try {
-                mailbox.expunge(GeneralMessageSetImpl.all(),GeneralMessageSet.TYPE_NONE);
+                mailbox.expunge(GeneralMessageSetImpl.all(),MessageResult.NOTHING);
             } catch (MailboxManagerException e) {
                throw new MailboxException(e);
             }

Modified: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/commands/ExpungeCommand.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/commands/ExpungeCommand.java?view=diff&rev=481519&r1=481518&r2=481519
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/commands/ExpungeCommand.java
(original)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/imapserver/commands/ExpungeCommand.java
Sat Dec  2 00:42:59 2006
@@ -24,8 +24,8 @@
 import org.apache.james.imapserver.ImapSession;
 import org.apache.james.imapserver.ProtocolException;
 import org.apache.james.imapserver.store.MailboxException;
-import org.apache.james.mailboxmanager.GeneralMessageSet;
 import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.MessageResult;
 import org.apache.james.mailboxmanager.impl.GeneralMessageSetImpl;
 import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
 
@@ -53,7 +53,7 @@
         }
        
         try {
-            mailbox.expunge(GeneralMessageSetImpl.all(),GeneralMessageSet.TYPE_NONE);
+            mailbox.expunge(GeneralMessageSetImpl.all(),MessageResult.NOTHING);
         } catch (MailboxManagerException e) {
             throw new MailboxException(e);
         }

Modified: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/GeneralMessageSet.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/GeneralMessageSet.java?view=diff&rev=481519&r1=481518&r2=481519
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/GeneralMessageSet.java
(original)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/GeneralMessageSet.java
Sat Dec  2 00:42:59 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/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/GeneralMessageSetImpl.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/GeneralMessageSetImpl.java?view=diff&rev=481519&r1=481518&r2=481519
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/GeneralMessageSetImpl.java
(original)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/GeneralMessageSetImpl.java
Sat Dec  2 00:42:59 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/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java?view=diff&rev=481519&r1=481518&r2=481519
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java
(original)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java
Sat Dec  2 00:42:59 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/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailbox/AbstractGeneralMailbox.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailbox/AbstractGeneralMailbox.java?view=diff&rev=481519&r1=481518&r2=481519
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailbox/AbstractGeneralMailbox.java
(original)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailbox/AbstractGeneralMailbox.java
Sat Dec  2 00:42:59 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/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java?view=diff&rev=481519&r1=481518&r2=481519
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java
(original)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java
Sat Dec  2 00:42:59 2006
@@ -89,6 +89,9 @@
      */
 
     MessageResult[] getMessages(GeneralMessageSet set, int result) throws MailboxManagerException;
+    
+    void remove(GeneralMessageSet set)
+            throws MailboxManagerException;
 
 
 }

Modified: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java?view=diff&rev=481519&r1=481518&r2=481519
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java
(original)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java
Sat Dec  2 00:42:59 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,25 +310,25 @@
     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) {
+                    if (mailboxSession != null) {
                         try {
-                            ((MailboxSession) mailbox).close();
+                            mailboxSession.close();
                         } catch (MailboxManagerException e) {
                         }
-                        mailbox=null;
+                        mailboxSession=null;
                     }
                 } else {
                     throw new RuntimeException("use<0 !");
@@ -383,20 +336,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 = mailboxManagerProvider.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;
         }
     }
 
@@ -404,7 +358,7 @@
      * lazy loads a MailboxManager from MailboxManagerProvider
      * 
      */
-    
+
     protected MailboxManager getMailboxManager() throws MessagingException,
             MailboxManagerException {
         if (mailboxManager == null) {
@@ -427,9 +381,9 @@
     }
 
     public void configure(Configuration conf) throws ConfigurationException {
-        
+
         // fetch user name
-        
+
         String destinationUrl = conf.getAttribute("destinationURL");
         if (destinationUrl.endsWith("/")) {
             destinationUrl = destinationUrl.substring(0, destinationUrl
@@ -437,25 +391,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/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java?view=diff&rev=481519&r1=481518&r2=481519
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
(original)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
Sat Dec  2 00:42:59 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;
+    }
+    
 }

Modified: james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/wrapper/SessionMailboxWrapper.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/wrapper/SessionMailboxWrapper.java?view=diff&rev=481519&r1=481518&r2=481519
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/wrapper/SessionMailboxWrapper.java
(original)
+++ james/server/sandbox/mailbox-namespaces/src/java/org/apache/james/mailboxmanager/wrapper/SessionMailboxWrapper.java
Sat Dec  2 00:42:59 2006
@@ -73,4 +73,8 @@
         return true;
     }
 
+    public void remove(GeneralMessageSet set) throws MailboxManagerException {
+        mailbox.remove(toUidSet(set));
+    }
+
 }



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