1 /*
2 * Copyright (C) The Apache Software Foundation. All rights reserved.
3 *
4 * This software is published under the terms of the Apache Software License
5 * version 1.1, a copy of which has been included with this distribution in
6 * the LICENSE file.
7 */
8 package org.apache.mailet;
9
10 import javax.mail.MessagingException;
11 import java.util.Collection;
12 import java.util.Iterator;
13 import java.util.Vector;
14
15 /***
16 * GenericMatcher makes writing recipient based matchers easier. It provides
17 * simple versions of the lifecycle methods init and destroy and of the methods
18 * in the MatcherConfig interface. GenericMatcher also implements the log method,
19 * declared in the MatcherContext interface.
20 *
21 * @version 1.0.0, 24/04/1999
22 * @author Federico Barbieri <scoobie@pop.systemy.it>
23 * @author Serge Knystautas <sergek@lokitech.com>
24 */
25 public abstract class GenericRecipientMatcher extends GenericMatcher {
26
27 /***
28 * Matches each recipient one by one through matchRecipient(MailAddress
29 * recipient) method. Handles splitting the recipients Collection
30 * as appropriate.
31 *
32 * @param mail - the message and routing information to determine whether to match
33 * @return Collection the Collection of MailAddress objects that have been matched
34 */
35 public final Collection match(Mail mail) throws MessagingException {
36 Collection matching = new Vector();
37 for (Iterator i = mail.getRecipients().iterator(); i.hasNext(); ) {
38 MailAddress rec = (MailAddress) i.next();
39 if (matchRecipient(rec)) {
40 matching.add(rec);
41 }
42 }
43 return matching;
44 }
45
46 /***
47 * Simple check to match exclusively on the email address (not
48 * message information).
49 *
50 * @param recipient - the address to determine whether to match
51 * @return boolean whether the recipient is a match
52 */
53 public abstract boolean matchRecipient(MailAddress recipient) throws MessagingException;
54 }
This page was automatically generated by Maven