Author: norman
Date: Fri Mar 26 18:50:55 2010
New Revision: 928014

URL: http://svn.apache.org/viewvc?rev=928014&view=rev
Log:
Move Poster to extra service since its not for imap only anymore, remove usage 
of getInbox(). (JAMES-983)

Added:
    
james/server/trunk/spoolmanager/src/main/java/org/apache/james/MailboxManagerPoster.java
    
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/ResourceLocatorImpl.java
    
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/SieveMailet.java
Removed:
    
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/sieve/
    
james/server/trunk/spoolmanager/src/test/java/org/apache/james/transport/mailets/LocalDeliveryTest.java
Modified:
    
james/server/trunk/core-api/src/main/java/org/apache/james/services/MailServer.java
    
james/server/trunk/core-library/src/test/java/org/apache/james/services/MailServerTestAllImplementations.java
    james/server/trunk/imapserver/pom.xml
    
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/mina/AsyncImapServer.java
    james/server/trunk/mailets/pom.xml
    
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/AbstractStorageQuota.java
    james/server/trunk/spoolmanager/pom.xml
    
james/server/trunk/spoolmanager/src/main/java/org/apache/james/AbstractMailServer.java
    
james/server/trunk/spoolmanager/src/main/java/org/apache/james/JamesMailetContext.java
    
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java
    
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/ToMultiRepository.java
    james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml

Modified: 
james/server/trunk/core-api/src/main/java/org/apache/james/services/MailServer.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/core-api/src/main/java/org/apache/james/services/MailServer.java?rev=928014&r1=928013&r2=928014&view=diff
==============================================================================
--- 
james/server/trunk/core-api/src/main/java/org/apache/james/services/MailServer.java
 (original)
+++ 
james/server/trunk/core-api/src/main/java/org/apache/james/services/MailServer.java
 Fri Mar 26 18:50:55 2010
@@ -100,15 +100,7 @@ public interface MailServer
     void sendMail(MimeMessage message)
         throws MessagingException;        
 
-    /**
-     * Retrieve the primary mailbox for userName. For POP3 style stores this
-     * is their (sole) mailbox.
-     *
-     * @param userName - the name of the user
-     * @return a reference to an initialised mailbox
-     */
-    MailRepository getUserInbox(String userName);
-
+  
     /**
      * Generate a new identifier/name for a mail being processed by this 
server.
      *

Modified: 
james/server/trunk/core-library/src/test/java/org/apache/james/services/MailServerTestAllImplementations.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/core-library/src/test/java/org/apache/james/services/MailServerTestAllImplementations.java?rev=928014&r1=928013&r2=928014&view=diff
==============================================================================
--- 
james/server/trunk/core-library/src/test/java/org/apache/james/services/MailServerTestAllImplementations.java
 (original)
+++ 
james/server/trunk/core-library/src/test/java/org/apache/james/services/MailServerTestAllImplementations.java
 Fri Mar 26 18:50:55 2010
@@ -97,21 +97,4 @@ abstract public class MailServerTestAllI
         
     }
 
-    public void testGetNonexistingUserInbox() throws Exception {
-
-        MailServer mailServer = createMailServer();
-
-        String userName = "testNonexisitingUserName";
-        MailRepository userInbox = null;
-        
-        userInbox = mailServer.getUserInbox(userName);
-        assertEquals("test user does not exist", null, userInbox);
-    }
-    
-    public void testGetExisitingUserInbox() throws Exception {
-        MailServer mailServer = createMailServer();
-
-        MailRepository userInbox = mailServer.getUserInbox(EXISTING_USER_NAME);
-        assertNotNull("existing user exists", userInbox);
-    }
 }

Modified: james/server/trunk/imapserver/pom.xml
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imapserver/pom.xml?rev=928014&r1=928013&r2=928014&view=diff
==============================================================================
--- james/server/trunk/imapserver/pom.xml (original)
+++ james/server/trunk/imapserver/pom.xml Fri Mar 26 18:50:55 2010
@@ -52,10 +52,6 @@
       <artifactId>apache-mailet</artifactId>
     </dependency>
 
-    <dependency>
-      <groupId>org.apache.james</groupId>
-      <artifactId>apache-jsieve-mailet</artifactId>
-    </dependency>
 
     <dependency>
        <groupId>org.apache.geronimo.specs</groupId>

Modified: 
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/mina/AsyncImapServer.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/mina/AsyncImapServer.java?rev=928014&r1=928013&r2=928014&view=diff
==============================================================================
--- 
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/mina/AsyncImapServer.java
 (original)
+++ 
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/mina/AsyncImapServer.java
 Fri Mar 26 18:50:55 2010
@@ -19,13 +19,7 @@
 
 package org.apache.james.imapserver.mina;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.Date;
-
 import javax.annotation.Resource;
-import javax.mail.MessagingException;
-import javax.mail.internet.MimeMessage;
 
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.HierarchicalConfiguration;
@@ -33,12 +27,8 @@ import org.apache.james.imap.api.ImapCon
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.decode.ImapDecoder;
 import org.apache.james.imap.encode.ImapEncoder;
-import org.apache.james.imap.mailbox.Mailbox;
-import org.apache.james.imap.mailbox.MailboxManager;
-import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.main.ImapRequestHandler;
 import org.apache.james.socket.mina.AbstractAsyncServer;
-import org.apache.jsieve.mailet.Poster;
 import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
 import org.apache.mina.core.service.IoHandler;
 
@@ -46,7 +36,7 @@ import org.apache.mina.core.service.IoHa
  * Async ImapServer which use MINA for socket handling
  *
  */
-public class AsyncImapServer extends AbstractAsyncServer implements 
ImapConstants, Poster{
+public class AsyncImapServer extends AbstractAsyncServer implements 
ImapConstants{
 
     private static final String softwaretype = "JAMES "+VERSION+" Server "; 
//+ Constants.SOFTWARE_VERSION;
 
@@ -56,8 +46,6 @@ public class AsyncImapServer extends Abs
 
     private ImapDecoder decoder;
 
-    private MailboxManager mailboxManager;
-
     @Resource(name="imapDecoder")
     public void setImapDecoder(ImapDecoder decoder) {
         this.decoder = decoder;
@@ -72,11 +60,6 @@ public class AsyncImapServer extends Abs
     public void setImapProcessor(ImapProcessor processor) {
         this.processor = processor;
     }
-   
-    @Resource(name="mailboxmanager")
-    public void setMailboxManager(MailboxManager mailboxManager) {
-        this.mailboxManager = mailboxManager;
-    }
     
     @Override
     public void doConfigure( final HierarchicalConfiguration configuration ) 
throws ConfigurationException {
@@ -115,93 +98,4 @@ public class AsyncImapServer extends Abs
         return new DefaultIoFilterChainBuilder();
     }
 
-    /**
-     * @see org.apache.jsieve.mailet.Poster#post(java.lang.String, 
javax.mail.internet.MimeMessage)
-     */
-    public void post(String url, MimeMessage mail)throws MessagingException {
-        final int endOfScheme = url.indexOf(':');
-        if (endOfScheme < 0) {
-            throw new MessagingException("Malformed URI");
-        } else {
-            final String scheme = url.substring(0, endOfScheme);
-            if ("mailbox".equals(scheme)) {
-                final int startOfUser = endOfScheme + 3;
-                final int endOfUser = url.indexOf('@', startOfUser);
-                if (endOfUser < 0) {
-                    // TODO: when user missing, append to a default location
-                    throw new MessagingException("Shared mailbox is not 
supported");
-                } else {
-                    String user = url.substring(startOfUser, endOfUser);
-                    final int startOfHost = endOfUser + 1;
-                    final int endOfHost  = url.indexOf('/', startOfHost);
-                    final String host = url.substring(startOfHost, endOfHost);
-                    //if (!"localhost".equals(host)) {
-                    if (getMailServer().isLocalServer(host) == false) {
-                        //TODO: possible support for clustering?
-                        throw new MessagingException("Only local mailboxes are 
supported");
-                    } else {
-                        final String urlPath;
-                        final int length = url.length();
-                        if (endOfHost + 1 == length) {
-                            urlPath = "INBOX";
-                        } else {
-                            urlPath = url.substring(endOfHost, length);
-                        }
-                        
-                        // check if we should use the full emailaddress as 
username
-                        if (getMailServer().supportVirtualHosting()) {
-                            user = user + "@" + host;
-                        } 
-                        
-                        final MailboxSession session = 
mailboxManager.createSystemSession(user, getLogger());
-                        
-                        // start processing request
-                        mailboxManager.startProcessingRequest(session);
-
-                        // This allows Sieve scripts to use a standard 
delimiter regardless of mailbox implementation
-                        String destination = urlPath.replace('/', 
session.getPersonalSpace().getDeliminator());
-                        
-                        if (destination == null || "".equals(destination)) {
-                            destination = "INBOX";
-                        }
-                        final String name = mailboxManager.resolve(user, 
destination);
-                        try
-                        {
-                            if ("INBOX".equalsIgnoreCase(destination) && 
!(mailboxManager.mailboxExists(name, session))) {
-                                mailboxManager.createMailbox(name, session);
-                            }
-                            final Mailbox mailbox = 
mailboxManager.getMailbox(name, session);
-                            
-                            if (mailbox == null) {
-                                final String error = "Mailbox for user " + user
-                                        + " was not found on this server.";
-                                throw new MessagingException(error);
-                            }
-
-                            final ByteArrayOutputStream baos = new 
ByteArrayOutputStream();
-                            mail.writeTo(baos);
-                            mailbox.appendMessage(baos.toByteArray() , new 
Date(), session, true, null);
-                        }
-                        catch (IOException e)
-                        {
-                            throw new MessagingException("Failed to write mail 
message", e);
-                        }
-                        finally 
-                        {
-                            session.close();   
-                            mailboxManager.logout(session, true);
-                            
-                            // stop processing request
-                            mailboxManager.endProcessingRequest(session);
-                        }
-                    }
-                }
-            } else {
-                // TODO: add support for more protocols
-                // TODO: for example mailto: for forwarding over SMTP
-                // TODO: for example xmpp: for forwarding over Jabber
-                throw new MessagingException("Unsupported protocol");
-            }
-        }
-    }
 }

Modified: james/server/trunk/mailets/pom.xml
URL: 
http://svn.apache.org/viewvc/james/server/trunk/mailets/pom.xml?rev=928014&r1=928013&r2=928014&view=diff
==============================================================================
--- james/server/trunk/mailets/pom.xml (original)
+++ james/server/trunk/mailets/pom.xml Fri Mar 26 18:50:55 2010
@@ -74,7 +74,10 @@
       <groupId>org.apache.james.protocols</groupId>
       <artifactId>protocols-smtp</artifactId>
     </dependency>
-
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-james-imap-mailbox</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.apache.james</groupId>
       <artifactId>apache-mailet-base</artifactId>

Modified: 
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/AbstractStorageQuota.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/AbstractStorageQuota.java?rev=928014&r1=928013&r2=928014&view=diff
==============================================================================
--- 
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/AbstractStorageQuota.java
 (original)
+++ 
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/AbstractStorageQuota.java
 Fri Mar 26 18:50:55 2010
@@ -21,20 +21,25 @@
 
 package org.apache.james.transport.matchers;
 
+import java.util.Iterator;
+
+import javax.annotation.Resource;
+import javax.mail.MessagingException;
+
+import org.apache.commons.logging.Log;
 import org.apache.james.api.user.JamesUser;
 import org.apache.james.api.user.UsersRepository;
-import org.apache.james.lifecycle.LifecycleUtil;
-import org.apache.james.services.MailRepository;
-import org.apache.james.services.MailServer;
+import org.apache.james.imap.mailbox.Mailbox;
+import org.apache.james.imap.mailbox.MailboxManager;
+import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.imap.mailbox.MessageRange;
+import org.apache.james.imap.mailbox.MessageResult;
+import org.apache.james.imap.mailbox.MessageResult.FetchGroup;
+import org.apache.james.imap.mailbox.util.FetchGroupImpl;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.MailetContext;
 
-import javax.annotation.Resource;
-import javax.mail.MessagingException;
-
-import java.util.Iterator;
-
 /**
  * <P>Experimental: Abstract matcher checking whether a recipient has exceeded 
a maximum allowed
  * <I>storage</I> quota for messages standing in his inbox.</P>
@@ -49,11 +54,11 @@ import java.util.Iterator;
  */
 abstract public class AbstractStorageQuota extends AbstractQuotaMatcher { 
 
-    private MailServer mailServer;
+    private MailboxManager manager;
 
-    @Resource(name="James")
-    public void setMailServer(MailServer mailServer) {
-        this.mailServer = mailServer;
+    @Resource(name="mailboxmanager")
+    public void setMailboxManager(MailboxManager manager) {
+        this.manager = manager;
     }
     
     @Resource(name="localusersrepository")
@@ -86,20 +91,92 @@ abstract public class AbstractStorageQuo
      */    
     protected long getUsed(MailAddress recipient, Mail _) throws 
MessagingException {
         long size = 0;
-        MailRepository userInbox = 
mailServer.getUserInbox(getPrimaryName(recipient.getLocalPart()));
-        for (Iterator<String> it = userInbox.list(); it.hasNext(); ) {
-            String key = it.next();
-            Mail mc = userInbox.retrieve(key);
-            // Retrieve can return null if the mail is no longer in the store.
-            if (mc != null) try {
-                size += mc.getMessageSize();
-            } catch (Throwable e) {
-                // MailRepository.retrieve() does NOT lock the message.
-                // It could be deleted while we're looping.
-                log("Exception in getting message size: " + e.getMessage());
-            }
-            LifecycleUtil.dispose(mc);
+        MailboxSession session = 
manager.createSystemSession(getPrimaryName(recipient.getLocalPart()), new Log() 
{
+
+                       public void debug(Object arg0) {
+                               // just consume                                 
+                       }
+
+                       public void debug(Object arg0, Throwable arg1) {
+                               // just consume 
+                       }
+
+                       public void error(Object arg0) {
+                               log(arg0.toString());
+
+                       }
+
+                       public void error(Object arg0, Throwable arg1) {
+                               log(arg0.toString(),arg1);
+                       }
+
+                       public void fatal(Object arg0) {
+                               log(arg0.toString());
+                       }
+
+                       public void fatal(Object arg0, Throwable arg1) {
+                               log(arg0.toString(), arg1);                     
        
+                       }
+
+                       public void info(Object arg0) {
+                               log(arg0.toString());
+                       }
+
+                       public void info(Object arg0, Throwable arg1) {
+                               log(arg0.toString(), arg1);
+                               
+                       }
+
+                       public boolean isDebugEnabled() {
+                               return false;
+                       }
+
+                       public boolean isErrorEnabled() {
+                               return true;
+                       }
+
+                       public boolean isFatalEnabled() {
+                               return true;
+                       }
+
+                       public boolean isInfoEnabled() {
+                               return true;
+                       }
+
+                       public boolean isTraceEnabled() {
+                               return false;
+                       }
+
+                       public boolean isWarnEnabled() {
+                               return true;
+                       }
+
+                       public void trace(Object arg0) {
+                               // just consume                                 
+                       }
+
+                       public void trace(Object arg0, Throwable arg1) {
+                               // just consume                                 
+                       }
+
+                       public void warn(Object arg0) {
+                               log(arg0.toString());
+                       }
+
+                       public void warn(Object arg0, Throwable arg1) {
+                               log(arg0.toString(), arg1);
+                       }
+               
+        });
+        manager.startProcessingRequest(session);
+        Mailbox mailbox = manager.getMailbox(manager.getUserNameSpacePrefix() 
+ manager.getDelimiter() + "INBOX", session);
+        Iterator<MessageResult> results = 
mailbox.getMessages(MessageRange.all(), new FetchGroupImpl(FetchGroup.MINIMAL), 
session);
+        
+        while (results.hasNext()) {
+               size += results.next().getSize();
         }
+        manager.startProcessingRequest(session);
+        manager.logout(session, true);
         return size;
     }
 

Modified: james/server/trunk/spoolmanager/pom.xml
URL: 
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/pom.xml?rev=928014&r1=928013&r2=928014&view=diff
==============================================================================
--- james/server/trunk/spoolmanager/pom.xml (original)
+++ james/server/trunk/spoolmanager/pom.xml Fri Mar 26 18:50:55 2010
@@ -67,7 +67,15 @@
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-annotation_1.0_spec</artifactId>
     </dependency>
-
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-james-imap-mailbox</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-jsieve-mailet</artifactId>
+    </dependency>
     <dependency>
       <groupId>commons-collections</groupId>
       <artifactId>commons-collections</artifactId>

Modified: 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/AbstractMailServer.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/AbstractMailServer.java?rev=928014&r1=928013&r2=928014&view=diff
==============================================================================
--- 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/AbstractMailServer.java
 (original)
+++ 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/AbstractMailServer.java
 Fri Mar 26 18:50:55 2010
@@ -30,7 +30,6 @@ import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
-import java.util.Map;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.Resource;
@@ -42,8 +41,6 @@ import javax.mail.internet.ParseExceptio
 
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.ProducerTemplate;
-import org.apache.commons.collections.map.ReferenceMap;
-import org.apache.commons.configuration.CombinedConfiguration;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.logging.Log;
@@ -56,13 +53,10 @@ import org.apache.james.core.MailImpl;
 import org.apache.james.impl.jamesuser.JamesUsersRepository;
 import org.apache.james.lifecycle.Configurable;
 import org.apache.james.lifecycle.LogEnabled;
-import org.apache.james.services.MailRepository;
 import org.apache.james.services.MailServer;
-import org.apache.james.services.store.Store;
 import org.apache.james.transport.camel.InMemoryMail;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
-import org.apache.mailet.Mailet;
 
 /**
  * Core class for JAMES. Provides three primary services:
@@ -91,17 +85,6 @@ public abstract class AbstractMailServer
 
 
     /**
-     * The mail store containing the inbox repository and the spool.
-     */
-    private Store store;
-
-  
-    /**
-     * The root URL used to get mailboxes from the repository
-     */
-    private String inboxRootURL;
-
-    /**
      * The user repository for this mail server.  Contains all the users with 
inboxes
      * on this server.
      */
@@ -120,19 +103,6 @@ public abstract class AbstractMailServer
     private static int count = 0;
     private static final Object countLock = new Object();
 
-
-    /**
-     * A map used to store mailboxes and reduce the cost of lookup of 
individual
-     * mailboxes.
-     */
-    private Map<String,MailRepository> mailboxes = new ReferenceMap();
-
-    /**
-     * Currently used by storeMail to avoid code duplication (we moved store 
logic to that mailet).
-     * TODO We should remove this and its initialization when we remove 
storeMail method.
-     */
-    protected Mailet localDeliveryMailet;
-
     private DomainList domains;
     
     private boolean virtualHosting = false;
@@ -162,29 +132,6 @@ public abstract class AbstractMailServer
         this.producerTemplate = producerTemplate;
     }
     
-    
-
-    /**
-     * Set Store to use
-     * 
-     * @param store the Store to use
-     */
-    @Resource(name="mailstore")
-    public void setStore(Store store) {
-        this.store = store;
-    }
-
-
-    /**
-     * Set the UsersRepository to use
-     * 
-     * @param localusers the UserRepository to use
-     */
-    @Resource(name="localusersrepository")
-    public void setUsersRepository(UsersRepository localusers) {
-        this.localusers = localusers;
-    }
-    
     /*
      * (non-Javadoc)
      * @see 
org.apache.james.lifecycle.LogEnabled#setLog(org.apache.commons.logging.Log)
@@ -207,8 +154,6 @@ public abstract class AbstractMailServer
 
         logger.info("JAMES init...");
 
-        initializeServices();
-
         if (conf.getKeys("usernames").hasNext()) {
             HierarchicalConfiguration userNamesConf = 
conf.configurationAt("usernames");
 
@@ -241,8 +186,6 @@ public abstract class AbstractMailServer
 
         initializeServernames();
 
-        inboxRootURL = 
conf.configurationAt("inboxRepository.repository").getString("[...@destinationurl]");
-
         logger.info("Private Repository LocalInbox opened");
         
         virtualHosting = conf.getBoolean("enableVirtualHosting", false);
@@ -276,23 +219,6 @@ public abstract class AbstractMailServer
         logger.info("JAMES ...init end");
     }
 
-    private void initializeServices() throws Exception {
-        try {
-            if (logger.isDebugEnabled()) {
-                logger.debug("Using Store: " + store.toString());
-            }
-        } catch (Exception e) {
-            if (logger.isWarnEnabled()) {
-                logger.warn("Can't get Store: " + e);
-            }
-        }
-
-
-      
-        if (logger.isDebugEnabled()) {
-            logger.debug("Using LocalUsersRepository: " + 
localusers.toString());
-        }    
-    }
 
     private void initializeServernames() throws ConfigurationException, 
ParseException {
         String defaultDomain = getDefaultDomain();
@@ -389,67 +315,6 @@ public abstract class AbstractMailServer
     }
 
     /**
-     * @see org.apache.james.services.MailServer#getUserInbox(java.lang.String)
-     */
-    public synchronized MailRepository getUserInbox(String userName) {
-        MailRepository userInbox = null;
-        
-        if (virtualHosting == false && (userName.indexOf("@") < 0) == false) {
-            userName = userName.split("@")[0];
-        }
-
-        userInbox = (MailRepository) mailboxes.get(userName);
-
-        if (userInbox != null) {
-            return userInbox;
-        /*
-         * we're using a ReferenceMap with HARD keys and SOFT values
-         * so it could happen to find a null value after a second pass
-         * of a full GC and we should simply lookup it again
-         */
-//        } else if (mailboxes.containsKey(userName)) {
-//            // we have a problem
-//            getLogger().error("Null mailbox for non-null key");
-//            throw new RuntimeException("Error in getUserInbox.");
-        } else {
-            // need mailbox object
-            if (logger.isDebugEnabled()) {
-                logger.debug("Retrieving and caching inbox for " + userName );
-            }
-
-            StringBuffer destinationBuffer = new StringBuffer(192);
-                  
-            if (virtualHosting == true && inboxRootURL.startsWith("file://") 
&& !(userName.indexOf("@") < 0)) {
-                String userArgs[] = userName.split("@");
-                            
-                // build the url like : 
file://var/mail/inboxes/domain/username/
-                
destinationBuffer.append(inboxRootURL).append(userArgs[1]).append("/").append(userArgs[0]).append("/");
-            } else {
-                
destinationBuffer.append(inboxRootURL).append(userName).append("/");
-            }
-                 
-            String destination = destinationBuffer.toString();
-            try {
-                // Copy the inboxRepository configuration and modify the 
destinationURL
-                CombinedConfiguration mboxConf = new CombinedConfiguration();
-                
mboxConf.addConfiguration(conf.configurationAt("inboxRepository.repository"));
-                mboxConf.setProperty("[...@destinationurl]", destination);
-
-                userInbox = (MailRepository) store.select(mboxConf);
-                if (userInbox!=null) {
-                    mailboxes.put(userName, userInbox);
-                }
-            } catch (Exception e) {
-                if (logger.isErrorEnabled()) {
-                    logger.error("Cannot open user Mailbox",e);
-                }
-                throw new RuntimeException("Error in getUserInbox.",e);
-            }
-            return userInbox;
-        }
-    }
-
-    /**
      * <p>Note that this method ensures that James cannot be run in a 
distributed
      * fashion.</p>
      * <p>Two instances may return the same ID. 

Modified: 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/JamesMailetContext.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/JamesMailetContext.java?rev=928014&r1=928013&r2=928014&view=diff
==============================================================================
--- 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/JamesMailetContext.java
 (original)
+++ 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/JamesMailetContext.java
 Fri Mar 26 18:50:55 2010
@@ -39,7 +39,6 @@ import javax.mail.internet.MimeMessage;
 import javax.mail.internet.ParseException;
 
 import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.DefaultConfigurationBuilder;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.james.api.dnsservice.DNSService;
@@ -73,8 +72,6 @@ public class JamesMailetContext implemen
 
     private UsersRepository localusers;
 
-    private LocalDelivery localDeliveryMailet;
-
     /**
      * The address of the postmaster for this server
      */
@@ -107,8 +104,6 @@ public class JamesMailetContext implemen
     @PostConstruct
     public void init() throws Exception {
 
-        initializeLocalDeliveryMailet();
-
         initPostmaster();
     }
 
@@ -397,18 +392,6 @@ public class JamesMailetContext implemen
         }
     }
 
-    private void initializeLocalDeliveryMailet() throws MessagingException {
-        // We can safely remove this and the localDeliveryField when we
-        // remove the storeMail method from James and from the MailetContext
-        DefaultConfigurationBuilder conf = new DefaultConfigurationBuilder();
-        MailetConfigImpl configImpl = new MailetConfigImpl();
-        configImpl.setMailetName("LocalDelivery");
-        configImpl.setConfiguration(conf);
-        configImpl.setMailetContext(this);
-        localDeliveryMailet = new LocalDelivery();
-        localDeliveryMailet.init(configImpl);
-    }
-
     /**
      * This method has been moved to LocalDelivery (the only client of the
      * method). Now we can safely remove it from the Mailet API and from this
@@ -421,19 +404,10 @@ public class JamesMailetContext implemen
      *             do the local delivery.
      * @see 
org.apache.mailet.MailetContext#storeMail(org.apache.mailet.MailAddress,
      *      org.apache.mailet.MailAddress, javax.mail.internet.MimeMessage)
+     *      
      */
     public void storeMail(MailAddress sender, MailAddress recipient, 
MimeMessage msg) throws MessagingException {
-        if (recipient == null) {
-            throw new IllegalArgumentException("Recipient for mail to be 
spooled cannot be null.");
-        }
-        if (msg == null) {
-            throw new IllegalArgumentException("Mail message to be spooled 
cannot be null.");
-        }
-        Collection<MailAddress> recipients = new HashSet<MailAddress>();
-        recipients.add(recipient);
-        MailImpl m = new MailImpl(mailServer.getId(), sender, recipients, msg);
-        localDeliveryMailet.service(m);
-        LifecycleUtil.dispose(m);
+       throw new UnsupportedOperationException("Was removed");
     }
 
     public void setLog(Log log) {

Added: 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/MailboxManagerPoster.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/MailboxManagerPoster.java?rev=928014&view=auto
==============================================================================
--- 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/MailboxManagerPoster.java
 (added)
+++ 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/MailboxManagerPoster.java
 Fri Mar 26 18:50:55 2010
@@ -0,0 +1,156 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Date;
+
+import javax.annotation.Resource;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.commons.logging.Log;
+import org.apache.james.imap.mailbox.Mailbox;
+import org.apache.james.imap.mailbox.MailboxManager;
+import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.lifecycle.LogEnabled;
+import org.apache.james.services.MailServer;
+import org.apache.jsieve.mailet.Poster;
+
+/**
+ * Post to Mail to MailboxManager implementations
+ * 
+ *
+ */
+public class MailboxManagerPoster implements Poster, LogEnabled{
+
+    private MailboxManager mailboxManager;
+       private MailServer mailserver;
+       private Log logger;
+
+
+    @Resource(name="James")
+    public void setMailServer(MailServer mailserver) {
+        this.mailserver = mailserver;
+    }
+    
+    @Resource(name="mailboxmanager")
+    public void setMailboxManager(MailboxManager mailboxManager) {
+        this.mailboxManager = mailboxManager;
+    }
+
+    /**
+     * @see org.apache.jsieve.mailet.Poster#post(java.lang.String, 
javax.mail.internet.MimeMessage)
+     */
+    public void post(String url, MimeMessage mail)throws MessagingException {
+        final int endOfScheme = url.indexOf(':');
+        if (endOfScheme < 0) {
+            throw new MessagingException("Malformed URI");
+        } else {
+            final String scheme = url.substring(0, endOfScheme);
+            if ("mailbox".equals(scheme)) {
+                final int startOfUser = endOfScheme + 3;
+                final int endOfUser = url.indexOf('@', startOfUser);
+                if (endOfUser < 0) {
+                    // TODO: when user missing, append to a default location
+                    throw new MessagingException("Shared mailbox is not 
supported");
+                } else {
+                    String user = url.substring(startOfUser, endOfUser);
+                    final int startOfHost = endOfUser + 1;
+                    final int endOfHost  = url.indexOf('/', startOfHost);
+                    final String host = url.substring(startOfHost, endOfHost);
+                    //if (!"localhost".equals(host)) {
+                    if (mailserver.isLocalServer(host) == false) {
+                        //TODO: possible support for clustering?
+                        throw new MessagingException("Only local mailboxes are 
supported");
+                    } else {
+                        final String urlPath;
+                        final int length = url.length();
+                        if (endOfHost + 1 == length) {
+                            urlPath = "INBOX";
+                        } else {
+                            urlPath = url.substring(endOfHost, length);
+                        }
+                        
+                        // check if we should use the full emailaddress as 
username
+                        if (mailserver.supportVirtualHosting()) {
+                            user = user + "@" + host;
+                        } 
+                        
+                        final MailboxSession session = 
mailboxManager.createSystemSession(user, logger);
+                        
+                        // start processing request
+                        mailboxManager.startProcessingRequest(session);
+
+                        // This allows Sieve scripts to use a standard 
delimiter regardless of mailbox implementation
+                        String destination = urlPath.replace('/', 
session.getPersonalSpace().getDeliminator());
+                        
+                        if (destination == null || "".equals(destination)) {
+                            destination = "INBOX";
+                        }
+                        final String name = mailboxManager.resolve(user, 
destination);
+                        try
+                        {
+                            if ("INBOX".equalsIgnoreCase(destination) && 
!(mailboxManager.mailboxExists(name, session))) {
+                                mailboxManager.createMailbox(name, session);
+                            }
+                            final Mailbox mailbox = 
mailboxManager.getMailbox(name, session);
+                            
+                            if (mailbox == null) {
+                                final String error = "Mailbox for user " + user
+                                        + " was not found on this server.";
+                                throw new MessagingException(error);
+                            }
+
+                            final ByteArrayOutputStream baos = new 
ByteArrayOutputStream();
+                            mail.writeTo(baos);
+                            mailbox.appendMessage(baos.toByteArray() , new 
Date(), session, true, null);
+                        }
+                        catch (IOException e)
+                        {
+                            throw new MessagingException("Failed to write mail 
message", e);
+                        }
+                        finally 
+                        {
+                            session.close();   
+                            mailboxManager.logout(session, true);
+                            
+                            // stop processing request
+                            mailboxManager.endProcessingRequest(session);
+                        }
+                    }
+                }
+            } else {
+                // TODO: add support for more protocols
+                // TODO: for example mailto: for forwarding over SMTP
+                // TODO: for example xmpp: for forwarding over Jabber
+                throw new MessagingException("Unsupported protocol");
+            }
+        }
+    }
+
+    /*
+     * 
+     */
+       public void setLog(Log log) {
+               this.logger = log;
+       }
+}

Modified: 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java?rev=928014&r1=928013&r2=928014&view=diff
==============================================================================
--- 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java
 (original)
+++ 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java
 Fri Mar 26 18:50:55 2010
@@ -21,10 +21,10 @@
 
 package org.apache.james.transport.mailets;
 
-import org.apache.commons.collections.iterators.IteratorChain;
 import org.apache.james.api.user.UsersRepository;
 import org.apache.james.api.user.UsersStore;
 import org.apache.james.services.MailServer;
+import org.apache.jsieve.mailet.Poster;
 import org.apache.mailet.base.GenericMailet;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailetConfig;
@@ -34,7 +34,6 @@ import javax.annotation.Resource;
 import javax.mail.MessagingException;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Iterator;
 
 /**
@@ -55,20 +54,24 @@ public class LocalDelivery extends Gener
     /**
      * Mailet that actually store the message
      */
-    private ToMultiRepository deliveryMailet;
-
+    private SieveMailet sieveMailet;
+    
     private UsersRepository usersRepository;
 
     private UsersStore usersStore;
 
     private MailServer mailServer;
 
+       private Poster poster;
 
+
+    
     @Resource(name="localusersrepository")
     public void setUsersRepository(UsersRepository usersRepository) {
         this.usersRepository = usersRepository;
     }
     
+    
     @Resource(name="users-store")
     public void setUsersStore(UsersStore usersStore) {
         this.usersStore = usersStore;
@@ -79,6 +82,11 @@ public class LocalDelivery extends Gener
         this.mailServer = mailServer;
     }
     
+
+    @Resource(name="org.apache.jsieve.mailet.Poster")
+    public void setPoster(Poster poster) {
+        this.poster = poster;
+    }
     
     /**
      * Delivers a mail to a local mailbox.
@@ -92,7 +100,7 @@ public class LocalDelivery extends Gener
     public void service(Mail mail) throws MessagingException {
         aliasingMailet.service(mail);
         if (mail.getState() != Mail.GHOST) {
-            deliveryMailet.service(mail);
+               sieveMailet.service(mail);
         }
     }
 
@@ -115,34 +123,21 @@ public class LocalDelivery extends Gener
         aliasingMailet.setUsersRepository(usersRepository);
         aliasingMailet.setUsersStore(usersStore);
         aliasingMailet.init(getMailetConfig());
-        deliveryMailet = new ToMultiRepository();
-        deliveryMailet.setMailServer(mailServer);
+        sieveMailet = new SieveMailet();
         MailetConfig m = new MailetConfig() {
 
             /**
              * @see 
org.apache.mailet.MailetConfig#getInitParameter(java.lang.String)
              */
             public String getInitParameter(String name) {
-                if ("addDeliveryHeader".equals(name)) {
-                    return "Delivered-To";
-                } else if ("resetReturnPath".equals(name)) {
-                    return "true";
-                } else {
-                    return getMailetConfig().getInitParameter(name);
-                }
+               return null;
             }
 
             /**
              * @see org.apache.mailet.MailetConfig#getInitParameterNames()
              */
             public Iterator<String> getInitParameterNames() {
-                IteratorChain c = new IteratorChain();
-                Collection<String> h = new ArrayList<String>();
-                h.add("addDeliveryHeader");
-                h.add("resetReturnPath");
-                c.addIterator(getMailetConfig().getInitParameterNames());
-                c.addIterator(h.iterator());
-                return c;
+               return new ArrayList<String>().iterator();
             }
 
             /**
@@ -160,7 +155,11 @@ public class LocalDelivery extends Gener
             }
 
         };
-        deliveryMailet.init(m);
+        sieveMailet.setMailSerer(mailServer);
+        sieveMailet.setPoster(poster);
+        sieveMailet.init(m);
+
+        sieveMailet.setQuiet(true);
     }
 
 }

Added: 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/ResourceLocatorImpl.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/ResourceLocatorImpl.java?rev=928014&view=auto
==============================================================================
--- 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/ResourceLocatorImpl.java
 (added)
+++ 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/ResourceLocatorImpl.java
 Fri Mar 26 18:50:55 2010
@@ -0,0 +1,57 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.transport.mailets;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.jsieve.mailet.ResourceLocator;
+
+/**
+ * To maintain backwards compatibility with existing
+ * installations, this uses the old file based scheme.
+ * TODO: replace with <code>FileSystem</code> based implementation.
+ */
+public class ResourceLocatorImpl implements ResourceLocator {
+
+    private boolean virtualHosting;
+
+    public ResourceLocatorImpl(boolean virtualHosting) {
+        this.virtualHosting = virtualHosting;
+    }
+    
+    public InputStream get(String uri) throws IOException {
+        // This is a toy implementation
+        
+        // Use the complete emailaddress for finding the sieve file
+        uri = uri.substring(2);
+        
+        String username;
+        if (virtualHosting) {
+            username = uri.substring(0,uri.indexOf("/"));
+        } else {
+            username = uri.substring(0,uri.indexOf("@"));
+        }
+        String sieveFileName = "../apps/james/var/sieve/"+username+".sieve";
+        return new FileInputStream(sieveFileName);
+    }
+
+}

Added: 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/SieveMailet.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/SieveMailet.java?rev=928014&view=auto
==============================================================================
--- 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/SieveMailet.java
 (added)
+++ 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/SieveMailet.java
 Fri Mar 26 18:50:55 2010
@@ -0,0 +1,81 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.transport.mailets;
+
+import javax.annotation.Resource;
+import javax.mail.MessagingException;
+
+import org.apache.james.services.MailServer;
+import org.apache.jsieve.mailet.Poster;
+import org.apache.jsieve.mailet.SieveMailboxMailet;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.MailetConfig;
+
+/**
+ * Contains resource bindings.
+ */
+public class SieveMailet extends SieveMailboxMailet {
+
+    private MailServer mailServer;
+
+    @Resource(name="James")
+    public void setMailSerer(MailServer mailServer) {
+        this.mailServer = mailServer;
+    }
+
+
+    @Override
+    public void init(MailetConfig config) throws MessagingException {
+        // ATM Fixed implementation
+        setLocator(new 
ResourceLocatorImpl(mailServer.supportVirtualHosting()));
+        
+        super.init(config);
+    }
+
+
+
+
+    public SieveMailet() {
+        super();
+
+    }
+
+    @Resource(name="org.apache.jsieve.mailet.Poster")
+    @Override
+    public void setPoster(Poster poster) {
+        super.setPoster(poster);
+    }
+   
+    /**
+     * Return the username to use for sieve processing for the given 
MailAddress. If virtualhosting
+     * is supported use the full emailaddrees as username
+     * 
+     * @param m
+     * @return username
+     */
+    protected String getUsername(MailAddress m) {
+        if (mailServer.supportVirtualHosting()) {
+            return m.toString();
+        } else {
+            return super.getUsername(m);
+        }
+    }
+    
+}

Modified: 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/ToMultiRepository.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/ToMultiRepository.java?rev=928014&r1=928013&r2=928014&view=diff
==============================================================================
--- 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/ToMultiRepository.java
 (original)
+++ 
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/ToMultiRepository.java
 Fri Mar 26 18:50:55 2010
@@ -24,14 +24,12 @@ package org.apache.james.transport.maile
 import org.apache.commons.configuration.DefaultConfigurationBuilder;
 import org.apache.james.core.MailImpl;
 import org.apache.james.services.MailRepository;
-import org.apache.james.services.MailServer;
 import org.apache.james.services.store.Store;
 import org.apache.mailet.base.GenericMailet;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.RFC2822Headers;
 
-import javax.annotation.Resource;
 import javax.mail.Header;
 import javax.mail.MessagingException;
 import javax.mail.internet.InternetHeaders;
@@ -74,10 +72,6 @@ public class ToMultiRepository extends G
     private static int count = 0;
     private static final Object countLock = new Object();
 
-    /**
-     * The mailserver reference
-     */
-    private MailServer mailServer;
 
     /**
      * The mailstore
@@ -113,11 +107,6 @@ public class ToMultiRepository extends G
     private boolean resetReturnPath;
 
     
-    @Resource(name="James")
-    public void setMailServer(MailServer mailServer) {
-        this.mailServer = mailServer;
-    }
-    
     /**
      * Delivers a mail to a local mailbox.
      * 
@@ -280,6 +269,8 @@ public class ToMultiRepository extends G
             if (!SELECTOR_LOCALPART.equals(repositorySelector) && 
!SELECTOR_FULL.equals(repositorySelector)) {
                 throw new MessagingException("repositorySelector valid options 
are "+SELECTOR_FULL+" or "+SELECTOR_LOCALPART);
             }
+        } else {
+               throw new MessagingException("Please configure a 
repositoryUrl");
         }
 
         deliveryHeader = getInitParameter("addDeliveryHeader");
@@ -295,30 +286,28 @@ public class ToMultiRepository extends G
      * @param userName
      */
     private MailRepository getRepository(String userName) {
-        MailRepository userInbox;
-        if (repositoryUrl == null) {
-            userInbox = mailServer.getUserInbox(userName);
-        } else {
-            if (SELECTOR_LOCALPART.equals(repositorySelector)) {
-                // find the username for delivery to that user - localname, 
ignore the rest
-                String[] addressParts = userName.split("@");
-                userName = addressParts[0];
-            }
-                        
-            StringBuffer destinationBuffer = new StringBuffer(192).append(
-            repositoryUrl).append(userName).append("/");
-            String destination = destinationBuffer.toString();
-            DefaultConfigurationBuilder mboxConf = new 
DefaultConfigurationBuilder();
-            mboxConf.addProperty("[...@destinationurl]", destination);
-            mboxConf.addProperty("[...@type]", repositoryType);
-            try {
-                userInbox = (MailRepository) store.select(mboxConf);
-            } catch (Exception e) {
-                log("Cannot open repository " + e);
-                userInbox = null;
-            }
-        }
-        return userInbox;
-    }
+               if (SELECTOR_LOCALPART.equals(repositorySelector)) {
+                       // find the username for delivery to that user - 
localname, ignore
+                       // the rest
+                       String[] addressParts = userName.split("@");
+                       userName = addressParts[0];
+               }
+
+               StringBuffer destinationBuffer = new StringBuffer(192).append(
+                               repositoryUrl).append(userName).append("/");
+               String destination = destinationBuffer.toString();
+               DefaultConfigurationBuilder mboxConf = new 
DefaultConfigurationBuilder();
+               mboxConf.addProperty("[...@destinationurl]", destination);
+               mboxConf.addProperty("[...@type]", repositoryType);
+               MailRepository userInbox;
+               try {
+                       userInbox = (MailRepository) store.select(mboxConf);
+               } catch (Exception e) {
+                       log("Cannot open repository " + e);
+                       userInbox = null;
+               }
+
+               return userInbox;
+       }
 
 }

Modified: 
james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml
URL: 
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml?rev=928014&r1=928013&r2=928014&view=diff
==============================================================================
--- james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml 
(original)
+++ james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml 
Fri Mar 26 18:50:55 2010
@@ -103,7 +103,9 @@
                                <entry key="pop3ProtocolHandlerChain" 
value="pop3server"/>
                                <entry key="remoteProtocolHandlerChain" 
value="remoteManager"/>
                                <entry key="spool" value="spoolmanager"/>       
-                               <entry key="mailserver" value="James"/>         
                                                                
+                               <entry key="mailserver" value="James"/>         
+                               <entry key="poster" value="James"/>             
                                                                
+                                                                               
                
                        </map>
                </property>
        </bean>
@@ -283,9 +285,11 @@
        <!--
        <bean id="domainlist" class="org.apache.james.vut.XMLVirtualUserTable"/>
        -->
-
+       <!-- Poster -->
+    <bean id="poster" name="org.apache.jsieve.mailet.Poster" 
class="org.apache.james.MailboxManagerPoster"/>
+       
        <!-- IMAP server Beans -->
-    <bean id="imapserver" name="org.apache.jsieve.mailet.Poster" 
class="org.apache.james.imapserver.mina.AsyncImapServer">
+    <bean id="imapserver" 
class="org.apache.james.imapserver.mina.AsyncImapServer">
                <property name="imapDecoder" ref="imapDecoder"/>
                <property name="imapEncoder" ref="imapEncoder"/>        
        </bean>



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to