summaryrefslogtreecommitdiff
path: root/Mailman/app/bounces.py
diff options
context:
space:
mode:
authorBarry Warsaw2008-02-02 23:03:19 -0500
committerBarry Warsaw2008-02-02 23:03:19 -0500
commitf03c31acb800d79c606ee3e206868aef8a08bfda (patch)
tree15e0b72f129b6ee5f4515647c8c25e0c970a80d9 /Mailman/app/bounces.py
parent7c5b4d64df6532548742460d405a8a64e35b22c2 (diff)
parent4823801716b1bf1711d63b649b0fafd6acd30821 (diff)
downloadmailman-f03c31acb800d79c606ee3e206868aef8a08bfda.tar.gz
mailman-f03c31acb800d79c606ee3e206868aef8a08bfda.tar.zst
mailman-f03c31acb800d79c606ee3e206868aef8a08bfda.zip
Merge the 'rules' branch.
Give the first alpha a code name. This branch mostly gets rid of all the approval oriented handlers in favor of a chain-of-rules based approach. This will be much more powerful and extensible, allowing rule definition by plugin and chain creation via web page. When a message is processed by the incoming queue, it gets sent through a chain of rules. The starting chain is defined on the mailing list object, and there is a built-in default starting chain, called 'built-in'. Each chain is made up of links, which describe a rule and an action, along with possibly some other information. Actions allow processing to take a detour through another chain, jump to another chain, stop processing, run a function, etc. The built-in chain essentially implements the original early part of the handler pipeline. If a message makes it through the built-in chain, it gets sent to the prep queue, where the message is decorated and such before sending out to the list membership. The 'accept' chain is what moves the message into the prep queue. There are also 'hold', 'discard', and 'reject' chains, which do what you would expect them to. There are lots of built-in rules, implementing everything from the old emergency handler to new handlers such as one not allowing empty subject headers. IMember grows an is_moderated attribute. The 'adminapproved' metadata key is renamed 'moderator_approved'. Fix some bogus uses of noreply_address to no_reply_address. Stash an 'original_size' attribute on the message after parsing its plain text. This can be used later to ensure the original message does not exceed a specified size without have to flatten the message again. The KNOWN_SPAMMERS global variable is replaced with HEADER_MATCHES. The mailing list's header_filter_rules variable is replaced with header_matches which has the same semantics as HEADER_MATCHES, but is list-specific. DEFAULT_MAIL_COMMANDS_MAX_LINES -> EMAIL_COMMANDS_MAX_LINES. Update smtplistener.py to be much better, to use maildir format instead of mbox format, to respond to RSET commands by clearing the maildir, and by silencing annoying asyncore error messages. Extend the doctest runner so that it will run .txt files in any docs subdirectory in the code tree. Add plugable keys 'mailman.mta' and 'mailman.rules'. The latter may have only one setting while the former is extensible. There are lots of doctests which should give all the gory details. Mailman/Post.py -> Mailman/inject.py and the command line usage of this module is removed. SQLALCHEMY_ECHO, which was unused, is removed. Backport the ability to specify additional footer interpolation variables by the message metadata 'decoration-data' key. can_acknowledge() defines whether a message can be responded to by the email robot. Simplify the implementation of _reset() based on Storm fixes. Be able to handle lists in Storm values. Do some reorganization.
Diffstat (limited to 'Mailman/app/bounces.py')
-rw-r--r--Mailman/app/bounces.py101
1 files changed, 0 insertions, 101 deletions
diff --git a/Mailman/app/bounces.py b/Mailman/app/bounces.py
index 6df5c8aa6..3f38cbf67 100644
--- a/Mailman/app/bounces.py
+++ b/Mailman/app/bounces.py
@@ -19,8 +19,6 @@
__all__ = [
'bounce_message',
- 'has_explicit_destination',
- 'has_matching_bounce_header',
]
import re
@@ -62,102 +60,3 @@ def bounce_message(mlist, msg, e=None):
bmsg.attach(txt)
bmsg.attach(MIMEMessage(msg))
bmsg.send(mlist)
-
-
-
-# Helper function used to match a pattern against an address.
-def _domatch(pattern, addr):
- try:
- if re.match(pattern, addr, re.IGNORECASE):
- return True
- except re.error:
- # The pattern is a malformed regexp -- try matching safely,
- # with all non-alphanumerics backslashed:
- if re.match(re.escape(pattern), addr, re.IGNORECASE):
- return True
- return False
-
-
-def has_explicit_destination(mlist, msg):
- """Does the list's name or an acceptable alias appear in the recipients?
-
- :param mlist: The mailing list the message is destined for.
- :param msg: The email message object.
- :return: True if the message is explicitly destined for the mailing list,
- otherwise False.
- """
- # Check all recipient addresses against the list's explicit addresses,
- # specifically To: Cc: and Resent-to:
- recipients = []
- to = []
- for header in ('to', 'cc', 'resent-to', 'resent-cc'):
- to.extend(getaddresses(msg.get_all(header, [])))
- for fullname, address in to:
- # It's possible that if the header doesn't have a valid RFC 2822
- # value, we'll get None for the address. So skip it.
- if address is None or '@' not in address:
- continue
- address = address.lower()
- if address == mlist.posting_address:
- return True
- recipients.append(address)
- # Match the set of recipients against the list's acceptable aliases.
- aliases = mlist.acceptable_aliases.splitlines()
- for address in recipients:
- for alias in aliases:
- stripped = alias.strip()
- if not stripped:
- # Ignore blank or empty lines
- continue
- if domatch(stripped, address):
- return True
- return False
-
-
-
-def _parse_matching_header_opt(mlist):
- """Return a list of triples [(field name, regex, line), ...]."""
- # - Blank lines and lines with '#' as first char are skipped.
- # - Leading whitespace in the matchexp is trimmed - you can defeat
- # that by, eg, containing it in gratuitous square brackets.
- all = []
- for line in mlist.bounce_matching_headers.splitlines():
- line = line.strip()
- # Skip blank lines and lines *starting* with a '#'.
- if not line or line.startswith('#'):
- continue
- i = line.find(':')
- if i < 0:
- # This didn't look like a header line. BAW: should do a
- # better job of informing the list admin.
- log.error('bad bounce_matching_header line: %s\n%s',
- mlist.real_name, line)
- else:
- header = line[:i]
- value = line[i+1:].lstrip()
- try:
- cre = re.compile(value, re.IGNORECASE)
- except re.error, e:
- # The regexp was malformed. BAW: should do a better
- # job of informing the list admin.
- log.error("""\
-bad regexp in bounce_matching_header line: %s
-\n%s (cause: %s)""", mlist.real_name, value, e)
- else:
- all.append((header, cre, line))
- return all
-
-
-def has_matching_bounce_header(mlist, msg):
- """Does the message have a matching bounce header?
-
- :param mlist: The mailing list the message is destined for.
- :param msg: The email message object.
- :return: True if a header field matches a regexp in the
- bounce_matching_header mailing list variable.
- """
- for header, cre, line in _parse_matching_header_opt(mlist):
- for value in msg.get_all(header, []):
- if cre.search(value):
- return True
- return False