summaryrefslogtreecommitdiff
path: root/Mailman/app/chains.py
diff options
context:
space:
mode:
authorBarry Warsaw2008-02-27 01:26:18 -0500
committerBarry Warsaw2008-02-27 01:26:18 -0500
commita1c73f6c305c7f74987d99855ba59d8fa823c253 (patch)
tree65696889450862357c9e05c8e9a589f1bdc074ac /Mailman/app/chains.py
parent3f31f8cce369529d177cfb5a7c66346ec1e12130 (diff)
downloadmailman-a1c73f6c305c7f74987d99855ba59d8fa823c253.tar.gz
mailman-a1c73f6c305c7f74987d99855ba59d8fa823c253.tar.zst
mailman-a1c73f6c305c7f74987d99855ba59d8fa823c253.zip
Diffstat (limited to 'Mailman/app/chains.py')
-rw-r--r--Mailman/app/chains.py115
1 files changed, 0 insertions, 115 deletions
diff --git a/Mailman/app/chains.py b/Mailman/app/chains.py
deleted file mode 100644
index 6b34b1dfb..000000000
--- a/Mailman/app/chains.py
+++ /dev/null
@@ -1,115 +0,0 @@
-# Copyright (C) 2007-2008 by the Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-# USA.
-
-"""Application support for chain processing."""
-
-__all__ = [
- 'initialize',
- 'process',
- ]
-__metaclass__ = type
-
-
-from Mailman.chains.accept import AcceptChain
-from Mailman.chains.discard import DiscardChain
-from Mailman.chains.headers import HeaderMatchChain
-from Mailman.chains.hold import HoldChain
-from Mailman.chains.reject import RejectChain
-from Mailman.chains.builtin import BuiltInChain
-from Mailman.configuration import config
-from Mailman.interfaces import LinkAction
-
-
-
-def process(mlist, msg, msgdata, start_chain='built-in'):
- """Process the message through a chain.
-
- :param mlist: the IMailingList for this message.
- :param msg: The Message object.
- :param msgdata: The message metadata dictionary.
- :param start_chain: The name of the chain to start the processing with.
- """
- # Set up some bookkeeping.
- chain_stack = []
- msgdata['rule_hits'] = hits = []
- msgdata['rule_misses'] = misses = []
- # Find the starting chain and begin iterating through its links.
- chain = config.chains[start_chain]
- chain_iter = chain.get_links(mlist, msg, msgdata)
- # Loop until we've reached the end of all processing chains.
- while chain:
- # Iterate over all links in the chain. Do this outside a for-loop so
- # we can capture a chain's link iterator in mid-flight. This supports
- # the 'detour' link action
- try:
- link = chain_iter.next()
- except StopIteration:
- # This chain is exhausted. Pop the last chain on the stack and
- # continue iterating through it. If there's nothing left on the
- # chain stack then we're completely finished processing.
- if len(chain_stack) == 0:
- return
- chain, chain_iter = chain_stack.pop()
- continue
- # Process this link.
- if link.rule.check(mlist, msg, msgdata):
- if link.rule.record:
- hits.append(link.rule.name)
- # The rule matched so run its action.
- if link.action is LinkAction.jump:
- chain = link.chain
- chain_iter = chain.get_links(mlist, msg, msgdata)
- continue
- elif link.action is LinkAction.detour:
- # Push the current chain so that we can return to it when
- # the next chain is finished.
- chain_stack.append((chain, chain_iter))
- chain = link.chain
- chain_iter = chain.get_links(mlist, msg, msgdata)
- continue
- elif link.action is LinkAction.stop:
- # Stop all processing.
- return
- elif link.action is LinkAction.defer:
- # Just process the next link in the chain.
- pass
- elif link.action is LinkAction.run:
- link.function(mlist, msg, msgdata)
- else:
- raise AssertionError('Bad link action: %s' % link.action)
- else:
- # The rule did not match; keep going.
- if link.rule.record:
- misses.append(link.rule.name)
-
-
-
-def initialize():
- """Set up chains, both built-in and from the database."""
- for chain_class in (DiscardChain, HoldChain, RejectChain, AcceptChain):
- chain = chain_class()
- assert chain.name not in config.chains, (
- 'Duplicate chain name: %s' % chain.name)
- config.chains[chain.name] = chain
- # Set up a couple of other default chains.
- chain = BuiltInChain()
- config.chains[chain.name] = chain
- # Create and initialize the header matching chain.
- chain = HeaderMatchChain()
- config.chains[chain.name] = chain
- # XXX Read chains from the database and initialize them.
- pass