Abhilash Raj pushed to branch master at GNU Mailman / Mailman Core
Commits:
dfcc7419 by Mark Sapiro at 2019-10-13T20:48:20Z
Fixed KeyError when fully personalizing a message without a To: header.
- - - - -
4f065aad by Abhilash Raj at 2019-10-13T20:48:21Z
Merge branch 'fix_639' into 'master'
Fixed KeyError when fully personalizing a message without a To: header.
Closes #639
See merge request mailman/mailman!567
- - - - -
3 changed files:
- src/mailman/docs/NEWS.rst
- src/mailman/mta/personalized.py
- src/mailman/mta/tests/test_delivery.py
Changes:
=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -17,6 +17,8 @@ Bugs
----
* It is now possible to add the list posting address with nonmember role, e.g.
to give it a moderaction of discard. (Closes #633)
+* The issue of posting a message without a To: header to a fully personalized
+ list throwing a KeyError has been fixed. (Closes #639)
3.3.0 -- "Tom Sawyer"
=====================
=====================================
src/mailman/mta/personalized.py
=====================================
@@ -49,13 +49,19 @@ class PersonalizedMixin:
user_manager = getUtility(IUserManager)
user = user_manager.get_user(recipient)
if user is None:
- msg.replace_header('To', recipient)
+ if msg.get('to'):
+ msg.replace_header('To', recipient)
+ else:
+ msg['To'] = recipient
else:
# Convert the unicode name to an email-safe representation.
# Create a Header instance for the name so that it's properly
# encoded for email transport.
name = Header(user.display_name).encode()
- msg.replace_header('To', formataddr((name, recipient)))
+ if msg.get('to'):
+ msg.replace_header('To', formataddr((name, recipient)))
+ else:
+ msg['To'] = formataddr((name, recipient))
@public
=====================================
src/mailman/mta/tests/test_delivery.py
=====================================
@@ -136,6 +136,104 @@ delivered: [email protected]
language : English (USA)
name : Anne Person
+""")
+
+ def test_full_personalization(self):
+ self._mlist.personalize = Personalization.full
+ msgdata = dict(recipients=['[email protected]'])
+ agent = DeliverTester()
+ refused = agent.deliver(self._mlist, self._msg, msgdata)
+ self.assertEqual(len(refused), 0)
+ self.assertEqual(len(_deliveries), 1)
+ _mlist, _msg, _msgdata, _recipients = _deliveries[0]
+ self.assertMultiLineEqual(_msg.as_string(), """\
+From: [email protected]
+To: Anne Person <[email protected]>
+Subject: test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
+Content-Transfer-Encoding: 7bit
+
+
+address : [email protected]
+delivered: [email protected]
+language : English (USA)
+name : Anne Person
+
+""")
+
+ def test_full_personalization_no_to(self):
+ self._mlist.personalize = Personalization.full
+ del self._msg['to']
+ msgdata = dict(recipients=['[email protected]'])
+ agent = DeliverTester()
+ refused = agent.deliver(self._mlist, self._msg, msgdata)
+ self.assertEqual(len(refused), 0)
+ self.assertEqual(len(_deliveries), 1)
+ _mlist, _msg, _msgdata, _recipients = _deliveries[0]
+ self.assertMultiLineEqual(_msg.as_string(), """\
+From: [email protected]
+Subject: test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
+Content-Transfer-Encoding: 7bit
+To: Anne Person <[email protected]>
+
+
+address : [email protected]
+delivered: [email protected]
+language : English (USA)
+name : Anne Person
+
+""")
+
+ def test_full_personalization_no_user(self):
+ self._mlist.personalize = Personalization.full
+ msgdata = dict(recipients=['[email protected]'])
+ agent = DeliverTester()
+ refused = agent.deliver(self._mlist, self._msg, msgdata)
+ self.assertEqual(len(refused), 0)
+ self.assertEqual(len(_deliveries), 1)
+ _mlist, _msg, _msgdata, _recipients = _deliveries[0]
+ self.assertMultiLineEqual(_msg.as_string(), """\
+From: [email protected]
+To: [email protected]
+Subject: test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
+Content-Transfer-Encoding: 7bit
+
+
+address : $user_address
+delivered: $user_delivered_to
+language : $user_language
+name : $user_name
+
+""")
+
+ def test_full_personalization_no_user_no_to(self):
+ self._mlist.personalize = Personalization.full
+ del self._msg['to']
+ msgdata = dict(recipients=['[email protected]'])
+ agent = DeliverTester()
+ refused = agent.deliver(self._mlist, self._msg, msgdata)
+ self.assertEqual(len(refused), 0)
+ self.assertEqual(len(_deliveries), 1)
+ _mlist, _msg, _msgdata, _recipients = _deliveries[0]
+ self.assertMultiLineEqual(_msg.as_string(), """\
+From: [email protected]
+Subject: test
+MIME-Version: 1.0
+Content-Type: text/plain; charset="us-ascii"
+Content-Transfer-Encoding: 7bit
+To: [email protected]
+
+
+address : $user_address
+delivered: $user_delivered_to
+language : $user_language
+name : $user_name
+
""")
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/8c8386fbcbca02bca3150db7569242a2a050b4f8...4f065aad4efeda4096b3af776d65f3db58d81cb8
--
View it on GitLab:
https://gitlab.com/mailman/mailman/compare/8c8386fbcbca02bca3150db7569242a2a050b4f8...4f065aad4efeda4096b3af776d65f3db58d81cb8
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