KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > filter > BounceFilterAction


1 package net.suberic.pooka.filter;
2 import net.suberic.pooka.gui.MessageProxy;
3 import net.suberic.pooka.Pooka;
4
5 import javax.mail.Address JavaDoc;
6 import javax.mail.internet.InternetAddress JavaDoc;
7
8 import java.util.List JavaDoc;
9 import java.util.ArrayList JavaDoc;
10
11
12 /**
13  * A filter which bounces the given message(s) to another folder.
14  */

15 public class BounceFilterAction implements FilterAction {
16   
17   private Address JavaDoc[] targetAddresses= null;
18
19   private boolean removeBounced = false;
20
21   public BounceFilterAction() {
22   }
23   
24   /**
25    * Runs the filterAction on each MessageProxy in the filteredMessages
26    * List.
27    *
28    * @param filteredMessages messages which have met the filter condition
29    * and need to have the FilterAction performed on them.
30    *
31    * @return messages which are removed from their original folder
32    * by the filter.
33    */

34   public List JavaDoc performFilter(List JavaDoc filteredMessages) {
35     List JavaDoc removed = new ArrayList JavaDoc();
36     for (int i = 0; i < filteredMessages.size(); i++) {
37       MessageProxy current = (MessageProxy) filteredMessages.get(i);
38       current.bounceMessage(getTargetAddresses(), removeBounced, false);
39       if (removeBounced) {
40     removed.add(current);
41       }
42     }
43
44     return removed;
45   }
46   
47   /**
48    * Initializes the FilterAction from the sourceProperty given.
49    *
50    * This takes the .targetFolder subproperty of the given sourceProperty
51    * and assigns its value as the folderName String.
52    */

53   
54   public void initializeFilter(String JavaDoc sourceProperty) {
55     try {
56       String JavaDoc addressString = Pooka.getProperty(sourceProperty + ".targetAddresses", "");
57       targetAddresses = InternetAddress.parse(addressString, false);
58
59       removeBounced = Pooka.getProperty(sourceProperty + ".removeBounced", "false").equalsIgnoreCase("true");
60     } catch (javax.mail.MessagingException JavaDoc me) {
61       String JavaDoc errorMessage = Pooka.getProperty("error.bounceMessage.addresses", "Error parsing address entry");
62       if (Pooka.getUIFactory() != null) {
63     Pooka.getUIFactory().showError(errorMessage + ": " + sourceProperty, me);
64       } else {
65     System.err.println(errorMessage + ": " + sourceProperty);
66     me.printStackTrace();
67       }
68     }
69   }
70   
71   /**
72    * Returns the targetFolder. If the targetFolder has not yet been
73    * loaded. calls Pooka.getStoreManager.getFolder(folderName) to
74    * cache the targetFolder.
75    */

76   public Address JavaDoc[] getTargetAddresses() {
77     return targetAddresses;
78   }
79
80 }
81
Popular Tags