Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core
Commits:
234b16f7 by Mark Sapiro at 2019-07-29T02:26:12Z
Decode message body for html_to_plaintext.
- - - - -
941991be by Abhilash Raj at 2019-07-29T02:26:12Z
Merge branch 'mimedel' into 'master'
Decode message body for html_to_plaintext.
Closes #616
See merge request mailman/mailman!542
- - - - -
3 changed files:
- src/mailman/docs/NEWS.rst
- src/mailman/handlers/mime_delete.py
- src/mailman/handlers/tests/test_mimedel.py
Changes:
=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -35,6 +35,8 @@ Bugs
with a string object instead of bytes. (Closes #613)
* A post with a Reply-To: the list address will no longer be shunted.
(Closes #614)
+* Encoded (base64 or quoted-printable) HTML message bodies are now decoded for
+ ``html_to_plaintext``. (Closes #616)
Command line
------------
=====================================
src/mailman/handlers/mime_delete.py
=====================================
@@ -274,8 +274,10 @@ def to_plaintext(msg):
resources.callback(shutil.rmtree, tempdir)
for subpart in typed_subpart_iterator(msg, 'text', 'html'):
filename = os.path.join(tempdir, '{}.html'.format(next(counter)))
+ ctype = msg.get_content_charset('utf-8')
with open(filename, 'w', encoding='utf-8') as fp:
- fp.write(subpart.get_payload())
+ fp.write(subpart.get_payload(decode=True).decode(ctype,
+ errors='replace'))
template = Template(config.mailman.html_to_plain_text_command)
command = template.safe_substitute(filename=filename).split()
try:
=====================================
src/mailman/handlers/tests/test_mimedel.py
=====================================
@@ -61,6 +61,7 @@ if len(sys.argv) > 2:
sys.exit(1)
print('Converted text/html to text/plain')
print('Filename:', sys.argv[1])
+print(open(sys.argv[1]).readlines()[0])
""", file=fp)
config.push('dummy script', """\
[mailman]
@@ -239,6 +240,27 @@ MIME-Version: 1.0
payload_lines = msg.get_payload().splitlines()
self.assertEqual(payload_lines[0], 'Converted text/html to text/plain')
+ def test_convert_html_to_plaintext_base64(self):
+ # Converting to plain text calls a command line script with decoded
+ # message body.
+ msg = mfs("""\
+From: [email protected]
+Content-Type: text/html
+Content-Transfer-Encoding: base64
+MIME-Version: 1.0
+
+PGh0bWw+PGhlYWQ+PC9oZWFkPgo8Ym9keT48L2JvZHk+PC9odG1sPgo=
+""")
+ process = config.handlers['mime-delete'].process
+ with dummy_script():
+ process(self._mlist, msg, {})
+ self.assertEqual(msg.get_content_type(), 'text/plain')
+ self.assertTrue(
+ 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')
+ self.assertEqual(payload_lines[2], '<html><head></head>')
+
def test_convert_html_to_plaintext_error_return(self):
# Calling a script which returns an error status is properly logged.
msg = mfs("""\
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/d2adb78eb5abe40d89bf3336c8ed0ea6ce4a93ff...941991bebc5c882c96d5f09c0e3a54a5e76f2104
--
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/d2adb78eb5abe40d89bf3336c8ed0ea6ce4a93ff...941991bebc5c882c96d5f09c0e3a54a5e76f2104
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org