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 rd...@apache.org on 2008/12/03 11:15:45 UTC

svn commit: r722832 - in /james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet: Poster.java ResourceLocator.java SieveMailboxMailet.java

Author: rdonkin
Date: Wed Dec  3 02:15:44 2008
New Revision: 722832

URL: http://svn.apache.org/viewvc?rev=722832&view=rev
Log:
Move from file to URI for script loading

Added:
    james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/ResourceLocator.java   (with props)
Modified:
    james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/Poster.java
    james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailboxMailet.java

Modified: james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/Poster.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/Poster.java?rev=722832&r1=722831&r2=722832&view=diff
==============================================================================
--- james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/Poster.java (original)
+++ james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/Poster.java Wed Dec  3 02:15:44 2008
@@ -28,12 +28,13 @@
 public interface Poster {
     
     /**
-     * Experimental RESTful mail delivery. 
+     * Experimental mail delivery. 
      * POST verb indicate that mail should be attached to the collection
      * indicated by the given URI.
-     * @param url indicates the destination to which the mail to added. ATM 
+     * 
+     * @param uri indicates the destination to which the mail to added. ATM 
      * the value should be mailbox://<user>@localhost/<mailbox-path>
      * @param mail not null
      */
-    public void post(String url, MimeMessage mail) throws MessagingException;
+    public void post(String uri, MimeMessage mail) throws MessagingException;
 }

Added: james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/ResourceLocator.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/ResourceLocator.java?rev=722832&view=auto
==============================================================================
--- james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/ResourceLocator.java (added)
+++ james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/ResourceLocator.java Wed Dec  3 02:15:44 2008
@@ -0,0 +1,66 @@
+/****************************************************************
+ * 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.jsieve.mailet;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * <p>Experimental API locates resources. 
+ * Used to load Sieve scripts. The base for relative URLs
+ * should be taken to be the root of the James configuration.
+ * </p><p>
+ * Required schemas:
+ * </p>
+ * <ul>
+ * <li><strong>User sieve scripts</strong> - the relative URL scheme 
+ * <code>//<em>user</em>@<em>host</em>/<em>sieve</em> will be used to
+ * obtain the script
+ * </ul>
+ * <p>
+ * The advantage of using <code>URI</code>s 
+ * and verbs (for example <code>GET</code>, <code>POST</code>)
+ * are their uniformity. The same API can be used to interface radically
+ * different resource types and protocols. This allows concise, minimal,
+ * powerful APIs to be created. Their simplicity is easy to preserved 
+ * across versions. 
+ * </p><p>
+ * The disadvantage is that this free decouple means that there is 
+ * no gaurantee that the implementations decoupled by this interface
+ * actually support the same scheme. Issues will be caught only 
+ * at deployment and not at compile time.
+ * This places a larger burden on the deployer.
+ * </p><p>
+ * Either an understanding or a consistent URL mapping scheme may be 
+ * required. For example, <code>//john.smith@localhost/sieve</code>
+ * may need to be resolved to <code>../apps/james/var/sieve/john.smith@localhost.sieve</code>
+ * when using the file system to store scripts. Note that names <strong>MUST</strong>
+ * be normalised before resolving on a file system.
+ * </p>
+ */
+public interface ResourceLocator {
+    
+    /**
+     * GET verb locates and loads a resource. 
+     * @param uri identifies the Sieve script 
+     * @return not null
+     * @throws IOException when the resource cannot be located
+     */
+    public InputStream get(String uri) throws IOException;
+}

Propchange: james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/ResourceLocator.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailboxMailet.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailboxMailet.java?rev=722832&r1=722831&r2=722832&view=diff
==============================================================================
--- james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailboxMailet.java (original)
+++ james/jsieve/trunk/mailet/src/main/java/org/apache/jsieve/mailet/SieveMailboxMailet.java Wed Dec  3 02:15:44 2008
@@ -21,6 +21,7 @@
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.InputStream;
 import java.util.Collection;
 import java.util.Enumeration;
 import java.util.Iterator;
@@ -43,8 +44,8 @@
 import org.apache.mailet.base.RFC2822Headers;
 
 /**
- * Executes a <a href='http://www.rfc-editor.org/rfc/rfc3028.txt'>Sieve</a>
- * script against incoming mail. The script applied is based on the recipient.
+ * <p>Executes a <a href='http://www.rfc-editor.org/rfc/rfc3028.txt'>Sieve</a>
+ * script against incoming mail. The script applied is based on the recipient.</p>
  */
 public class SieveMailboxMailet extends GenericMailet {
 
@@ -59,6 +60,8 @@
     private boolean resetReturnPath;
     /** Experimental */
     private Poster poster;
+    /** Experimental */
+    private ResourceLocator locator;
     
     private SieveFactory factory;
 
@@ -71,9 +74,23 @@
      * CDI
      * @param poster not null
      */
-    public SieveMailboxMailet(Poster poster) {
+    public SieveMailboxMailet(Poster poster, ResourceLocator locator) {
         this();
         this.poster = poster;
+        this.locator = locator;
+    }
+
+    
+    public ResourceLocator getLocator() {
+        return locator;
+    }
+
+    /**
+     * For SDI
+     * @param locator not null
+     */
+    public void setLocator(ResourceLocator locator) {
+        this.locator = locator;
     }
 
     public final Poster getPoster() {
@@ -88,11 +105,11 @@
         this.poster = poster;
     }
 
-    
     //@Override
     public void init(MailetConfig config) throws MessagingException {
         
         super.init(config);
+
         try {
             factory = new ConfigurationManager().build();
         } catch (SieveConfigurationException e) {
@@ -214,31 +231,21 @@
         // recipient.toString was used here (JD)
         username = recipient.getUser();
         
-        storeMessage(username, mail);
+        sieveMessage(username, mail);
  
     }
     
-    void storeMessage(String username, Mail mail) throws MessagingException {
-        String sieveFileName="../apps/james/var/sieve/"+username+".sieve";
-        if (new File(sieveFileName).canRead()) {
-            getMailetContext().log("Passing over to sieve delivery for "+username);
-            storeMessageSieve(sieveFileName, username, mail);
-        } else {
-            getMailetContext().log(new File(sieveFileName).getAbsolutePath()+ " does not exists");
-            storeMessageInbox(username, mail);
-        }
-    }
-    
-    void storeMessageSieve(String sieveFileName, String username, Mail aMail) throws MessagingException {
+    void sieveMessage(String username, Mail aMail) throws MessagingException {
         // Evaluate the script against the mail
+        String relativeUri = "//" + username + "@" + "localhost/sieve"; 
         try
         {
+            final InputStream ins = locator.get(relativeUri);
             MailAdapter aMailAdapter = new SieveMailAdapter(aMail,
                     getMailetContext());
             log("Evaluating " + aMailAdapter.toString() + "against \""
-                    + sieveFileName + "\"");
-            factory.evaluate(aMailAdapter,
-                    factory.parse(new FileInputStream(sieveFileName)));
+                    + relativeUri + "\"");
+            factory.evaluate(aMailAdapter, factory.parse(ins));
         }
         catch (Exception ex)
         {



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