You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by jo...@apache.org on 2006/10/09 19:15:42 UTC

svn commit: r454432 [6/14] - in /james/server/sandbox/imap-integration: ./ lib/ src/java/ src/java/org/apache/james/imapserver/ src/java/org/apache/james/imapserver/commands/ src/java/org/apache/james/imapserver/debug/ src/java/org/apache/james/imapser...

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/acl/GroupAcl.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/acl/GroupAcl.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/acl/GroupAcl.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/acl/GroupAcl.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,19 @@
+package org.apache.james.mailboxmanager.acl;
+
+
+/**
+ * 
+ * Group acl bound to a mailbox. 
+ *
+ */
+
+public interface GroupAcl extends Acl {
+	
+	/**
+	 * 
+	 * could be enviroment specific. e.g. a unix group or a ldap dn
+	 */
+	
+	public String getGroupName();
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/acl/GroupAwareUser.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/acl/GroupAwareUser.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/acl/GroupAwareUser.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/acl/GroupAwareUser.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,11 @@
+package org.apache.james.mailboxmanager.acl;
+
+import org.apache.james.services.User;
+
+public interface GroupAwareUser extends User {
+	/**
+	 * could be enviroment specific. e.g. a unix group or a ldap dn
+	 */
+	String[] getGroups();
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/acl/MailboxRights.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/acl/MailboxRights.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/acl/MailboxRights.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/acl/MailboxRights.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,66 @@
+package org.apache.james.mailboxmanager.acl;
+
+import java.util.HashMap;
+
+
+/**
+ * Reprensents a set of rights that can be assigned to a mailbox in combination
+ * of an ACL. It is similar to javamails com.sun.mail.imap.Rights
+ */
+
+public class MailboxRights {
+
+	public MailboxRights() {
+
+	}
+
+	public void add(Right right) {
+		;
+	}
+
+	/**
+	 * returns a string representation like defined in RFC 2086. Rights not
+	 * supported by RFC 2086 will be omitted.
+	 * 
+	 */
+	public String toImapString() {
+		return null;
+
+	}
+
+
+	
+	public void remove(Right right) {
+		;
+	}
+
+	public boolean contains(Right right) {
+		return false;
+	}
+/**
+ * 
+ * draft an incomplete. Idea is to internally use String representives. The list of possible rights
+ * could increase a lot. That would make it impossible to find an appropriate char.
+ *
+ */
+	public static final class Right {
+
+		private static HashMap allRights = new HashMap();
+
+		public static final Right WRITE = getInstance("w");
+
+		private Right(String representative) {
+
+		}
+
+		private synchronized static final Right getInstance(String s) {
+			Right right = (Right) allRights.get(s);
+			if (right == null) {
+				right = new Right(s);
+			}
+			return right;
+		}
+
+	}
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/acl/UserAcl.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/acl/UserAcl.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/acl/UserAcl.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/acl/UserAcl.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,8 @@
+package org.apache.james.mailboxmanager.acl;
+
+
+public interface UserAcl extends Acl {
+	
+	public String getUserName();
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/GeneralMessageSetImpl.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/GeneralMessageSetImpl.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/GeneralMessageSetImpl.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/GeneralMessageSetImpl.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,135 @@
+package org.apache.james.mailboxmanager.impl;
+
+import javax.mail.Message;
+import org.apache.james.mailboxmanager.GeneralMessageSet;
+
+public class GeneralMessageSetImpl implements GeneralMessageSet {
+
+    private int type;
+
+    private long uidFrom;
+
+    private long uidTo;
+
+    private int msnFrom;
+
+    private int msnTo;
+
+    private GeneralMessageSetImpl() {
+    }
+
+    public int getType() {
+        return type;
+    }
+
+    public long getUidFrom() throws IllegalStateException {
+        if (type != TYPE_UID)
+            throw new IllegalStateException("not in UID mode");
+        return uidFrom;
+    }
+
+    public long getUidTo() throws IllegalStateException {
+        if (type != TYPE_UID)
+            throw new IllegalStateException("not in UID mode");
+        return uidTo;
+    }
+
+    public int getMsnFrom() throws IllegalStateException {
+        return msnFrom;
+    }
+
+    public int getMsnTo() throws IllegalStateException {
+        return msnTo;
+    }
+
+    public String getKey() throws IllegalStateException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Message getMessage() throws IllegalStateException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public static GeneralMessageSet oneUid(long uid) {
+        GeneralMessageSetImpl gms = new GeneralMessageSetImpl();
+        gms.type = TYPE_UID;
+        gms.uidFrom = uid;
+        gms.uidTo = uid;
+        return gms;
+    }
+
+    public static GeneralMessageSet all() {
+        GeneralMessageSetImpl gms = new GeneralMessageSetImpl();
+        gms.type = TYPE_ALL;
+        return gms;
+    }
+
+    public static GeneralMessageSet range(long lowVal, long highVal,
+            boolean useUids) {
+        GeneralMessageSetImpl gms = new GeneralMessageSetImpl();
+        if (highVal==Long.MAX_VALUE) {
+            highVal=-1;
+        }
+        if (useUids) {
+            gms.type = TYPE_UID;
+            gms.uidFrom = lowVal;
+            gms.uidTo = highVal;
+        } else {
+            gms.type = TYPE_MSN;
+            gms.msnFrom = (int) lowVal;
+            gms.msnTo = (int) highVal;
+        }
+        return gms;
+    }
+
+    public static GeneralMessageSet uidRange(long from, long to) {
+        GeneralMessageSetImpl gms = new GeneralMessageSetImpl();
+        gms.type = TYPE_UID;
+        gms.uidFrom = from;
+        gms.uidTo = to;
+        return gms;
+    }
+
+    public String toString() {
+        return "TYPE: " + type + " UID: " + uidFrom + ":" + uidTo;
+    }
+
+    public boolean isValid() {
+        if (type == TYPE_ALL) {
+            return true;
+        } else if (type == TYPE_UID) {
+            if (uidTo < 0) {
+                return true;
+            } else {
+                return (uidFrom <= uidTo);
+            }
+        } else if (type == TYPE_MSN) {
+            if (msnTo < 0) {
+                return true;
+            } else {
+                return (msnFrom <= msnTo);
+            }
+        } else {
+            return false;
+        }
+
+    }
+
+	public static GeneralMessageSet msnRange(int from, int to) {
+        GeneralMessageSetImpl gms = new GeneralMessageSetImpl();
+        gms.type = TYPE_MSN;
+        gms.msnFrom = from;
+        gms.msnTo = to;
+        return gms;
+	}
+
+	public static GeneralMessageSet oneMsn(int msn) {
+        GeneralMessageSetImpl gms = new GeneralMessageSetImpl();
+        gms.type = TYPE_MSN;
+        gms.msnFrom = msn;
+        gms.msnTo = msn;
+        return gms;
+	}
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/ListResultImpl.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/ListResultImpl.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/ListResultImpl.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/ListResultImpl.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,28 @@
+package org.apache.james.mailboxmanager.impl;
+
+import org.apache.james.mailboxmanager.ListResult;
+
+public class ListResultImpl implements ListResult {
+
+    private String name;
+    private String delimiter;
+    private String[] attributes=new String[0];
+
+    public ListResultImpl(String name, String delimiter) {
+        this.name=name;
+        this.delimiter=delimiter;
+    }
+
+    public String[] getAttributes() {
+        return attributes;
+    }
+
+    public String getHierarchyDelimiter() {
+        return delimiter;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/MailboxEventDispatcher.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/MailboxEventDispatcher.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/MailboxEventDispatcher.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/MailboxEventDispatcher.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,61 @@
+package org.apache.james.mailboxmanager.impl;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.james.mailboxmanager.MailboxListener;
+import org.apache.james.mailboxmanager.MessageResult;
+
+public class MailboxEventDispatcher implements MailboxListener {
+
+    private Set listeners = new HashSet();
+
+    public void addMailboxListener(MailboxListener mailboxListener) {
+        listeners.add(mailboxListener);
+    }
+
+    public void removeMailboxListener(MailboxListener mailboxListener) {
+        listeners.remove(mailboxListener);
+    }
+
+    public void added(MessageResult result) {
+        for (Iterator iter = listeners.iterator(); iter.hasNext();) {
+			MailboxListener mailboxListener = (MailboxListener) iter.next();
+			mailboxListener.added(result);
+		}
+    }
+
+    public void expunged(MessageResult mr) {
+        for (Iterator iter = listeners.iterator(); iter.hasNext();) {
+			MailboxListener mailboxListener = (MailboxListener) iter.next();
+            mailboxListener.expunged(mr);
+        }
+    }
+
+    public void flagsUpdated(MessageResult result, MailboxListener silentListener) {
+        for (Iterator iter = listeners.iterator(); iter.hasNext();) {
+			MailboxListener mailboxListener = (MailboxListener) iter.next();
+            mailboxListener.flagsUpdated(result, silentListener);
+        }
+    }
+
+    public void mailboxDeleted() {
+        for (Iterator iter = listeners.iterator(); iter.hasNext();) {
+			MailboxListener mailboxListener = (MailboxListener) iter.next();
+            mailboxListener.mailboxDeleted();
+        }
+    }
+
+    public void mailboxRenamed(String origName, String newName) {
+        for (Iterator iter = listeners.iterator(); iter.hasNext();) {
+			MailboxListener mailboxListener = (MailboxListener) iter.next();
+            mailboxListener.mailboxRenamed(origName,origName);
+        }
+    }
+    
+    public int size() {
+        return listeners.size();
+    }
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/MailboxListenerCollector.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/MailboxListenerCollector.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/MailboxListenerCollector.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/MailboxListenerCollector.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,60 @@
+package org.apache.james.mailboxmanager.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.james.mailboxmanager.MailboxListener;
+import org.apache.james.mailboxmanager.MessageResult;
+
+public class MailboxListenerCollector implements MailboxListener {
+    
+    protected List addedList =new ArrayList();
+    protected List expungedList =new ArrayList();
+    protected List flaggedList =new ArrayList();
+
+    public void added(MessageResult mr) {
+        addedList.add(mr);
+    }
+
+    public void expunged(MessageResult mr) {
+        expungedList.add(mr);
+    }
+
+    public void flagsUpdated(MessageResult mr, MailboxListener silentListener) {
+        flaggedList.add(mr);
+    }
+    
+    public synchronized List getAddedList(boolean reset) {
+        List list=addedList;
+        if (reset) {
+            addedList=new ArrayList();
+        }
+        return list;
+    }
+
+    public synchronized List getExpungedList(boolean reset) {
+        List list=expungedList;
+        if (reset) {
+            expungedList=new ArrayList();
+        }
+        return list;
+    }
+
+    public synchronized List getFlaggedList(boolean reset) {
+        List list=flaggedList;
+        if (reset) {
+            flaggedList=new ArrayList();
+        }
+        return list;
+    }
+
+    public void mailboxDeleted() {
+    }
+
+    public void mailboxRenamed(String origName, String newName) {
+    }
+
+    public void mailboxRenamed(String newName) {
+    }
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/MessageResultImpl.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,164 @@
+package org.apache.james.mailboxmanager.impl;
+
+import java.util.Date;
+
+import javax.mail.Flags;
+import javax.mail.Flags.Flag;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.james.mailboxmanager.MessageResult;
+import org.apache.mailet.Mail;
+
+public class MessageResultImpl implements MessageResult {
+    
+    private MimeMessage mimeMessage;
+    private long uid;
+    private int msn;
+    private Flags flags;
+    private int size;
+    private Date internalDate;
+    
+
+    public MessageResultImpl(long uid) {
+        this.uid=uid;
+    }
+
+    public MessageResultImpl() {
+    }
+
+    public MessageResultImpl(long uid, Flags flags) {
+        this.uid=uid;
+        this.flags=flags;
+    }
+
+    public MessageResultImpl(MessageResult origMr) {
+        this.uid=origMr.getUid();
+        this.flags=origMr.getFlags();
+        this.mimeMessage=origMr.getMimeMessage();
+    }
+
+    public int getIncludedResults() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public boolean contains(int result) {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    public MimeMessage getMimeMessage() {
+        return mimeMessage;
+    }
+
+    public void setMimeMessage(MimeMessage mimeMessage) {
+        this.mimeMessage=mimeMessage;
+    }
+
+    
+    public long getUid() {
+        return uid;
+    }
+
+    public long getUidValidity() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    public int getMsn() {
+        return msn;
+    }
+
+    public Date getInternalDate() {
+        return internalDate;
+    }
+
+    public Flags getFlags() {
+        return flags;
+    }
+
+    public Mail getMail() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public String getKey() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public void setUid(long uid) {
+        this.uid=uid;
+    }
+    public void setMsn(int msn) {
+        this.msn=msn;
+    }
+    public int getSize() {
+        return size;
+    }
+
+    public void setFlags(Flags flags) {
+        this.flags=flags;
+    }
+
+    public int compareTo(Object o) {
+        MessageResult that=(MessageResult)o;
+        if (this.uid>0 && that.getUid()>0) {
+            return new Long(uid).compareTo(new Long(that.getUid()));    
+        } else {
+            throw new RuntimeException("can't compare");
+        }
+        
+    }
+
+    public void setSize(int size) {
+        this.size=size;
+    }
+
+    public void setInternalDate(Date internalDate) {
+        this.internalDate = internalDate;
+    }
+    
+    public String toString() {
+        return "UID: "+uid+" FLAGS: "+flagsToString(flags);
+    }
+
+    public static  String flagsToString(Flags flags) {
+        if (flags==null) {
+            return "null";
+        }
+        String result="";
+        Flag[] f=flags.getSystemFlags();
+        for (int i = 0; i < f.length; i++) {
+            result +=" "+flagToString(f[i]);
+        }
+        if (result.length()>0) {
+             // without leading space
+            result=result.substring(1);
+        }
+        return result;
+    }
+    public static String flagToString(Flag flag) {
+        if (flag.equals(Flag.ANSWERED)) {
+            return "\\Answered";
+        }
+        if (flag.equals(Flag.DELETED)) {
+            return "\\Deleted";
+        }
+        if (flag.equals(Flag.DRAFT)) {
+            return "\\Draft";
+        }
+        if (flag.equals(Flag.FLAGGED)) {
+            return "\\Flagged";
+        }
+        if (flag.equals(Flag.RECENT)) {
+            return "\\Recent";
+        }
+        if (flag.equals(Flag.SEEN)) {
+            return "\\Seen";
+        }
+        throw new IllegalArgumentException("unknown Flag: "+flag);
+
+    }
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/NamespaceImpl.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/NamespaceImpl.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/NamespaceImpl.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/NamespaceImpl.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,23 @@
+package org.apache.james.mailboxmanager.impl;
+
+import org.apache.james.mailboxmanager.Namespace;
+
+public class NamespaceImpl implements Namespace {
+    
+    private String delimiter;
+    private String name;
+    
+    public NamespaceImpl(String delimiter,String name) {
+        this.delimiter=delimiter;
+        this.name=name;
+    }
+
+    public String getHierarchyDelimter() {
+        return delimiter;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/NamespacesImpl.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/NamespacesImpl.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/NamespacesImpl.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/impl/NamespacesImpl.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,50 @@
+package org.apache.james.mailboxmanager.impl;
+
+import org.apache.james.mailboxmanager.Namespace;
+import org.apache.james.mailboxmanager.Namespaces;
+
+public class NamespacesImpl implements Namespaces {
+	
+	private Namespace[] personal;
+	
+	private Namespace[] shared;
+	
+	private Namespace[] user;
+	
+	private Namespace personalDefault;
+	
+	public Namespace[] getPersonal() {
+		return personal;
+	}
+
+	public Namespace getPersonalDefault() {
+		return personalDefault;
+	}
+
+	public Namespace[] getShared() {
+		return shared;
+	}
+
+	public Namespace[] getUser() {
+		return user;
+	}
+
+	public void setPersonal(Namespace[] personal) {
+		this.personal = personal;
+	}
+
+	public void setPersonalDefault(Namespace personalDefault) {
+		this.personalDefault = personalDefault;
+	}
+
+	public void setShared(Namespace[] shared) {
+		this.shared = shared;
+	}
+
+	public void setUser(Namespace[] user) {
+		this.user = user;
+	}
+	
+	
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/BasicMailbox.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/BasicMailbox.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/BasicMailbox.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/BasicMailbox.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,28 @@
+package org.apache.james.mailboxmanager.mailbox;
+
+import java.util.Collection;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+public interface BasicMailbox {
+
+	/** @return the key */
+	String store(MimeMessage message) throws MessagingException;
+
+	/** @return keys */
+	Collection list() throws MessagingException;
+
+	MimeMessage retrieve(String key);
+
+	/**
+	 * key changes by updating
+	 *  
+	 * @param key the current key
+	 * @return the new key
+	 */
+	String update(String key, MimeMessage message)
+			throws MessagingException;
+
+	void remove(String key);
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/BasicMailboxSession.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/BasicMailboxSession.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/BasicMailboxSession.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/BasicMailboxSession.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,5 @@
+package org.apache.james.mailboxmanager.mailbox;
+
+public interface BasicMailboxSession extends BasicMailbox, MailboxSession {
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/EventQueueingSessionMailbox.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/EventQueueingSessionMailbox.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/EventQueueingSessionMailbox.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/EventQueueingSessionMailbox.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,14 @@
+package org.apache.james.mailboxmanager.mailbox;
+
+import java.util.List;
+
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.MessageResult;
+
+public interface EventQueueingSessionMailbox {
+	
+	MessageResult[] getFlagEvents(boolean reset) throws MailboxManagerException;
+	
+    MessageResult[] getExpungedEvents(boolean reset) throws MailboxManagerException;
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/EventTriggerMailbox.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/EventTriggerMailbox.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/EventTriggerMailbox.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/EventTriggerMailbox.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,32 @@
+package org.apache.james.mailboxmanager.mailbox;
+
+import org.apache.james.mailboxmanager.MailboxListener;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+
+
+
+/**
+ * 
+ * An EventTriggerMailbox will fire an event of the types defined in
+ * MailboxListener. When the underlaying store is modified by mupltiple
+ * instances it has to keep track of last known status and deliver events as
+ * soon as it detects external operations
+ * 
+ */
+public interface EventTriggerMailbox {
+
+	/**
+	 * Implementations of Mailbox may interpret the fact that someone is
+	 * listening and do some caching and even postpone persistence until
+	 * everyone has removed itself.
+	 * 
+	 * @param listener
+	 * @param result
+	 *            which fields to be returned in MessageResult
+	 * @throws MailboxManagerException 
+	 */
+	void addListener(MailboxListener listener, int result) throws MailboxManagerException;
+
+	void removeListener(MailboxListener listener);
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/FlaggedMailbox.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/FlaggedMailbox.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/FlaggedMailbox.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/FlaggedMailbox.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,69 @@
+package org.apache.james.mailboxmanager.mailbox;
+
+import javax.mail.Flags;
+
+import org.apache.james.mailboxmanager.GeneralMessageSet;
+import org.apache.james.mailboxmanager.MailboxListener;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.MessageResult;
+
+public interface FlaggedMailbox extends GeneralMailbox {
+	
+	/**
+	 * @return Flags that can be stored
+	 */
+
+	Flags getPermanentFlags();
+	
+
+	int getRecentCount(boolean reset) throws MailboxManagerException;
+	
+	int getUnseenCount() throws MailboxManagerException;
+    
+    MessageResult getFirstUnseen(int result) throws MailboxManagerException;
+	
+	/**
+	 * 
+	 * @param set
+	 *            <ul>
+	 *            <li> IMAP, Javamail: not required, always expunge all</li>
+	 *            <li> UIDPLUS: requires the possibility of defining a uid range</li>
+	 *            </ul>
+	 * 
+	 * @param result
+	 *            which fields to be returned in MessageResult
+	 * @return MessageResult with the fields defined by <b>result</b><br />
+	 *         <ul>
+	 *         <li> IMAP, UIDPLUS: nothing required </li>
+	 *         <li> Javamail Folder: requires the expunged Message[]</li>
+	 *         </ul>
+	 * @throws MailboxManagerException
+	 *             if anything went wrong
+	 */
+	MessageResult[] expunge(GeneralMessageSet set, int result)
+			throws MailboxManagerException;
+	
+
+	/**
+	 * this is much more straight forward for IMAP instead of setting Flags of
+	 * an array of lazy-loading MimeMessages. <br />
+	 * required by IMAP
+	 * 
+	 * @param flags
+	 *            Flags to be set
+	 * @param value
+	 *            true = set, false = unset
+	 * @param replace
+	 *            replace all Flags with this flags, value has to be true
+	 * @param set
+	 *            the range of messages
+	 * @param silentListener
+	 *            IMAP requires the ability of setting Flags without getting an
+	 *            acknowledge TODO this may be handled only inside of a session
+	 * @throws MailboxManagerException
+	 */
+
+	void setFlags(Flags flags, boolean value, boolean replace, GeneralMessageSet set,
+			MailboxListener silentListener) throws MailboxManagerException;
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/GeneralMailbox.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,85 @@
+package org.apache.james.mailboxmanager.mailbox;
+
+import java.util.Date;
+
+import javax.mail.internet.MimeMessage;
+
+import org.apache.james.mailboxmanager.GeneralMessageSet;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.MessageResult;
+
+public interface GeneralMailbox {
+	
+	/**
+	 * 
+	 * What the Mailbox is able to put out as an result. e.g.: message number, uid, key, MimeMessage, Size, internal Date, flags
+	 * @see MessageResult
+	 */
+	int getMessageResultTypes();
+	
+	/**
+	 * 
+	 * which queries could be made to select a set of messages, e.g.: range of uid or message numbers, a key, a MimeMessage object
+	 * @see GeneralMessageSet
+	 */
+	int getMessageSetTypes();
+	
+	/**
+	 * Example #mail.paul.lists.apache.james-dev (3rd level folder of user paul)
+	 * 
+	 * @return Full folder name with namespace
+	 * @throws MailboxManagerException 
+	 */
+
+	String getName() throws MailboxManagerException;
+
+	int getMessageCount() throws MailboxManagerException;
+	
+
+	/**
+	 * @param internalDate
+	 *            <p>IMAP defines this as the time when the message has arrived to
+	 *            this server (by smtp). Clients are also allowed to set the
+	 *            internalDate on apppend.</p><p>Is this Mail.getLastUpdates() for 
+	 *            James delivery? Should we use MimeMessage.getReceivedDate()?
+	 * @param result
+	 *            which fields to be returned in MessageResult
+	 * @return MessageResult with the fields defined by <b>result</b>
+	 *         <ul>
+	 *         <li> IMAP, Javamail Folder: nothing required </li>
+	 *         <li> UIDPlusFolder: requires to return appended Message or uid</li>
+	 *         <li> UIDPLUS: requires to return appended uid</li>
+	 *         </ul>
+	 * @throws MailboxManagerException
+	 *             if anything went wrong
+	 */
+	MessageResult appendMessage(MimeMessage message, Date internalDate,
+			int result) throws MailboxManagerException;
+	
+	/**
+	 * 
+	 * @param messageSet TODO
+	 * @param message has to belong to this mailbox and either come as the result from an appendMessage or
+	 * getMessages operation
+	 * @param result uid and msn will change TODO should key change, too?
+	 * @return
+	 */
+	
+	MessageResult updateMessage(GeneralMessageSet messageSet, MimeMessage message, int result) throws MailboxManagerException;
+	
+	/**
+	 * 
+	 * @param set
+	 * @return MessageResult with the fields defined by <b>result</b>
+	 *         <ul>
+	 *         <li> IMAP: a set of msn, uid, Flags, header lines, content, mime
+	 *         parts...</li>
+	 *         <li> Javamail Folder: Message[]</li>
+	 *         </ul>
+	 * @throws MailboxManagerException 
+	 */
+
+	MessageResult[] getMessages(GeneralMessageSet set, int result) throws MailboxManagerException;
+
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/GeneralMailboxSession.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/GeneralMailboxSession.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/GeneralMailboxSession.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/GeneralMailboxSession.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,5 @@
+package org.apache.james.mailboxmanager.mailbox;
+
+public interface GeneralMailboxSession extends GeneralMailbox, MailboxSession {
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/ImapMailbox.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/ImapMailbox.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/ImapMailbox.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/ImapMailbox.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,12 @@
+package org.apache.james.mailboxmanager.mailbox;
+
+
+
+/**
+ * Provides access to a single Folder.<br />
+ */
+
+public interface ImapMailbox extends GeneralMailbox, FlaggedMailbox, EventTriggerMailbox, UidMailbox, SearchableMailbox {
+
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/ImapMailboxSession.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/ImapMailboxSession.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/ImapMailboxSession.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/ImapMailboxSession.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,34 @@
+package org.apache.james.mailboxmanager.mailbox;
+
+import org.apache.james.mailboxmanager.MailboxListener;
+import org.apache.james.mailboxmanager.Quota;
+import org.apache.james.mailboxmanager.acl.MailboxRights;
+
+
+/**
+ * This is the Mailbox from the view of the user<br />
+ * 
+ * <p>Not sure whether it should extend ImapMailbox or provide it with a getMailbox() method.</p>
+ * <p>If it extends ImapMailbox it requires an adapter but it would be possible to check rights
+ * and maybe quota on access.</p> 
+ * <p>Another requirements for sessions is to keep the message numbers stable. Maybe message numbers
+ * should only be provided by the session</p>
+ */
+
+public interface ImapMailboxSession extends ImapMailbox, MailboxListener, GeneralMailboxSession, EventQueueingSessionMailbox {
+	
+	
+	/**
+	 *
+	 * @return the effective rights to this mailbox
+	 */
+	MailboxRights myRights();
+	/**
+	 * 
+	 * @return the quota that is assigned to this mailbox
+	 */
+	Quota[] getQuota();
+
+	boolean isSelectable();
+    
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/MailMailbox.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/MailMailbox.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/MailMailbox.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/MailMailbox.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,28 @@
+package org.apache.james.mailboxmanager.mailbox;
+
+import java.util.Date;
+
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.MessageResult;
+import org.apache.mailet.Mail;
+
+/**
+ * 
+ * This is a step to support mail object spools<br />
+ * To fetch Mail objects the normal
+ * 
+ * <pre>
+ * MessageResult[] getMessages(GeneralMessageSet set, int result);
+ * </pre>
+ * 
+ * Method of Mailbox could be used by demanding Mail as an result.
+ */
+
+public interface MailMailbox {
+
+	MessageResult appendMail(Mail mail, Date internalDate, int result)
+			throws MailboxManagerException;
+
+	MessageResult updateMail(Mail mail, Date internalDate, int result)
+			throws MailboxManagerException;
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/Mailbox.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/Mailbox.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/Mailbox.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/Mailbox.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,5 @@
+package org.apache.james.mailboxmanager.mailbox;
+
+public interface Mailbox {
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/MailboxSession.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/MailboxSession.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/MailboxSession.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/MailboxSession.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,10 @@
+package org.apache.james.mailboxmanager.mailbox;
+
+
+public interface MailboxSession extends Mailbox {
+
+    public void close();
+    
+    public boolean isWriteable();
+    
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/SearchableMailbox.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/SearchableMailbox.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/SearchableMailbox.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/SearchableMailbox.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,22 @@
+package org.apache.james.mailboxmanager.mailbox;
+
+import javax.mail.search.SearchTerm;
+
+import org.apache.james.mailboxmanager.GeneralMessageSet;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.MessageResult;
+
+public interface SearchableMailbox {
+	/**
+	 * @param result
+	 *            which fields to be returned in MessageResult
+	 * @return MessageResult with the fields defined by <b>result</b>
+	 *         <ul>
+	 *         <li> IMAP: msn or (msn and uid)</li>
+	 *         <li> Javamail Folder: Message[]</li>
+	 *         </ul>
+	 * @throws MailboxManagerException
+	 *             if anything went wrong
+	 */
+	MessageResult[] search(GeneralMessageSet set,SearchTerm searchTerm, int result) throws MailboxManagerException;
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/UidMailbox.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/UidMailbox.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/UidMailbox.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/mailbox/UidMailbox.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,18 @@
+package org.apache.james.mailboxmanager.mailbox;
+
+import org.apache.james.mailboxmanager.MailboxManagerException;
+
+public interface UidMailbox {
+	
+	
+	long getUidValidity() throws MailboxManagerException;
+	
+	/**
+	 * 
+	 * @return the uid that will be assigned to the next appended message
+	 * @throws MailboxManagerException 
+	 */
+
+	long getUidNext() throws MailboxManagerException;
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/BasicManager.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/BasicManager.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/BasicManager.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/BasicManager.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,16 @@
+package org.apache.james.mailboxmanager.manager;
+
+import org.apache.james.mailboxmanager.mailbox.BasicMailboxSession;
+import org.apache.james.services.User;
+
+public interface BasicManager {
+
+	/**
+	 * 
+	 * @param user
+	 * @return
+	 */
+	BasicMailboxSession getInbox(User user);
+	
+	void deleteAllUserData(User user);
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/GeneralManager.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/GeneralManager.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/GeneralManager.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/GeneralManager.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,145 @@
+package org.apache.james.mailboxmanager.manager;
+
+import org.apache.james.mailboxmanager.GeneralMessageSet;
+import org.apache.james.mailboxmanager.ListResult;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.Namespace;
+import org.apache.james.mailboxmanager.Namespaces;
+import org.apache.james.mailboxmanager.mailbox.GeneralMailbox;
+import org.apache.james.mailboxmanager.mailbox.GeneralMailboxSession;
+import org.apache.james.mailboxmanager.mailbox.ImapMailboxSession;
+import org.apache.james.mailboxmanager.mailbox.MailboxSession;
+import org.apache.james.services.User;
+
+
+/**
+ * <p>
+ * Central MailboxManager which creates, lists, provides, renames and
+ * deletes Mailboxes
+ * </p>
+ * <p>
+ * An important goal is to be JavaMail feature compatible. That means JavaMail
+ * could be used in both directions: As a backend for e.g. accessing a Maildir
+ * JavaMail store or as a frontend to access a JDBC MailboxManager
+ * through JavaMail. This should be possible by not too complicated wrapper
+ * classes. Due to the complexity of JavaMail it might be impossible to avoid
+ * some limitations.
+ * </p>
+ * <p>
+ * Internally MailboxManager deals with named repositories that could have
+ * different implementations. E.g. JDBC connections to different hosts or
+ * Maildir / Mbox like stores. This repositories are identified by its names and
+ * maybe are configured in config.xml. The names of the mailboxes have to be
+ * mapped to the corresponding repository name. For user mailboxes this could be
+ * done by a "User.getRepositoryName()" property. It is imaginable that
+ * repositories lookup further properties from the user object like a path name
+ * for a file based storage method. Until Milestone 6 there is only one named
+ * repository: "default".
+ * </p>
+ * <p>
+ * The only operation that requires dealing with the named repositories directly
+ * is the quota management. It is probably really difficult to implement a quota
+ * system that spans multiple repository implementations. That is why quotas are
+ * created for a specific repository. To be able to administer, repositories and
+ * theier belonging mailboxes can be listet.
+ * </p>
+ */
+
+public interface GeneralManager extends MailboxManager {
+
+	/**
+	 * get a session mailbox 
+	 * 
+	 * @param nameSpaceName
+	 * @param user
+	 * @return
+	 * @throws MailboxManagerException 
+	 */
+	MailboxSession getMailboxSession(String mailboxName,Class neededInterface,int[] setTypes,int resultTypes) throws MailboxManagerException;
+	
+	/**
+	 * Supports 
+	 * 
+	 * @param mailboxName
+	 * @return
+	 * @throws MailboxManagerException
+	 */
+	
+	GeneralMailboxSession getGenericGeneralMailboxSession(String mailboxName) throws MailboxManagerException;
+	
+	ImapMailboxSession getGenericImapMailboxSession(String mailboxName) throws MailboxManagerException;
+
+	/**
+	 * The Namespaces a user has access to.
+	 * @param forUser TODO
+	 * @param user
+	 * 
+	 * @return
+	 */
+	Namespaces getNamespaces(User forUser);
+
+	/**
+	 * To get the Inbox you can just to a mailbox
+	 * defaultNameSpace=ImapMailboxRepository.getPersonalDefaultNameSpace(user)
+	 * inbox=defaultNameSpace.getName()+defaultNameSpace.getHierarchyDelimter()+"INBOX";
+	 * TODO add a convinience method to get directly a session mailbox for a users inbox
+	 * @param forUser TODO
+	 * 
+	 * @return
+	 */
+	Namespace getPersonalDefaultNamespace(User forUser);
+	
+	
+
+	void createMailbox(String mailboxName) throws MailboxManagerException;
+
+	void deleteMailbox(String mailboxName) throws MailboxManagerException;
+
+	void renameMailbox(String from, String to) throws MailboxManagerException;
+
+	/**
+	 * this is done by the MailboxRepository because maybe this operation could
+	 * be optimized in the corresponding store.
+	 * 
+	 * @param from
+	 * @param set
+	 *            messages to copy
+	 * @param to
+	 *            name of the destination mailbox
+	 */
+	void copyMessages(GeneralMailbox from, GeneralMessageSet set, String to) throws MailboxManagerException;
+
+	/**
+	 * 
+	 * @param base
+	 *            hierarchy starting point like #mail.user1 to list mailboxes of
+	 *            user1
+	 * @param expression
+	 *            allows the use of wildcards
+	 * @param subscribed
+	 *            if true, only list subscribed mailboxes (needs interaction
+	 *            with the user-object)
+	 * @param user
+	 * @return
+	 * @throws MailboxManagerException 
+	 */
+
+	ListResult[] list(String base, String expression, boolean subscribed) throws MailboxManagerException;
+
+	/**
+	 * could be implemented later. There could be enviroments where
+	 * subscribtions are stored in the mailbox database. Another possibility is
+	 * to manage subscribtions in the user repository, e.g. a ldap attribute,
+	 * 
+	 * @param mailboxName
+	 * @param value
+	 * @param user
+	 */
+
+	void setSubscription(String mailboxName, boolean value) throws MailboxManagerException;
+
+    boolean existsMailbox(String mailboxName) throws MailboxManagerException;
+
+	void close();
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/MailboxManager.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/MailboxManager.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/MailboxManager.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/MailboxManager.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,5 @@
+package org.apache.james.mailboxmanager.manager;
+
+public interface MailboxManager {
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/MailboxManagerProvider.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/MailboxManagerProvider.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/MailboxManagerProvider.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/MailboxManagerProvider.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,14 @@
+package org.apache.james.mailboxmanager.manager;
+
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.services.User;
+
+public interface MailboxManagerProvider {
+    
+    public MailboxManager getMailboxManagerInstance(User user, Class neededClass) throws MailboxManagerException;
+    
+    public GeneralManager getGeneralManagerInstance(User user) throws MailboxManagerException;
+    
+    public void deleteEverything() throws MailboxManagerException;
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/QuotaManager.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/QuotaManager.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/QuotaManager.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/manager/QuotaManager.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,100 @@
+package org.apache.james.mailboxmanager.manager;
+
+import org.apache.james.mailboxmanager.ListResult;
+import org.apache.james.mailboxmanager.Quota;
+import org.apache.james.services.User;
+
+/**
+ * manages quota. Only getQuotas() will be used by MailboxRepository to create a
+ * session. The other methods will be used by a management user interface
+ * (console/webapp/jmx...) or IMAP ACL extensions.
+ * <p>
+ * The only operation that requires dealing with the named repositories directly
+ * is the quota management. It is probably really difficult to implement a quota
+ * system that spans multiple repository implementations. That is why quotas are
+ * created for a specific repository. To be able to administer, repositories and
+ * theier belonging mailboxes can be listet.
+ * </p>
+ * 
+ */
+
+public interface QuotaManager {
+
+	/**
+	 * Get the quotas that are associated to this mailbox
+	 * 
+	 * @param requestingUser
+	 *            to check credentials
+	 */
+
+	Quota[] getQuotas(String mailboxName, User requestingUser);
+
+	/**
+	 * list the available repositories
+	 * 
+	 * @return names of the repositories
+	 */
+	String[] listRepositories();
+
+	/**
+	 * List the mailboxes that exist in this repository.
+	 * 
+	 * @param repositoryName
+	 * @param base
+	 * @param expression
+	 * @param user
+	 * @return
+	 */
+
+	ListResult[] listForRepository(String repositoryName, String base,
+			String expression, User user);
+
+	/**
+	 * Lists quotas the user is allowed to manage. Via base and expression the
+	 * user is able to browse quotas that are bound to a root mailbox.
+	 * 
+	 * @param repositoryName
+	 * @param base
+	 *            like in list()
+	 * @param expression
+	 *            like in list(), if empty only namespace-root quotas will be
+	 *            listet
+	 * @param user
+	 * @return
+	 */
+	Quota[] listQuotas(String repositoryName, String base, String expression,
+			User requestingUser);
+
+	/**
+	 * <p>
+	 * create a new quota in the given repository
+	 * </p>
+	 * <p>
+	 * An example sitatuation where users create quotas could be setting up auto
+	 * purge for their Trash mailbox. User may be limited to the store where
+	 * theier mailbox resists. To avoid chaos a naming schema should be used.
+	 * </p>
+	 * Changing/updating quotas will be done in quota object itself by calling
+	 * save() method
+	 * 
+	 * @param repositoryName
+	 * @param rootMailbox
+	 *            the root mailbox the quota will be bound to, maybe an empty
+	 *            String for a namespace root quota
+	 * @param quotaName
+	 *            free chosen, has to be unique for the root mailbox
+	 * @param user
+	 *            to check credentials
+	 * @return a new quota object that can be populated with values
+	 */
+
+	Quota createQuota(String repositoryName, String rootMailbox,
+			String quotaName, User user);
+
+	Quota getQuota(String repositoryName, String rootMailbox, String quotaName,
+			User user);
+
+	void removeQuota(String repositoryName, String quotaName,
+			User requestingUser);
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/package.html
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/package.html?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/package.html (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/package.html Mon Oct  9 10:15:30 2006
@@ -0,0 +1,19 @@
+<html>
+  <head>
+    <title></title>
+  </head>
+  <body>
+    <p> This is now some kind of complete as it reflects the ideas I have in mind. Of
+    course it's still far away from being finished. There maybe cleaner ways than MessageResult
+    and GeneralMessageSet... It would be much easier to just write an API for a JDBC based
+    IMAP backend. I hope for discussion and help to make this fit into James.</p>
+    <p> Main topic of discussion should be MailboxRepository and the interfaces which
+      ImapMailbox extends.
+      <br/> Quota and Acl/Rights will stay drafts until the time has come. </p>
+    <p>The level of integration into James code base is an important question. It should be
+      possible to introduce this without having to touch existing James code.
+      NamespaceMailRepository will lookup and wrap a Mailbox. In a long term view more
+      integration should be done like using namespaces in whole james, because it makes no
+      sense to deal with two different approaches which blows up code base.</p>
+  </body>
+</html>
\ No newline at end of file

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/AbstractMailRepository.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/AbstractMailRepository.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/AbstractMailRepository.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/AbstractMailRepository.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,188 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.mailboxmanager.repository;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Random;
+
+import javax.mail.MessagingException;
+
+import org.apache.avalon.framework.logger.LogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.impl.AvalonLogger;
+import org.apache.commons.logging.impl.SimpleLog;
+import org.apache.james.mailrepository.javamail.LockAdapter;
+import org.apache.james.mailrepository.javamail.LockInterface;
+import org.apache.james.services.MailRepository;
+import org.apache.mailet.Mail;
+
+/**
+ * AbstractMailRepository that uses LockInterface
+ * 
+ */
+public abstract class AbstractMailRepository implements MailRepository, LogEnabled
+         {
+
+    /**
+     * Whether 'deep debugging' is turned on.
+     */
+    protected final static boolean DEEP_DEBUG = true;
+
+	private static Random random;
+
+    protected Log log;
+    
+    /**
+     * A lock used to control access to repository elements, locking access
+     * based on the key
+     */
+    private LockInterface lock;
+    
+
+    protected Log getLogger() {
+    	if (log==null) {
+    		log=new SimpleLog("AbstractMailRepository");
+    	}
+        return log;
+    }
+
+    /**
+     * gets the Lock and creates it, if not present. LockInterface offers functionality
+     * of org.apache.james.util.Lock
+     */
+    protected LockInterface getLock() {
+        if (lock==null) {
+            lock = new LockAdapter();
+        }
+        return lock;
+    }
+    
+    /**
+     * possibility to replace Lock implementation. At the moment only used for testing 
+     */
+    void setLock(LockInterface lock) {
+        this.lock=lock;
+    }
+    /**
+     * sets log
+     */
+    public void enableLogging(Logger log) {
+        this.log=new AvalonLogger(log);
+        log.debug("MaiLRepository enableLogging");
+    }
+
+    /**
+     * Removes a specified message
+     * 
+     * @param mail
+     *            the message to be removed from the repository
+     * @throws MessagingException
+     */
+    public void remove(Mail mail) throws MessagingException {
+        getLogger().debug(this.getClass().getName()+" remove by Mail");
+        remove(mail.getName());
+    }
+    
+    
+    /**
+     * Remove a list of messages from disk The collection is simply a list of
+     * mails to delete
+     * 
+     * @param mails
+     * @throws MessagingException
+     */
+    public void remove(final Collection mails) throws MessagingException {
+        if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
+            StringBuffer logBuffer = new StringBuffer(128).append(
+                    this.getClass().getName()).append(
+                    " Removing entry for key ").append(mails);
+
+            getLogger().debug(logBuffer.toString());
+        }
+        Iterator mailList = mails.iterator();
+
+        /*
+         * remove every email from the Collection
+         */
+        while (mailList.hasNext()) {
+            remove(((Mail) mailList.next()).getName());
+        }
+    }
+  
+  
+    /**
+     * Releases a lock on a message identified by a key
+     * 
+     * @param key
+     *            the key of the message to be unlocked
+     * 
+     * @return true if successfully released the lock, false otherwise
+     */
+    public boolean unlock(String key) {
+        if (getLock().unlock(key)) {
+            if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
+                StringBuffer debugBuffer = new StringBuffer(256).append(
+                        "Unlocked ").append(key).append(" for ").append(
+                        Thread.currentThread().getName()).append(" @ ").append(
+                        new java.util.Date(System.currentTimeMillis()));
+                getLogger().debug(debugBuffer.toString());
+            }
+            return true;
+        } else {
+            return false;
+        }
+    }
+    
+    /**
+     * Obtains a lock on a message identified by a key
+     * 
+     * @param key
+     *            the key of the message to be locked
+     * 
+     * @return true if successfully obtained the lock, false otherwise
+     */
+    public boolean lock(String key) {
+        if (getLock().lock(key)) {
+            if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
+                StringBuffer debugBuffer = new StringBuffer(256).append(
+                        "Locked ").append(key).append(" for ").append(
+                        Thread.currentThread().getName()).append(" @ ").append(
+                        new java.util.Date(System.currentTimeMillis()));
+                getLogger().debug(debugBuffer.toString());
+            }
+            return true;
+        } else {
+            return false;
+        }
+    }
+    
+    /**
+     * lazy-loads random 
+     */
+    protected static synchronized Random getRandom() {
+        if (random == null) {
+            random = new Random();
+        }
+        return random;
+
+    }
+    
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/AvalonMailStore.xinfo
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/AvalonMailStore.xinfo?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/AvalonMailStore.xinfo (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/AvalonMailStore.xinfo Mon Oct  9 10:15:30 2006
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+
+<blockinfo>
+
+  <!-- section to describe block -->
+  <block>
+    <version>1.0</version>
+  </block>
+
+  <!-- services that are offered by this block -->
+  <services>
+    <service name="org.apache.avalon.cornerstone.services.store.Store" version="1.0" />
+  </services>
+
+  <dependencies>
+    <dependency>
+      <service name="org.apache.avalon.cornerstone.services.datasources.DataSourceSelector" version="1.0"/>
+    </dependency>
+  </dependencies>
+
+</blockinfo>
+
+

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/MailboxManagerMailRepository.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,458 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.mailboxmanager.repository;
+
+import java.util.ArrayList;
+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;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.commons.logging.Log;
+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.MailboxSession;
+import org.apache.james.mailboxmanager.mailbox.UidMailbox;
+import org.apache.james.mailboxmanager.manager.GeneralManager;
+import org.apache.james.mailboxmanager.manager.MailboxManagerProvider;
+import org.apache.james.services.User;
+import org.apache.james.userrepository.DefaultJamesUser;
+import org.apache.mailet.Mail;
+
+/**
+ * MailRepository wrapper to a MailboxManager <br />
+ * This implementation should be considered as EXPERIMENTAL.
+ * 
+ * TODO examine for thread-safety
+ */
+public class MailboxManagerMailRepository extends AbstractMailRepository
+		implements Configurable, Serviceable {
+
+	/**
+	 * used to map keys to uid and vice versa
+	 */
+	private UidToKeyBidiMap uidToKeyBidiMap = null;
+
+	private GeneralManager mailboxManager;
+
+	private MailboxGateKeeper mailboxGateKeeper;
+
+	private MailboxManagerProvider mailboxManagerProvider;
+
+	private User user;
+
+	protected long addUIDMessage(MimeMessage message) throws MessagingException {
+		try {
+			MessageResult mr = getMailboxGateKeeper().getMailbox().appendMessage(message,
+					new Date(), MessageResult.UID);
+			return mr.getUid();
+		} catch (MailboxManagerException e) {
+			throw new MessagingException(e.getMessage(), e);
+		}
+
+	}
+
+	/**
+	 * Does nothing
+	 * 
+	 * @see Initializable#initialize()
+	 */
+	public void initialize() throws Exception {
+		getLogger().debug("MailboxManagerMailRepository initialized");
+	}
+
+	/**
+	 * Stores a message in this repository.
+	 * 
+	 * @param mc
+	 *            the mail message to store
+	 * @throws MessagingException
+	 */
+	public synchronized void store(Mail mc) throws MessagingException {
+		MimeMessage message = mc.getMessage();
+		String key = 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);
+				if (!wasLocked) {
+					// If it wasn't locked, we want a lock during the store
+					lock(key);
+				}
+			}
+
+			// 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());
+		} finally {
+
+			if (!wasLocked) {
+				// If it wasn't locked, we need to unlock now
+				unlock(key);
+				synchronized (this) {
+					notify();
+				}
+			}
+			getMailboxGateKeeper().free();
+		}
+	}
+
+	/**
+	 * lazy loads UidToKeyBidiMap
+	 * 
+	 * @return
+	 */
+	protected UidToKeyBidiMap getUidToKeyBidiMap() {
+		if (uidToKeyBidiMap == null) {
+			uidToKeyBidiMap = new UidToKeyBidiMapImpl();
+		}
+		return uidToKeyBidiMap;
+	}
+
+	/**
+	 * Used for testing
+	 * 
+	 * @param uidToKeyBidiMap
+	 */
+	void setUidToKeyBidiMap(UidToKeyBidiMap uidToKeyBidiMap) {
+		this.uidToKeyBidiMap = uidToKeyBidiMap;
+	}
+
+	/**
+	 * Retrieves a message given a key. At the moment, keys can be obtained from
+	 * list() in superinterface Store.Repository
+	 * 
+	 * @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 {
+		getLogger().info("retrieve " + key);
+		MimeMessage mm = getMessageFromInbox(key);
+		if (mm == null)
+			return null;
+		Mail mail = new MailImpl(mm);
+		mail.setName(key);
+		return mail;
+	}
+
+	/**
+	 * Removes a message identified by key.
+	 * 
+	 * @param key
+	 *            the key of the message to be removed from the repository
+	 */
+	public synchronized void remove(String key) throws MessagingException {
+		getLogger().info(" remove key:" + key);
+		doLockedRemove(key,true);
+	}
+
+	protected void doLockedRemove(String key,boolean expunge) throws MessagingException {
+		if (lock(key)) {
+			try {
+				doRemove(key,expunge);
+			} finally {
+				unlock(key);
+			}
+		} else {
+			getLogger().info("could not optain lock to remove key:" + key);
+			throw new MessagingException("could not optain lock for remove");
+		}
+	}
+	protected void doRemove(String key,boolean expunge) 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();
+				}
+			}
+		} catch (MailboxManagerException e) {
+			throw new MessagingException(e.getMessage(), e);
+		} finally {
+			getMailboxGateKeeper().free();
+		}
+	}
+
+	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.
+	 * 
+	 * @return an <code>Iterator</code> over the list of keys in the
+	 *         repository
+	 * @throws MessagingException
+	 * 
+	 */
+	public Iterator list() throws MessagingException {
+		getLogger().debug("UIDPlusFolder list");
+		try {
+			getMailboxGateKeeper().use();
+			FlaggedMailbox mailbox = getMailboxGateKeeper().getMailbox();
+			
+			// needed for retainAllListedAndAddedByKeys(String[], Collection)
+			String[] keysBefore = getUidToKeyBidiMap().getKeys();
+			
+			// 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); 
+				}
+			}
+			// 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();
+		} catch (MailboxManagerException e) {
+			throw new MessagingException(e.getMessage(), e);
+		} finally {
+			getMailboxGateKeeper().free();
+		}
+	}
+
+	private MimeMessage getMessageFromInbox(String key)
+			throws MessagingException {
+
+		long uid = getUidToKeyBidiMap().getByKey(key);
+		if (uid < 1) {
+			return null;
+		}
+		MessageResult[] messageResults;
+		try {
+			getMailboxGateKeeper().use();
+			messageResults = getMailboxGateKeeper().getMailbox().getMessages(
+					GeneralMessageSetImpl.oneUid(uid),
+					MessageResult.MIME_MESSAGE);
+		} 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;
+	}
+
+	public void remove(Collection mails) throws MessagingException {
+		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);
+			}
+			doExpunge();
+		} finally {
+			getMailboxGateKeeper().free();
+		}
+
+	}
+
+	protected MailboxGateKeeper getMailboxGateKeeper() {
+		if (mailboxGateKeeper == null) {
+			mailboxGateKeeper = new MailboxGateKeeper();
+		}
+		return mailboxGateKeeper;
+	}
+
+	class MailboxGateKeeper {
+		int open = 0;
+
+		FlaggedMailbox mailbox = null;
+
+		synchronized void use() {
+			open++;
+		}
+
+		synchronized void  free() {
+			if (open < 1) {
+				throw new RuntimeException("use<1 !");
+			}
+			open--;
+			if (open < 1) {
+				if (open == 0) {
+					if (mailbox != null) {
+						((MailboxSession) mailbox).close();
+						mailbox=null;
+					}
+				} else {
+					throw new RuntimeException("use<0 !");
+				}
+			}
+		}
+
+		synchronized FlaggedMailbox getMailbox()
+				throws MailboxManagerException, MessagingException {
+			if (open < 1) {
+				throw new RuntimeException("use<1 !");
+			}
+			if (mailbox == null) {
+				Namespace ns = getMailboxManager().getPersonalDefaultNamespace(
+						user);
+
+				String inbox=ns.getName() + ns.getHierarchyDelimter()+ "INBOX";
+				mailbox = getMailboxManager()
+						.getGenericImapMailboxSession(inbox);
+			}
+			return mailbox;
+		}
+	}
+
+	/**
+	 * lazy loads a MailboxManager from MailboxManagerProvider
+	 * 
+	 */
+	
+	protected GeneralManager getMailboxManager() throws MessagingException,
+			MailboxManagerException {
+		if (mailboxManager == null) {
+			if (user == null) {
+				throw new MessagingException("user is null");
+			}
+			mailboxManager = getMailboxManagerProvider()
+					.getGeneralManagerInstance(user);
+		}
+		return mailboxManager;
+	}
+
+	protected MailboxManagerProvider getMailboxManagerProvider() {
+		return mailboxManagerProvider;
+	}
+
+	public void setMailboxManagerProvider(
+			MailboxManagerProvider mailboxManagerProvider) {
+		this.mailboxManagerProvider = mailboxManagerProvider;
+	}
+
+	public void configure(Configuration conf) throws ConfigurationException {
+		
+		// fetch user name
+		
+		String destinationUrl = conf.getAttribute("destinationURL");
+		if (destinationUrl.endsWith("/")) {
+			destinationUrl = destinationUrl.substring(0, destinationUrl
+					.length() - 1);
+		}
+		String userName = destinationUrl.substring(destinationUrl
+				.lastIndexOf('/') + 1);
+		getLogger().info("Configured for user: '"+userName+"' URL: '"+destinationUrl+"'");
+		setUser(new DefaultJamesUser(userName,"none"));
+	}
+
+
+	public void setUser(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);
+		setMailboxManagerProvider(mailboxManagerProvider);
+	}
+	
+	
+    protected Log getLogger() {
+    	if (log==null) {
+    		log=new SimpleLog("MailboxManagerMailRepository");
+    	}
+        return log;
+    }
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/MyAvalonMailStore.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/MyAvalonMailStore.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/MyAvalonMailStore.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/MyAvalonMailStore.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,7 @@
+package org.apache.james.mailboxmanager.repository;
+
+import org.apache.james.core.AvalonMailStore;
+
+public class MyAvalonMailStore extends AvalonMailStore {
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMap.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMap.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMap.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMap.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,43 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.mailboxmanager.repository;
+
+import java.util.Collection;
+
+/**
+ * Used to map uids to keys and keys to uids 
+ *
+ */
+
+public interface UidToKeyBidiMap {
+
+    boolean containsKey(String key);
+
+    void put(String key, long uid);
+
+    void removeByKey(String key);
+
+    String[] getKeys();
+
+    String getByUid(long uid);
+
+    void retainAllListedAndAddedByKeys(String[] keysBefore, Collection keys);
+
+    long getByKey(String key);
+
+}

Added: james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMapImpl.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMapImpl.java?view=auto&rev=454432
==============================================================================
--- james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMapImpl.java (added)
+++ james/server/sandbox/imap-integration/src/java/org/apache/james/mailboxmanager/repository/UidToKeyBidiMapImpl.java Mon Oct  9 10:15:30 2006
@@ -0,0 +1,69 @@
+package org.apache.james.mailboxmanager.repository;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+public class UidToKeyBidiMapImpl  implements UidToKeyBidiMap {
+
+        private Map keyToUid;
+
+        private Map uidToKey;
+
+        public UidToKeyBidiMapImpl() {
+            keyToUid = new HashMap();
+            uidToKey = new HashMap();
+        }
+
+        public synchronized String[] getKeys() {
+            final ArrayList al = new ArrayList(keyToUid.keySet());
+            final String[] keys = (String[]) al.toArray(new String[0]);
+            return keys;
+        }
+
+        public synchronized void retainAllListedAndAddedByKeys(
+                final String[] before, final Collection listed) {
+            Collection added = new HashSet(keyToUid.keySet());
+            added.removeAll(Arrays.asList(before));
+            Collection retain = new HashSet(listed);
+            retain.addAll(added);
+            keyToUid.keySet().retainAll(retain);
+            uidToKey.keySet().retainAll(keyToUid.values());
+        }
+
+        public synchronized void removeByKey(String key) {
+            long uid = getByKey(key);
+            if (uid > -1) {
+                uidToKey.remove(new Long(uid));
+            }
+            keyToUid.remove(key);
+        }
+
+        public synchronized long getByKey(String key) {
+            Long lo = (Long) keyToUid.get(key);
+            long l = -1;
+            if (lo != null) {
+                l = lo.longValue();
+            }
+            return l;
+        }
+
+        public synchronized String getByUid(long uid) {
+
+            return (String) uidToKey.get(new Long(uid));
+        }
+
+        public synchronized boolean containsKey(String key) {
+            return keyToUid.containsKey(key);
+        }
+
+        public synchronized void put(String key, long uid) {
+            keyToUid.put(key, new Long(uid));
+            uidToKey.put(new Long(uid), key);
+        }
+
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org