KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > filter > plugins > ToOrCcFilter


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16

17 package org.columba.mail.filter.plugins;
18
19 import org.columba.core.filter.FilterCriteria;
20 import org.columba.mail.folder.AbstractMessageFolder;
21 import org.columba.ristretto.message.Header;
22
23 /**
24  * This FilterPlugin searches every To and Cc headerfield of an occurence of a
25  * search string and combines the result with an logical OR operation
26  *
27  * @author fdietz
28  */

29 public class ToOrCcFilter extends HeaderfieldFilter {
30     private String JavaDoc pattern;
31
32     private int condition;
33
34     /** {@inheritDoc} */
35     public boolean process(AbstractMessageFolder folder, Object JavaDoc uid)
36             throws Exception JavaDoc {
37         // get the header of the message
38
Header header = folder
39                 .getHeaderFields(uid, new String JavaDoc[] { "To", "Cc" });
40
41         boolean result = false;
42         if (header != null) {
43             // convert the condition string to an int which is easier to handle
44

45             // get the "To" headerfield from the header
46
String JavaDoc to = (String JavaDoc) header.get("To");
47
48             // get the "Cc" headerfield from the header
49
String JavaDoc cc = (String JavaDoc) header.get("Cc");
50
51             // test if our To headerfield contains or contains not the search
52
// string
53
result = match(to, condition, pattern);
54
55             // do the same for the Cc headerfield and OR the results
56
result |= match(cc, condition, pattern);
57
58             // return the result as boolean value true or false
59
}
60         return result;
61     }
62
63     /**
64      * {@inheritDoc}
65      */

66     public void setUp(FilterCriteria filterCriteria) {
67
68         // string to search
69
pattern = filterCriteria.get("pattern");
70
71         condition = filterCriteria.getCriteria();
72     }
73 }
74
Popular Tags