KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > transport > mailets > RemoveMailAttribute


1 /***********************************************************************
2  * Copyright (c) 2000-2004 The Apache Software Foundation. *
3  * All rights reserved. *
4  * ------------------------------------------------------------------- *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you *
6  * may not use this file except in compliance with the License. You *
7  * may obtain a copy of the License at: *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
14  * implied. See the License for the specific language governing *
15  * permissions and limitations under the License. *
16  ***********************************************************************/

17
18 package org.apache.james.transport.mailets;
19
20 import org.apache.mailet.GenericMailet;
21 import org.apache.mailet.Mail;
22 import org.apache.mailet.MailetException;
23 import java.util.Iterator JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.StringTokenizer JavaDoc;
26 import javax.mail.MessagingException JavaDoc;
27
28 /**
29  * This mailet sets attributes on the Mail.
30  *
31  * Sample configuration:
32  * <mailet match="All" class="RemoveMailAttribute">
33  * <name>attribute_name1</name>
34  * <name>attribute_name2</name>
35  * </mailet>
36  *
37  * @version CVS $Revision: 1.1.2.2 $ $Date: 2004/03/15 03:54:19 $
38  * @since 2.2.0
39  */

40 public class RemoveMailAttribute extends GenericMailet {
41     
42     private ArrayList JavaDoc attributesToRemove = new ArrayList JavaDoc();
43     
44     /**
45      * Return a string describing this mailet.
46      *
47      * @return a string describing this mailet
48      */

49     public String JavaDoc getMailetInfo() {
50         return "Remove Mail Attribute Mailet";
51     }
52
53     /**
54      * Initialize the mailet
55      *
56      * @throws MailetException if the processor parameter is missing
57      */

58     public void init() throws MailetException
59     {
60         String JavaDoc name = getInitParameter("name");
61
62         if (name != null) {
63             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(name, ",") ;
64             while (st.hasMoreTokens()) {
65                 String JavaDoc attribute_name = st.nextToken().trim() ;
66                 attributesToRemove.add(attribute_name);
67             }
68         }
69     }
70
71     /**
72      * Remove the configured attributes
73      *
74      * @param mail the mail to process
75      *
76      * @throws MessagingException in all cases
77      */

78     public void service(Mail mail) throws MessagingException JavaDoc {
79         Iterator JavaDoc iter = attributesToRemove.iterator();
80         while (iter.hasNext()) {
81             String JavaDoc attribute_name = iter.next().toString();
82             mail.removeAttribute (attribute_name);
83         }
84     }
85     
86
87 }
88
Popular Tags