1 /*****************************************************************
2 * Licensed to the Apache Software Foundation (ASF) under one *
3 * or more contributor license agreements. See the NOTICE file *
4 * distributed with this work for additional information *
5 * regarding copyright ownership. The ASF licenses this file *
6 * to you under the Apache License, Version 2.0 (the *
7 * "License"); you may not use this file except in compliance *
8 * with the License. You may obtain a copy of the License at *
9 * *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
11 * *
12 * Unless required by applicable law or agreed to in writing, *
13 * software distributed under the License is distributed on an *
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15 * KIND, either express or implied. See the License for the *
16 * specific language governing permissions and limitations *
17 * under the License. *
18 ****************************************************************/
19
20 package org.apache.james.transport.mailets;
21
22 import org.apache.mailet.GenericMailet;
23 import org.apache.mailet.Mail;
24 import org.apache.mailet.MailetException;
25 import java.util.Iterator;
26 import java.util.ArrayList;
27 import java.util.StringTokenizer;
28 import javax.mail.MessagingException;
29
30 /***
31 * This mailet sets attributes on the Mail.
32 *
33 * Sample configuration:
34 * <mailet match="All" class="RemoveMailAttribute">
35 * <name>attribute_name1</name>
36 * <name>attribute_name2</name>
37 * </mailet>
38 *
39 * @version CVS $Revision: 494012 $ $Date: 2007-01-08 10:23:58 +0000 (lun, 08 gen 2007) $
40 * @since 2.2.0
41 */
42 public class RemoveMailAttribute extends GenericMailet {
43
44 private ArrayList attributesToRemove = new ArrayList();
45
46 /***
47 * Return a string describing this mailet.
48 *
49 * @return a string describing this mailet
50 */
51 public String getMailetInfo() {
52 return "Remove Mail Attribute Mailet";
53 }
54
55 /***
56 * Initialize the mailet
57 *
58 * @throws MailetException if the processor parameter is missing
59 */
60 public void init() throws MailetException
61 {
62 String name = getInitParameter("name");
63
64 if (name != null) {
65 StringTokenizer st = new StringTokenizer(name, ",") ;
66 while (st.hasMoreTokens()) {
67 String attribute_name = st.nextToken().trim() ;
68 attributesToRemove.add(attribute_name);
69 }
70 }
71 }
72
73 /***
74 * Remove the configured attributes
75 *
76 * @param mail the mail to process
77 *
78 * @throws MessagingException in all cases
79 */
80 public void service(Mail mail) throws MessagingException {
81 Iterator iter = attributesToRemove.iterator();
82 while (iter.hasNext()) {
83 String attribute_name = iter.next().toString();
84 mail.removeAttribute (attribute_name);
85 }
86 }
87
88
89 }