diff options
| author | bwarsaw | 2002-10-08 00:02:00 +0000 |
|---|---|---|
| committer | bwarsaw | 2002-10-08 00:02:00 +0000 |
| commit | 7e5beaf9665444591b0c1d889b220acff240a928 (patch) | |
| tree | 25d3898b9af18f438e6cd170dfcba526c693c03e | |
| parent | 748d95d10b0fce9bd8576cf4cc8114f9e1027190 (diff) | |
| download | mailman-7e5beaf9665444591b0c1d889b220acff240a928.tar.gz mailman-7e5beaf9665444591b0c1d889b220acff240a928.tar.zst mailman-7e5beaf9665444591b0c1d889b220acff240a928.zip | |
When content filtering, we may not always want to just discard the
message. This is especially the case when debugging your filtering
rules. To support this we now have a "filter action" which can be
Discard, Reject, Forward to Admin, Preserve on disk.
process(): Call dispose() when we want to chuck the message.
dispose(): New function which disposes of a matching message based on
filter_action.
| -rw-r--r-- | Mailman/Handlers/MimeDel.py | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/Mailman/Handlers/MimeDel.py b/Mailman/Handlers/MimeDel.py index 5c5725a49..3bcdaffae 100644 --- a/Mailman/Handlers/MimeDel.py +++ b/Mailman/Handlers/MimeDel.py @@ -31,8 +31,11 @@ from email.Iterators import typed_subpart_iterator from Mailman import mm_cfg from Mailman import Errors +from Mailman.Message import UserNotification +from Mailman.Queue.sbcache import get_switchboard from Mailman.Logging.Syslog import syslog from Mailman.Version import VERSION +from Mailman.i18n import _ @@ -49,11 +52,13 @@ def process(mlist, msg, msgdata): filtertypes = mlist.filter_mime_types passtypes = mlist.pass_mime_types if ctype in filtertypes or mtype in filtertypes: - raise Errors.DiscardMessage + dispose(mlist, msg, msgdata, + _("The message's content type was explicitly disallowed")) # Check to see if there is a pass types and the outer type doesn't match # one of these types if passtypes and not (ctype in passtypes or mtype in passtypes): - raise Errors.DiscardMessage + dispose(mlist, msg, msgdata, + _("The message's content type was not explicitly allowed")) numparts = len([subpart for subpart in msg.walk()]) # If the message is a multipart, filter out matching subparts if msg.is_multipart(): @@ -64,7 +69,8 @@ def process(mlist, msg, msgdata): # before!) then, again it gets discarded. postlen = len(msg.get_payload()) if postlen == 0 and prelen > 0: - raise Errors.DiscardMessage + dispose(mlist, msg, msgdata, + _("After content filtering, the message was empty")) # Now replace all multipart/alternatives with just the first non-empty # alternative. BAW: We have to special case when the outer part is a # multipart/alternative because we need to retain most of the outer part's @@ -186,3 +192,29 @@ def to_plaintext(msg): subpart.set_type('text/plain') changedp = 1 return changedp + + + +def dispose(mlist, msg, msgdata, why): + # filter_action == 0 just discards, see below + if mlist.filter_action == 1: + # Bounce the message to the original author + raise Errors.RejectMessage, why + if mlist.filter_action == 2: + # Forward it on to the list owner + listname = mlist.internal_name() + mlist.ForwardMessage( + msg, + text=_("""\ +The attached message matched the %(listname)s mailing list's content filtering +rules and was prevented from being forwarded on to the list membership. You +are receiving the only remaining copy of the discarded message. + +"""), + subject=_('Content filtered message notification')) + if mlist.filter_action == 3 and \ + mm_cfg.OWNERS_CAN_PRESERVE_FILTERED_MESSAGES: + badq = get_switchboard(mm_cfg.BADQUEUE_DIR) + badq.enqueue(msg, msgdata) + # Most cases also discard the message + raise Errors.DiscardMessage |
