Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core
Commits:
5270bc38 by Tommy M. McGuire at 2021-05-20T21:47:03-05:00
Join header lines when getting senders
RFC2047-decode From header then join multi-line values of From, etc.,
headers before parsing out email addresses.
This should fix #903.
- - - - -
7775c730 by Mark Sapiro at 2021-05-21T03:17:36+00:00
Merge branch 'senders_long_header_issue_903' into 'master'
Decode and unfold header lines when getting senders.
Closes #903
See merge request mailman/mailman!865
- - - - -
3 changed files:
- src/mailman/docs/NEWS.rst
- src/mailman/email/message.py
- src/mailman/email/tests/test_message.py
Changes:
=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -65,6 +65,8 @@ Bugs
accept emojis and other 4-byte unicode characters by using the utf8mb4
character set instead of 3-byte. (Closes #891)
* LMTP runner now sets unixfrom in incoming messages. (Closes #904)
+* Message RFC2047-decodes and unfolds headers before looking for
+ senders. (Closes #903)
Command line
------------
=====================================
src/mailman/email/message.py
=====================================
@@ -23,11 +23,12 @@ safe pickle deserialization, even if the email package adds
additional Message
attributes.
"""
+import re
import email
import email.message
import email.utils
-from email.header import Header
+from email.header import Header, decode_header, make_header
from email.mime.multipart import MIMEMultipart
from mailman.config import config
from mailman.interfaces.address import IEmailValidator
@@ -107,7 +108,12 @@ class Message(email.message.Message):
else:
for field_value in self.get_all(header, []):
# Convert the header to str in case it's a Header instance.
- name, address = email.utils.parseaddr(str(field_value))
+ header_value = re.sub(
+ '[\r\n]',
+ '',
+ str(make_header(decode_header(field_value)))
+ )
+ name, address = email.utils.parseaddr(header_value)
senders.append(address.lower())
# Filter out invalid addresses, None and the empty string, and convert
# to unicode.
=====================================
src/mailman/email/tests/test_message.py
=====================================
@@ -99,6 +99,14 @@ Test content
# Make sure the senders property does not fail
self.assertEqual(msg.senders, ['[email protected]'])
+ def test_senders_long_header(self):
+ msg = Message()
+ msg['From'] = (
+ '"User, A. Very Long Name W. (CNTR-DEPT)[An Employer,\r\n'
+ ' Inc.]" <[email protected]>'
+ )
+ self.assertEqual(msg.senders, ['[email protected]'])
+
def test_user_notification_bad_charset(self):
msg = UserNotification(
'[email protected]',
View it on GitLab:
https://gitlab.com/mailman/mailman/-/compare/71c2e368708bd9bfab4adeb4f569cb75e58852c3...7775c730b6a3225ebdcb60a8e6d8b14bc7975d06
--
View it on GitLab:
https://gitlab.com/mailman/mailman/-/compare/71c2e368708bd9bfab4adeb4f569cb75e58852c3...7775c730b6a3225ebdcb60a8e6d8b14bc7975d06
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/mailman-checkins.python.org/
Member address: [email protected]