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