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.matchers;
19
20
21 import org.apache.mailet.GenericMatcher;
22 import org.apache.mailet.Mail;
23 import org.apache.mailet.MatcherConfig;
24 import java.util.Collection;
25 import javax.mail.MessagingException;
26
27 /***
28 * <P>This Matcher determines if the mail contains the attribute specified in the
29 * condition, and returns all recipients if it is the case.</P>
30 * <P>Sample configuration:</P>
31 * <PRE><CODE>
32 * <mailet match="HasMailAttribute=whatever" class="<any-class>">
33 * </CODE></PRE>
34 *
35 * @version CVS $Revision: 365582 $ $Date: 2006-01-03 08:51:21 +0000 (mar, 03 gen 2006) $
36 * @since 2.2.0
37 **/
38 public class HasMailAttribute extends GenericMatcher
39 {
40
41 private String attributeName;
42
43 /***
44 * Return a string describing this matcher.
45 *
46 * @return a string describing this matcher
47 */
48 public String getMatcherInfo() {
49 return "Has Mail Attribute Matcher";
50 }
51
52 public void init (MatcherConfig conf) throws MessagingException
53 {
54 attributeName = conf.getCondition();
55 }
56
57 /***
58 * @param mail the mail to check.
59 * @return all recipients if the condition is the name of an attribute
60 * set on the mail
61 *
62 **/
63 public Collection match (Mail mail) throws MessagingException
64 {
65 if (mail.getAttribute (attributeName) != null) {
66 return mail.getRecipients();
67 }
68 return null;
69 }
70
71 }