1 /************************************************************************ 2 * Copyright (c) 2000-2006 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; 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: 365582 $ $Date: 2006-01-03 08:51:21 +0000 (mar, 03 gen 2006) $ 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 { 60 String name = getInitParameter("name"); 61 62 if (name != null) { 63 StringTokenizer st = new StringTokenizer(name, ",") ; 64 while (st.hasMoreTokens()) { 65 String 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 { 79 Iterator iter = attributesToRemove.iterator(); 80 while (iter.hasNext()) { 81 String attribute_name = iter.next().toString(); 82 mail.removeAttribute (attribute_name); 83 } 84 } 85 86 87 }