summaryrefslogtreecommitdiff
path: root/src/mailman/pipeline
diff options
context:
space:
mode:
authorBarry Warsaw2009-03-03 00:31:03 -0500
committerBarry Warsaw2009-03-03 00:31:03 -0500
commitf3ee1ed7d9198d79f7feaf6fb3bb5b6e5ae4bd38 (patch)
tree2c233acf23575b15cbaadfb67298c96b751651ce /src/mailman/pipeline
parentb6ed8a7c98ea02af9014793f3b508c601da6ea75 (diff)
downloadmailman-f3ee1ed7d9198d79f7feaf6fb3bb5b6e5ae4bd38.tar.gz
mailman-f3ee1ed7d9198d79f7feaf6fb3bb5b6e5ae4bd38.tar.zst
mailman-f3ee1ed7d9198d79f7feaf6fb3bb5b6e5ae4bd38.zip
Diffstat (limited to 'src/mailman/pipeline')
-rw-r--r--src/mailman/pipeline/docs/filtering.txt75
-rw-r--r--src/mailman/pipeline/mime_delete.py18
2 files changed, 48 insertions, 45 deletions
diff --git a/src/mailman/pipeline/docs/filtering.txt b/src/mailman/pipeline/docs/filtering.txt
index 70ca3098d..f895220f0 100644
--- a/src/mailman/pipeline/docs/filtering.txt
+++ b/src/mailman/pipeline/docs/filtering.txt
@@ -3,12 +3,9 @@ Content filtering
Mailman can filter the content of messages posted to a mailing list by
stripping MIME subparts, and possibly reorganizing the MIME structure of a
-message. It does this with the MimeDel handler module, although other
-handlers can potentially do other kinds of finer level content filtering.
+message.
- >>> from mailman.pipeline.mime_delete import process
- >>> mlist = config.db.list_manager.create(u'_xtest@example.com')
- >>> mlist.preferred_language = u'en'
+ >>> mlist = create_list(u'test@example.com')
Several mailing list options control content filtering. First, the feature
must be enabled, then there are two options that control which MIME types get
@@ -17,8 +14,8 @@ text/html parts will get converted to plain text. Let's set up some defaults
for these variables, then we'll explain them in more detail below.
>>> mlist.filter_content = True
- >>> mlist.filter_mime_types = []
- >>> mlist.pass_mime_types = []
+ >>> mlist.filter_types = []
+ >>> mlist.pass_types = []
>>> mlist.convert_html_to_plaintext = False
@@ -29,9 +26,11 @@ A simple filtering setting will just search the content types of the messages
parts, discarding all parts with a matching MIME type. If the message's outer
content type matches the filter, the entire message will be discarded.
- >>> mlist.filter_mime_types = ['image/jpeg']
- >>> # XXX Change this to an enum
- >>> mlist.filter_action = 0 # Discard
+ >>> from mailman.interfaces.mime import FilterAction
+
+ >>> mlist.filter_types = [u'image/jpeg']
+ >>> mlist.filter_action = FilterAction.discard
+
>>> msg = message_from_string("""\
... From: aperson@example.com
... Content-Type: image/jpeg
@@ -39,6 +38,8 @@ content type matches the filter, the entire message will be discarded.
...
... xxxxx
... """)
+
+ >>> process = config.handlers['mime-delete'].process
>>> process(mlist, msg, {})
Traceback (most recent call last):
...
@@ -85,20 +86,21 @@ just that subpart will be stripped.
... From: aperson@example.com
... Content-Type: multipart/mixed; boundary=BOUNDARY
... MIME-Version: 1.0
- ...
+ ...
... --BOUNDARY
... Content-Type: image/jpeg
... MIME-Version: 1.0
- ...
+ ...
... xxx
- ...
+ ...
... --BOUNDARY
... Content-Type: image/gif
... MIME-Version: 1.0
- ...
+ ...
... yyy
... --BOUNDARY--
... """)
+
>>> process(mlist, msg, {})
>>> print msg.as_string()
From: aperson@example.com
@@ -136,24 +138,24 @@ subpart.
... From: aperson@example.com
... Content-Type: multipart/mixed; boundary=BOUNDARY
... MIME-Version: 1.0
- ...
+ ...
... --BOUNDARY
... Content-Type: multipart/alternative; boundary=BOUND2
... MIME-Version: 1.0
- ...
+ ...
... --BOUND2
... Content-Type: image/jpeg
... MIME-Version: 1.0
- ...
+ ...
... xxx
- ...
+ ...
... --BOUND2
... Content-Type: image/gif
... MIME-Version: 1.0
- ...
+ ...
... yyy
... --BOUND2--
- ...
+ ...
... --BOUNDARY--
... """)
>>> process(mlist, msg, {})
@@ -176,21 +178,22 @@ part with just one subpart, the entire message is converted to the left over
part's content type. In other words, the left over inner part is promoted to
being the outer part.
- >>> mlist.filter_mime_types.append('text/html')
+ >>> mlist.filter_types = [u'image/jpeg', u'text/html']
>>> msg = message_from_string("""\
... From: aperson@example.com
... Content-Type: multipart/alternative; boundary=AAA
- ...
+ ...
... --AAA
... Content-Type: text/html
- ...
+ ...
... <b>This is some html</b>
... --AAA
... Content-Type: text/plain
- ...
+ ...
... This is plain text
... --AAA--
... """)
+
>>> process(mlist, msg, {})
>>> print msg.as_string()
From: aperson@example.com
@@ -201,7 +204,7 @@ being the outer part.
Clean up.
- >>> ignore = mlist.filter_mime_types.pop()
+ >>> mlist.filter_types = [u'image/jpeg']
Conversion to plain text
@@ -245,7 +248,7 @@ name of the file containing the message payload to filter.
... From: aperson@example.com
... Content-Type: text/html
... MIME-Version: 1.0
- ...
+ ...
... <html><head></head>
... <body></body></html>
... """)
@@ -272,39 +275,39 @@ the entire inner multipart/mixed is discarded.
>>> msg = message_from_string("""\
... From: aperson@example.com
... Content-Type: multipart/mixed; boundary=AAA
- ...
+ ...
... --AAA
... Content-Type: multipart/mixed; boundary=BBB
- ...
+ ...
... --BBB
... Content-Type: image/jpeg
- ...
+ ...
... xxx
... --BBB
... Content-Type: image/jpeg
- ...
+ ...
... yyy
... --BBB---
... --AAA
... Content-Type: multipart/alternative; boundary=CCC
- ...
+ ...
... --CCC
... Content-Type: text/html
- ...
+ ...
... <h2>This is a header</h2>
- ...
+ ...
... --CCC
... Content-Type: text/plain
- ...
+ ...
... A different message
... --CCC--
... --AAA
... Content-Type: image/gif
- ...
+ ...
... zzz
... --AAA
... Content-Type: image/gif
- ...
+ ...
... aaa
... --AAA--
... """)
diff --git a/src/mailman/pipeline/mime_delete.py b/src/mailman/pipeline/mime_delete.py
index 3c4e4154f..17da13c4a 100644
--- a/src/mailman/pipeline/mime_delete.py
+++ b/src/mailman/pipeline/mime_delete.py
@@ -54,17 +54,12 @@ log = logging.getLogger('mailman.error')
def process(mlist, msg, msgdata):
- # Short-circuits
- if not mlist.filter_content:
- return
- if msgdata.get('isdigest'):
- return
# We also don't care about our own digests or plaintext
ctype = msg.get_content_type()
mtype = msg.get_content_maintype()
# Check to see if the outer type matches one of the filter types
- filtertypes = mlist.filter_mime_types
- passtypes = mlist.pass_mime_types
+ filtertypes = set(mlist.filter_types)
+ passtypes = set(mlist.pass_types)
if ctype in filtertypes or mtype in filtertypes:
dispose(mlist, msg, msgdata,
_("The message's content type was explicitly disallowed"))
@@ -74,8 +69,8 @@ def process(mlist, msg, msgdata):
dispose(mlist, msg, msgdata,
_("The message's content type was not explicitly allowed"))
# Filter by file extensions
- filterexts = mlist.filter_filename_extensions
- passexts = mlist.pass_filename_extensions
+ filterexts = set(mlist.filter_extensions)
+ passexts = set(mlist.pass_extensions)
fext = get_file_ext(msg)
if fext:
if fext in filterexts:
@@ -282,4 +277,9 @@ class MIMEDelete:
description = _('Filter the MIME content of messages.')
def process(self, mlist, msg, msgdata):
+ # Short-circuits
+ if not mlist.filter_content:
+ return
+ if msgdata.get('isdigest'):
+ return
process(mlist, msg, msgdata)