KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > BackendMessageFilter


1 package net.suberic.pooka;
2 import javax.mail.*;
3 import javax.mail.search.SearchTerm JavaDoc;
4 import net.suberic.pooka.filter.FilterAction;
5 import java.util.List JavaDoc;
6 import java.util.LinkedList JavaDoc;
7 import java.util.Iterator JavaDoc;
8
9 /**
10  * This represents a MessageFilter which acts on the backend of the
11  * mail server. Basically, this means a filter which, say, modifies incoming
12  * messages, or moves them into another Folder. Compare to
13  * DisplayMessageFilter, which changes the way a Message is displayed.
14  */

15 public class BackendMessageFilter extends MessageFilter {
16   private SearchTerm JavaDoc searchTerm;
17   private FilterAction action;
18   
19   /**
20    * Create a MessageFilter from a SearchTerm and a FilterAction.
21    */

22   public BackendMessageFilter(SearchTerm JavaDoc newSearchTerm, FilterAction newAction) {
23     super(newSearchTerm, newAction);
24   }
25   
26   /**
27    * Create a MessageFilter from a String which represents a Pooka
28    * property.
29    *
30    */

31   public BackendMessageFilter(String JavaDoc sourceProperty) {
32     super(sourceProperty);
33   }
34   
35   /**
36    * This runs the searchTerm test for each MessageInfo in the
37    * messages List. Each MessageInfo that matches the searchTerm
38    * then has performFilter() run on it.
39    *
40    * @return: all messages removed from the current folder.
41    */

42   public List JavaDoc filterMessages(List JavaDoc messages) {
43     return filterMessages(messages, null);
44   }
45
46   /**
47    * This runs the searchTerm test for each MessageInfo in the
48    * messages List. Each MessageInfo that matches the searchTerm
49    * then has performFilter() run on it.
50    *
51    * @return: all messages removed from the current folder.
52    */

53   public List JavaDoc filterMessages(List JavaDoc messages, net.suberic.util.swing.ProgressDialog pd) {
54     List JavaDoc matches = new LinkedList JavaDoc();
55     for (int i = 0; i < messages.size() && (pd == null || ! pd.isCancelled()); i++) {
56       
57       if (getSearchTerm().match(((net.suberic.pooka.gui.MessageProxy)messages.get(i)).getMessageInfo().getMessage()))
58     matches.add(messages.get(i));
59
60       if (pd != null) {
61     pd.setValue(pd.getValue() + 1);
62       }
63     }
64     
65     if (pd == null || ! pd.isCancelled())
66       return performFilter(matches);
67     else
68       return new LinkedList JavaDoc();
69   }
70   
71   /**
72    * Actually performs the FilterAction on the given MessageInfo array.
73    *
74    * @param filteredMessages A List of MessageInfo objects that are to
75    * have the filter performed on them.
76    *
77    * @return all messagesremoved from the current folder.
78    */

79   public List JavaDoc performFilter(List JavaDoc filteredMessages) {
80     return getAction().performFilter(filteredMessages);
81   }
82   
83 }
84
Popular Tags