KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > spam > rules > RuleList


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.spam.rules;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.logging.Logger JavaDoc;
24
25 import org.columba.mail.folder.IMailbox;
26 import org.macchiato.maps.ProbabilityMap;
27 import org.macchiato.maps.ProbabilityMapImpl;
28 import org.macchiato.tokenizer.Token;
29
30 /**
31  * Managing list of Rules
32  * <p>
33  * This is currently a hack. Adding new rules should happen more dynamic in the
34  * future.
35  *
36  * @author fdietz
37  *
38  */

39 public class RuleList {
40
41     /** JDK 1.4+ logging framework logger, used for logging. */
42     private static final Logger JavaDoc LOG = Logger
43             .getLogger("org.columba.mail.spam.rules");
44
45     private List JavaDoc list;
46
47     private static RuleList instance;
48
49     public RuleList() {
50         list = new ArrayList JavaDoc();
51
52         addRule(new SubjectWhitespaceRule());
53         addRule(new OnlyHTMLMimepartRule());
54         addRule(new SubjectIsAllCapitalsRule());
55         addRule(new MixedCharactersAddressRule());
56         addRule(new MissingToHeaderRule());
57         addRule(new SubjectContainsSpamRule());
58     }
59
60     public static RuleList getInstance() {
61         if (instance == null)
62             instance = new RuleList();
63
64         return instance;
65     }
66
67     public ProbabilityMap getProbabilities(IMailbox folder, Object JavaDoc uid)
68             throws Exception JavaDoc {
69
70         ProbabilityMap map = new ProbabilityMapImpl();
71
72         Iterator JavaDoc it = list.iterator();
73
74         while (it.hasNext()) {
75             Rule rule = (Rule) it.next();
76             LOG.info("rule " + rule.getName());
77
78             float score = rule.score(folder, uid);
79             LOG.info("score=" + score);
80
81             map.addToken(new Token(rule.getName()), score);
82         }
83
84         return map;
85     }
86
87     public void addRule(Rule rule) {
88         list.add(rule);
89     }
90 }
91
Popular Tags