james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vince...@apache.org
Subject cvs commit: james-server/src/java/org/apache/james/transport/matchers HasMailAttribute.java
Date Tue, 15 Jul 2003 10:44:49 GMT
vincenzo    2003/07/15 03:44:49

  Added:       src/java/org/apache/james/transport/mailets
                        RemoveAllMailAttributes.java
                        RemoveMailAttribute.java SetMailAttribute.java
               src/java/org/apache/james/transport/matchers
                        HasMailAttribute.java
  Log:
  Adding some matchers/mailets that manage mail attributes from config.xml.
  
  Revision  Changes    Path
  1.1                  james-server/src/java/org/apache/james/transport/mailets/RemoveAllMailAttributes.java
  
  Index: RemoveAllMailAttributes.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation"
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at the National Center for Supercomputing Applications,
   * University of Illinois, Urbana-Champaign.
   */
  
  package org.apache.james.transport.mailets;
  
  import org.apache.mailet.GenericMailet;
  import org.apache.mailet.Mail;
  import org.apache.mailet.MailetException;
  import javax.mail.MessagingException;
  
  /**
   * This mailet sets removes all attributes set on the Mail instance
   * 
   * Sample configuration:
   * &lt;mailet match="All" class="RemoveAllMailAttributes"/&gt;
   *
   * @version CVS $Revision: 1.1 $ $Date: 2003/07/15 10:44:48 $
   * @since 2.2.0
   */
  public class RemoveAllMailAttributes extends GenericMailet {
      
      /**
       * Return a string describing this mailet.
       *
       * @return a string describing this mailet
       */
      public String getMailetInfo() {
          return "Remove All Mail Attributes Mailet";
      }
  
      /**
       * Removes all attributes on the Mail
       *
       * @param mail the mail to process
       *
       * @throws MessagingException in all cases
       */
      public void service(Mail mail) throws MessagingException {
          mail.removeAllAttributes ();
      }
      
  
  }
  
  
  
  1.1                  james-server/src/java/org/apache/james/transport/mailets/RemoveMailAttribute.java
  
  Index: RemoveMailAttribute.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation"
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at the National Center for Supercomputing Applications,
   * University of Illinois, Urbana-Champaign.
   */
  
  package org.apache.james.transport.mailets;
  
  import org.apache.mailet.GenericMailet;
  import org.apache.mailet.Mail;
  import org.apache.mailet.MailetException;
  import java.util.Iterator;
  import java.util.ArrayList;
  import java.util.StringTokenizer;
  import javax.mail.MessagingException;
  
  /**
   * This mailet sets attributes on the Mail.
   * 
   * Sample configuration:
   * &lt;mailet match="All" class="RemoveMailAttribute"&gt;
   *   &lt;name&gt;attribute_name1&lt;/name&gt;
   *   &lt;name&gt;attribute_name2&lt;/name&gt;
   * &lt;/mailet&gt;
   *
   * @version CVS $Revision: 1.1 $ $Date: 2003/07/15 10:44:48 $
   * @since 2.2.0
   */
  public class RemoveMailAttribute extends GenericMailet {
      
      private ArrayList attributesToRemove = new ArrayList();
      
      /**
       * Return a string describing this mailet.
       *
       * @return a string describing this mailet
       */
      public String getMailetInfo() {
          return "Remove Mail Attribute Mailet";
      }
  
      /**
       * Initialize the mailet
       *
       * @throws MailetException if the processor parameter is missing
       */
      public void init() throws MailetException
      {
          String name = getInitParameter("name");
  
          if (name != null) {
              StringTokenizer st = new StringTokenizer(name, ",") ;
              while (st.hasMoreTokens()) {
                  String attribute_name = st.nextToken().trim() ;
                  attributesToRemove.add(attribute_name);
              }
          }
      }
  
      /**
       * Remove the configured attributes
       *
       * @param mail the mail to process
       *
       * @throws MessagingException in all cases
       */
      public void service(Mail mail) throws MessagingException {
          Iterator iter = attributesToRemove.iterator();
          while (iter.hasNext()) {
              String attribute_name = iter.next().toString();
              mail.removeAttribute (attribute_name);
          }
      }
      
  
  }
  
  
  
  1.1                  james-server/src/java/org/apache/james/transport/mailets/SetMailAttribute.java
  
  Index: SetMailAttribute.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation"
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at the National Center for Supercomputing Applications,
   * University of Illinois, Urbana-Champaign.
   */
  
  package org.apache.james.transport.mailets;
  
  import org.apache.mailet.GenericMailet;
  import org.apache.mailet.Mail;
  import org.apache.mailet.MailetException;
  import java.io.Serializable;
  import java.util.Iterator;
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Set;
  import javax.mail.MessagingException;
  
  /**
   * This mailet sets attributes on the Mail.
   * 
   * Sample configuration:
   * &lt;mailet match="All" class="SetMailAttribute"&gt;
   *   &lt;name1&gt;value1&lt;/name1&gt;
   *   &lt;name2&gt;value2&lt;/name2&gt;
   * &lt;/mailet&gt;
   *
   * @version CVS $Revision: 1.1 $ $Date: 2003/07/15 10:44:48 $
   * @since 2.2.0
   */
  public class SetMailAttribute extends GenericMailet {
  
      private HashMap attributesToSet = new HashMap(2);
      
      private Set entries;
      
      /**
       * Return a string describing this mailet.
       *
       * @return a string describing this mailet
       */
      public String getMailetInfo() {
          return "Set Mail Attribute Mailet";
      }
  
      /**
       * Initialize the mailet
       *
       * @throws MailetException if the processor parameter is missing
       */
      public void init() throws MailetException
      {
          Iterator iter = getInitParameterNames();
          while (iter.hasNext()) {
              String name = iter.next().toString();
              String value = getInitParameter (name);
              attributesToSet.put (name,value);
          }
          entries = attributesToSet.entrySet();
      }
  
      /**
       * Sets the configured attributes
       *
       * @param mail the mail to process
       *
       * @throws MessagingException in all cases
       */
      public void service(Mail mail) throws MessagingException {
          if (entries != null) {
              Iterator iter = entries.iterator();
              while (iter.hasNext()) {
                  Map.Entry entry = (Map.Entry)iter.next();
                  mail.setAttribute ((String)entry.getKey(),(Serializable)entry.getValue());
              }
          }
      }
      
  
  }
  
  
  
  1.1                  james-server/src/java/org/apache/james/transport/matchers/HasMailAttribute.java
  
  Index: HasMailAttribute.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation"
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * Portions of this software are based upon public domain software
   * originally written at the National Center for Supercomputing Applications,
   * University of Illinois, Urbana-Champaign.
   */
  
  package org.apache.james.transport.matchers;
  
  
  import org.apache.mailet.GenericMatcher;
  import org.apache.mailet.Mail;
  import org.apache.mailet.MatcherConfig;
  import java.util.Collection;
  import java.util.regex.Matcher;
  import java.util.regex.Pattern;
  import javax.mail.MessagingException;
  
  
  /**
   * This Matcher determines if the mail contains the attribute specified in the
   * condition, and returns all recipients if it is the case.
   * Sample configuration:
   * &lt;mailet match="HasMailAttribute=whatever" class="Null"/&gt;
   *
   * @version CVS $Revision: 1.1 $ $Date: 2003/07/15 10:44:49 $
   * @since 2.2.0
   **/
  public class HasMailAttribute extends GenericMatcher 
  {
      
      private String attributeName;
  
      /**
       * Return a string describing this matcher.
       *
       * @return a string describing this matcher
       */
      public String getMatcherInfo() {
          return "Has Mail Attribute Matcher";
      }
  
      public void init (MatcherConfig conf) throws MessagingException
      {
          super.init(conf);
          attributeName = conf.getCondition();
      }
  
      /**
       * @param mail the mail to check.
       * @return all recipients if the condition is the name of an attribute
       * set on the mail
       *
       **/
      public Collection match (Mail mail) throws MessagingException
      {
          if (mail.getAttribute (attributeName) != null) {
              return mail.getRecipients();
          } 
          return null;
      }
      
  }
  
  
  

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