KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > mail > IncomingFilter


1 /*
2  * IncomingFilter.java
3  *
4  * Copyright (C) 2002 Peter Graves
5  * $Id: IncomingFilter.java,v 1.1.1.1 2002/09/24 16:09:44 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j.mail;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26 import org.armedbear.j.Log;
27
28 public final class IncomingFilter
29 {
30     public static final int NOTHING = 0;
31     public static final int MOVE = 1;
32     public static final int BOUNCE = 2;
33     public static final int BOUNCE_AND_DELETE = 3;
34
35     private static ArrayList JavaDoc filterList;
36
37     private final String JavaDoc mailbox;
38     private final String JavaDoc pattern;
39     private final MailboxFilter filter;
40     private final int action;
41     private final String JavaDoc parameter;
42
43     private IncomingFilter(String JavaDoc mailbox, String JavaDoc pattern, MailboxFilter filter,
44         int action, String JavaDoc parameter)
45     {
46         this.mailbox = mailbox;
47         this.pattern = pattern;
48         this.filter = filter;
49         this.action = action;
50         this.parameter = parameter;
51     }
52
53     public final String JavaDoc getPattern()
54     {
55         return pattern;
56     }
57
58     public final MailboxFilter getFilter()
59     {
60         return filter;
61     }
62
63     public final int getAction()
64     {
65         return action;
66     }
67
68     public final String JavaDoc getParameter()
69     {
70         return parameter;
71     }
72
73     public static synchronized void addIncomingFilter(
74         String JavaDoc mailbox,
75         String JavaDoc pattern,
76         String JavaDoc actionName,
77         String JavaDoc parameter)
78     {
79         if (mailbox == null) return;
80         if (pattern == null) return;
81         if (actionName == null) return;
82         if (parameter == null) return;
83         if (!mailbox.equals("inbox")) {
84             Log.error("addIncomingFilter - only \"inbox\" is supported");
85             return;
86         }
87         MailboxFilter filter = MailboxFilter.getMailboxFilter(pattern);
88         if (filter == null) {
89             Log.error("addIncomingFilter - bad pattern |" + pattern + "|");
90             return;
91         }
92         int action = NOTHING;
93         if (actionName.equalsIgnoreCase("move"))
94             action = MOVE;
95         else if (actionName.equalsIgnoreCase("bounce"))
96             action = BOUNCE;
97         else if (actionName.equalsIgnoreCase("bounce_and_delete"))
98             action = BOUNCE_AND_DELETE;
99         else {
100             Log.error("addIncomingFilter - action \"" + actionName +
101                 "\" is not supported");
102             return;
103         }
104         if (filterList == null)
105             filterList = new ArrayList JavaDoc();
106         filterList.add(new IncomingFilter(mailbox, pattern, filter, action,
107             parameter));
108     }
109
110     public static synchronized final void resetIncomingFilters()
111     {
112         filterList = null;
113     }
114
115     public static synchronized final List JavaDoc getFilterList()
116     {
117         return filterList == null ? null : new ArrayList JavaDoc(filterList);
118     }
119 }
Popular Tags