james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r691782 - in /james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/sieve: Actions.java SieveToMultiMailbox.java
Date Wed, 03 Sep 2008 21:23:03 GMT
Author: rdonkin
Date: Wed Sep  3 14:23:03 2008
New Revision: 691782

URL: http://svn.apache.org/viewvc?rev=691782&view=rev
Log:
Experimental decoupling of Sieve mailet from IMAP. Note that this probably doesn't work but
may be useful for illustrative purposes. JAMES-858.

Modified:
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/sieve/Actions.java
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/sieve/SieveToMultiMailbox.java

Modified: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/sieve/Actions.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/sieve/Actions.java?rev=691782&r1=691781&r2=691782&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/sieve/Actions.java
(original)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/sieve/Actions.java
Wed Sep  3 14:23:03 2008
@@ -23,7 +23,6 @@
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Date;
 
 import javax.mail.Address;
 import javax.mail.MessagingException;
@@ -31,13 +30,9 @@
 import javax.mail.internet.MimeMessage;
 import javax.mail.internet.MimeMultipart;
 
-import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.james.Constants;
-import org.apache.james.mailboxmanager.MailboxSession;
-import org.apache.james.mailboxmanager.mailbox.Mailbox;
-import org.apache.james.mailboxmanager.manager.MailboxManager;
-import org.apache.james.mailboxmanager.manager.MailboxManagerProvider;
+import org.apache.james.core.MailImpl;
 import org.apache.james.util.mail.mdn.ActionModeAutomatic;
 import org.apache.james.util.mail.mdn.Disposition;
 import org.apache.james.util.mail.mdn.DispositionModifier;
@@ -60,6 +55,7 @@
 public class Actions
 {
     private static final String INBOX = "INBOX";
+    private static final char HIERARCHY_DELIMITER = '.';
     static private String fieldAttributePrefix;
 
     /**
@@ -93,43 +89,39 @@
      * @param anAction
      * @param aMail
      * @param aMailetContext
+     * @param poster TODO
      * @throws MessagingException
      */
     static public void execute(ActionFileInto anAction, Mail aMail,
-            MailetContext aMailetContext) throws MessagingException
+            MailetContext aMailetContext, Poster poster) throws MessagingException
     {
         ServiceManager compMgr = (ServiceManager)aMailetContext
             .getAttribute(Constants.AVALON_COMPONENT_MANAGER);
         String destinationMailbox = anAction.getDestination();
         MailAddress recipient;
-        MailboxManagerProvider mailboxManagerProvider;
         boolean delivered = false;
         try
         {
-            mailboxManagerProvider = (MailboxManagerProvider) compMgr
-            .lookup(MailboxManagerProvider.class.getName());
             recipient = getSoleRecipient(aMail);
             MimeMessage localMessage = createMimeMessage(aMail, recipient);
             
             if (!(destinationMailbox.length() > 0 
-                    && destinationMailbox.charAt(0) == MailboxManager.HIERARCHY_DELIMITER))
{
-                destinationMailbox =  MailboxManager.HIERARCHY_DELIMITER + destinationMailbox;
+                    && destinationMailbox.charAt(0) == HIERARCHY_DELIMITER)) {
+                destinationMailbox =  HIERARCHY_DELIMITER + destinationMailbox;
             }
-            final String mailboxName = 
-                mailboxManagerProvider.getMailboxManager().resolve(recipient.getUser(), destinationMailbox);
-            final MailboxManager mailboxManager = mailboxManagerProvider.getMailboxManager();
-            Mailbox mailbox=mailboxManager.getMailbox(mailboxName, true);
-            final MailboxSession session = mailboxManager.createSession();
-            mailbox.appendMessage(localMessage, new Date(), null, session);
-            session.close();
+            
+            final String url = "mailbox://" + recipient.getUser() + "@localhost/" + 
+                destinationMailbox.replace(HIERARCHY_DELIMITER, '/');
+            //TODO: copying this message so many times seems a waste
+            Mail mail = new MailImpl();
+            mail.setMessage(localMessage);
+            poster.post(url, mail);
             delivered = true;
         }
         catch (MessagingException ex)
         {
             aMailetContext.log("Error while storing mail into. "+destinationMailbox, ex);
             throw ex;
-        } catch (ServiceException e) {
-            aMailetContext.log("Error while storing mail into. "+destinationMailbox, e);
         }
         finally
         {
@@ -180,10 +172,10 @@
      * @throws MessagingException
      */
     public static void execute(ActionKeep anAction, Mail aMail,
-            MailetContext aMailetContext) throws MessagingException
+            MailetContext aMailetContext, Poster poster) throws MessagingException
     {
         final ActionFileInto action = new ActionFileInto(INBOX);
-        execute(action, aMail, aMailetContext);
+        execute(action, aMail, aMailetContext, poster);
     }
 
     /**

Modified: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/sieve/SieveToMultiMailbox.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/sieve/SieveToMultiMailbox.java?rev=691782&r1=691781&r2=691782&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/sieve/SieveToMultiMailbox.java
(original)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/sieve/SieveToMultiMailbox.java
Wed Sep  3 14:23:03 2008
@@ -22,7 +22,6 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.util.Collection;
-import java.util.Date;
 import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.Vector;
@@ -32,19 +31,12 @@
 import javax.mail.internet.InternetHeaders;
 import javax.mail.internet.MimeMessage;
 
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.james.Constants;
-import org.apache.james.impl.user.DefaultUser;
-import org.apache.james.mailboxmanager.MailboxSession;
-import org.apache.james.mailboxmanager.mailbox.Mailbox;
-import org.apache.james.mailboxmanager.manager.MailboxManager;
-import org.apache.james.mailboxmanager.manager.MailboxManagerProvider;
 import org.apache.jsieve.SieveFactory;
 import org.apache.jsieve.mail.MailAdapter;
 import org.apache.mailet.GenericMailet;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
+import org.apache.mailet.MailetException;
 import org.apache.mailet.RFC2822Headers;
 
 /**
@@ -78,8 +70,34 @@
      * resetReturnPath
      */
     private boolean resetReturnPath;
+    /** Experimental */
+    private Poster poster;
 
-    private MailboxManagerProvider mailboxManagerProvider;
+    /**
+     * For SDI
+     */
+    public SieveToMultiMailbox() {}
+    
+    /**
+     * CDI
+     * @param poster not null
+     */
+    public SieveToMultiMailbox(Poster poster) {
+        super();
+        this.poster = poster;
+    }
+
+    public final Poster getPoster() {
+        return poster;
+    }
+    
+    /**
+     * For SDI
+     * @param poster not null
+     */
+    public final void setPoster(Poster poster) {
+        this.poster = poster;
+    }
 
     /**
      * Delivers a mail to a local mailbox.
@@ -206,7 +224,7 @@
             storeMessageSieve(sieveFileName, username, mail);
         } else {
             getMailetContext().log(new File(sieveFileName).getAbsolutePath()+ " does not
exists");
-            storeMessageInbox(username, mail.getMessage());
+            storeMessageInbox(username, mail);
         }
     }
     
@@ -230,25 +248,13 @@
             // So just log and store in INBOX.
             //
             log("Cannot evaluate Sieve script. Storing mail in user INBOX.", ex);
-            storeMessageInbox(username, aMail.getMessage());
+            storeMessageInbox(username, aMail);
         }
     }
     
-    void storeMessageInbox(String username, MimeMessage message) throws MessagingException
{
-        final MailboxManagerProvider mailboxManagerProvider = getMailboxManagerProvider();
-        final String inboxName = mailboxManagerProvider.getMailboxManager().resolve(username,
"INBOX");
-        
-        final MailboxManager mailboxManager = mailboxManagerProvider.getMailboxManager();
-        final MailboxSession session = mailboxManager.createSession();
-        Mailbox inbox = mailboxManager.getMailbox(inboxName, true);
-        
-        if (inbox == null) {
-            String error = "Mailbox for user " + username
-                    + " was not found on this server.";
-            throw new MessagingException(error);
-        }
-        inbox.appendMessage(message, new Date(), null, session);
-        session.close();
+    void storeMessageInbox(String username, Mail mail) throws MessagingException {
+        String url = "mailbox://" + username + "@localhost/";
+        poster.post(url, mail);
     }
 
     /**
@@ -256,30 +262,13 @@
      */
     public void init() throws MessagingException {
         super.init();
-        ServiceManager compMgr = (ServiceManager) getMailetContext()
-                .getAttribute(Constants.AVALON_COMPONENT_MANAGER);
-
-        try {
-            setMailboxManagerProvider((MailboxManagerProvider) compMgr
-                    .lookup(MailboxManagerProvider.class.getName()));
-        } catch (ServiceException cnfe) {
-            log("Failed to retrieve Store component:" + cnfe.getMessage());
-        } catch (Exception e) {
-            log("Failed to retrieve Store component:" + e.getMessage());
+        if (poster == null) {
+            throw new MailetException("Not initialised. Please ensure that the mailet container
supports either" +
+                    " setter or constructor injection");
         }
-
+        
         deliveryHeader = getInitParameter("addDeliveryHeader");
         String resetReturnPathString = getInitParameter("resetReturnPath");
         resetReturnPath = "true".equalsIgnoreCase(resetReturnPathString);
     }
-
-    public void setMailboxManagerProvider(
-            MailboxManagerProvider mailboxManagerProvider) {
-        this.mailboxManagerProvider = mailboxManagerProvider;
-    }
-
-    MailboxManagerProvider getMailboxManagerProvider() {
-        return mailboxManagerProvider;
-    }
-
 }



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


Mime
View raw message