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