01: /****************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one *
03: * or more contributor license agreements. See the NOTICE file *
04: * distributed with this work for additional information *
05: * regarding copyright ownership. The ASF licenses this file *
06: * to you under the Apache License, Version 2.0 (the *
07: * "License"); you may not use this file except in compliance *
08: * with the License. You may obtain a copy of the License at *
09: * *
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: ****************************************************************/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;
24: import java.util.ArrayList;
25: import java.util.StringTokenizer;
26: import javax.mail.MessagingException;
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: 494012 $ $Date: 2007-01-08 11:23:58 +0100 (Mo, 08 Jan 2007) $
38: * @since 2.2.0
39: */
40: public class RemoveMailAttribute extends GenericMailet {
41:
42: private ArrayList attributesToRemove = new ArrayList();
43:
44: /**
45: * Return a string describing this mailet.
46: *
47: * @return a string describing this mailet
48: */
49: public String 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: String name = getInitParameter("name");
60:
61: if (name != null) {
62: StringTokenizer st = new StringTokenizer(name, ",");
63: while (st.hasMoreTokens()) {
64: String attribute_name = st.nextToken().trim();
65: attributesToRemove.add(attribute_name);
66: }
67: }
68: }
69:
70: /**
71: * Remove the configured attributes
72: *
73: * @param mail the mail to process
74: *
75: * @throws MessagingException in all cases
76: */
77: public void service(Mail mail) throws MessagingException {
78: Iterator iter = attributesToRemove.iterator();
79: while (iter.hasNext()) {
80: String attribute_name = iter.next().toString();
81: mail.removeAttribute(attribute_name);
82: }
83: }
84:
85: }
|