summaryrefslogtreecommitdiff
path: root/src/mailman/handlers/tests/test_mimedel.py
diff options
context:
space:
mode:
authorMark Sapiro2017-05-23 17:51:52 +0000
committerBarry Warsaw2017-05-23 17:51:52 +0000
commit98d3a060093941e0d593d7128e3d5e141328068e (patch)
tree5fa76ca26dc5e48efb44849edf1d30e918d1e67a /src/mailman/handlers/tests/test_mimedel.py
parentcabccce9f8a905e3a495486a0fd6d86d1acfff72 (diff)
downloadmailman-98d3a060093941e0d593d7128e3d5e141328068e.tar.gz
mailman-98d3a060093941e0d593d7128e3d5e141328068e.tar.zst
mailman-98d3a060093941e0d593d7128e3d5e141328068e.zip
Diffstat (limited to 'src/mailman/handlers/tests/test_mimedel.py')
-rw-r--r--src/mailman/handlers/tests/test_mimedel.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/mailman/handlers/tests/test_mimedel.py b/src/mailman/handlers/tests/test_mimedel.py
index 5e536134f..01cac0f20 100644
--- a/src/mailman/handlers/tests/test_mimedel.py
+++ b/src/mailman/handlers/tests/test_mimedel.py
@@ -19,11 +19,13 @@
import os
import sys
+import email
import shutil
import tempfile
import unittest
from contextlib import ExitStack, contextmanager
+from io import StringIO
from mailman.app.lifecycle import create_list
from mailman.config import config
from mailman.handlers import mime_delete
@@ -35,6 +37,7 @@ from mailman.testing.helpers import (
LogFileMark, configuration, get_queue_messages,
specialized_message_from_string as mfs)
from mailman.testing.layers import ConfigLayer
+from pkg_resources import resource_filename
from zope.component import getUtility
@@ -215,3 +218,73 @@ MIME-Version: 1.0
msg['x-content-filtered-by'].startswith('Mailman/MimeDel'))
payload_lines = msg.get_payload().splitlines()
self.assertEqual(payload_lines[0], 'Converted text/html to text/plain')
+
+
+class TestMiscellaneous(unittest.TestCase):
+ """Test various miscellaneous filtering actions."""
+
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+ self._mlist.collapse_alternatives = True
+ self._mlist.filter_content = True
+ self._mlist.filter_extensions = ['xlsx']
+
+ def test_collapse_alternatives(self):
+ email_file = resource_filename(
+ 'mailman.handlers.tests.data', 'collapse_alternatives.eml')
+ with open(email_file) as fp:
+ msg = email.message_from_file(fp)
+ process = config.handlers['mime-delete'].process
+ process(self._mlist, msg, {})
+ structure = StringIO()
+ email.iterators._structure(msg, fp=structure)
+ self.assertEqual(structure.getvalue(), """\
+multipart/signed
+ multipart/mixed
+ text/plain
+ text/plain
+ application/pgp-signature
+""")
+
+ def test_msg_rfc822(self):
+ email_file = resource_filename(
+ 'mailman.handlers.tests.data', 'msg_rfc822.eml')
+ email_file2 = resource_filename(
+ 'mailman.handlers.tests.data', 'msg_rfc822_out.eml')
+ with open(email_file) as fp:
+ msg = email.message_from_file(fp)
+ process = config.handlers['mime-delete'].process
+ process(self._mlist, msg, {})
+ with open(email_file2) as fp:
+ self.assertEqual(msg.as_string(), fp.read())
+
+ def test_mixed_case_ext_and_recast(self):
+ msg = mfs("""\
+From: anne@example.com
+To: test@example.com
+Subject: Testing mixed extension
+Message-ID: <ant>
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="AAAA"
+
+--AAAA
+Content-Type: text/plain; charset="utf-8"
+
+Plain text
+
+--AAAA
+Content-Type: application/octet-stream; name="test.xlsX"
+Content-Disposition: attachment; filename="test.xlsX"
+
+spreadsheet
+
+--AAAA--
+""")
+ process = config.handlers['mime-delete'].process
+ process(self._mlist, msg, {})
+ self.assertEqual(msg['content-type'], 'text/plain; charset="utf-8"')
+ self.assertEqual(msg.get_payload(), """\
+Plain text
+""")