001: /*
002: * IncomingFilter.java
003: *
004: * Copyright (C) 2002 Peter Graves
005: * $Id: IncomingFilter.java,v 1.1.1.1 2002/09/24 16:09:44 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j.mail;
023:
024: import java.util.ArrayList;
025: import java.util.List;
026: import org.armedbear.j.Log;
027:
028: public final class IncomingFilter {
029: public static final int NOTHING = 0;
030: public static final int MOVE = 1;
031: public static final int BOUNCE = 2;
032: public static final int BOUNCE_AND_DELETE = 3;
033:
034: private static ArrayList filterList;
035:
036: private final String mailbox;
037: private final String pattern;
038: private final MailboxFilter filter;
039: private final int action;
040: private final String parameter;
041:
042: private IncomingFilter(String mailbox, String pattern,
043: MailboxFilter filter, int action, String parameter) {
044: this .mailbox = mailbox;
045: this .pattern = pattern;
046: this .filter = filter;
047: this .action = action;
048: this .parameter = parameter;
049: }
050:
051: public final String getPattern() {
052: return pattern;
053: }
054:
055: public final MailboxFilter getFilter() {
056: return filter;
057: }
058:
059: public final int getAction() {
060: return action;
061: }
062:
063: public final String getParameter() {
064: return parameter;
065: }
066:
067: public static synchronized void addIncomingFilter(String mailbox,
068: String pattern, String actionName, String parameter) {
069: if (mailbox == null)
070: return;
071: if (pattern == null)
072: return;
073: if (actionName == null)
074: return;
075: if (parameter == null)
076: return;
077: if (!mailbox.equals("inbox")) {
078: Log
079: .error("addIncomingFilter - only \"inbox\" is supported");
080: return;
081: }
082: MailboxFilter filter = MailboxFilter.getMailboxFilter(pattern);
083: if (filter == null) {
084: Log.error("addIncomingFilter - bad pattern |" + pattern
085: + "|");
086: return;
087: }
088: int action = NOTHING;
089: if (actionName.equalsIgnoreCase("move"))
090: action = MOVE;
091: else if (actionName.equalsIgnoreCase("bounce"))
092: action = BOUNCE;
093: else if (actionName.equalsIgnoreCase("bounce_and_delete"))
094: action = BOUNCE_AND_DELETE;
095: else {
096: Log.error("addIncomingFilter - action \"" + actionName
097: + "\" is not supported");
098: return;
099: }
100: if (filterList == null)
101: filterList = new ArrayList();
102: filterList.add(new IncomingFilter(mailbox, pattern, filter,
103: action, parameter));
104: }
105:
106: public static synchronized final void resetIncomingFilters() {
107: filterList = null;
108: }
109:
110: public static synchronized final List getFilterList() {
111: return filterList == null ? null : new ArrayList(filterList);
112: }
113: }
|