Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core
Commits: 663f4eff by Mark Sapiro at 2023-01-02T22:42:20+00:00 Don't replace non-ascii in subjects in notifications - use utf-8. Fixes #673 - - - - - 47a4f235 by Mark Sapiro at 2023-01-02T22:42:20+00:00 Merge branch '673' into 'master' Don't replace non-ascii in subjects in notifications - use utf-8. Closes #673 See merge request mailman/mailman!1082 - - - - - 3 changed files: - src/mailman/chains/hold.py - src/mailman/chains/tests/test_hold.py - src/mailman/docs/NEWS.rst Changes: ===================================== src/mailman/chains/hold.py ===================================== @@ -162,12 +162,15 @@ class HoldChain(TerminalChainBase): if original_subject is None: original_subject = _('(no subject)') else: - # This must be encoded to the mailing list's perferred charset, - # ignoring incompatible characters, otherwise when creating the - # notification messages, we could get a Unicode error. + # We try to encode to the mailing list's perferred charset, + # but if we can't, we leave it as is because notificatuins can now + # be sent as utf-8 if necessary. oneline_subject = oneline(original_subject, in_unicode=True) - bytes_subject = oneline_subject.encode(charset, 'replace') - original_subject = bytes_subject.decode(charset) + try: + bytes_subject = oneline_subject.encode(charset) + original_subject = bytes_subject.decode(charset) + except UnicodeError: + original_subject = oneline_subject substitutions = dict( subject=original_subject, sender_email=msg.sender, @@ -233,8 +236,13 @@ class HoldChain(TerminalChainBase): nmsg.set_type('multipart/mixed') template = getUtility(ITemplateLoader).get( 'list:admin:action:post', mlist) - text = MIMEText(expand(template, mlist, substitutions), - _charset=charset) + try: + text = MIMEText(expand(template, mlist, substitutions), + _charset=charset) + except UnicodeError: + # Fall back to utf-8 if necessary. + text = MIMEText(expand(template, mlist, substitutions), + _charset='utf-8') dmsg = MIMEText(wrap(_("""\ If you reply to this message, keeping the Subject: header intact, Mailman will discard the held message. Do this if the message is spam. If you reply to ===================================== src/mailman/chains/tests/test_hold.py ===================================== @@ -172,6 +172,7 @@ A message body. def test_hold_chain_charset(self): # Issue #144 - UnicodeEncodeError in the hold chain. + # Also, issue # 673 use UTF-8 rather than replace. self._mlist.admin_immed_notify = True self._mlist.respond_to_post_requests = False bart = self._user_manager.create_user('b...@example.com', 'Bart User') @@ -189,15 +190,37 @@ A message body. # Ensure that the subject looks correct in the postauth.txt. msg = items[0].msg value = None - for line in msg.get_payload(0).get_payload().splitlines(): + payload = msg.get_payload(0).get_payload(decode=True).decode('utf-8') + for line in payload.splitlines(): if line.strip().startswith('Subject:'): header, colon, value = line.partition(':') break - self.assertEqual(value.lstrip(), 'Vi?enamjenski pi?tolj za vodu 8/1') + self.assertEqual(value.lstrip(), 'Višenamjenski pištolj za vodu 8/1') self.assertEqual( msg['Subject'], 't...@example.com post from a...@example.com requires approval') + def test_hold_chain_charset_user(self): + # Issue # 673 use UTF-8 rather than replace in user notice. + self._mlist.admin_immed_notify = False + self._mlist.respond_to_post_requests = True + msg = mfb(read_binary('mailman.chains.tests', 'issue144.eml')) + msg.sender = 'a...@example.com' + process_chain(self._mlist, msg, {}, start_chain='hold') + # The user notice message is now in the virgin queue awaiting + # delivery to the user. + items = get_queue_messages('virgin', expected_count=1) + msgdata = items[0].msgdata + # Should get sent to -owner address. + self.assertEqual(msgdata['recipients'], {'a...@example.com'}) + # Ensure that the subject looks correct in the postauth.txt. + msg = items[0].msg + payload = msg.get_payload(decode=True).decode('utf-8') + self.assertIn('Višenamjenski pištolj za vodu 8/1', payload) + self.assertEqual( + msg['Subject'], + 'Your message to t...@example.com awaits moderator approval') + def test_hold_chain_crosspost(self): mlist2 = create_list('te...@example.com') msg = mfs("""\ ===================================== src/mailman/docs/NEWS.rst ===================================== @@ -26,6 +26,7 @@ Bugs fixed the decoded subject. (Closes #672) * Don't RFC 2047 encode display names in UserNotifications. Allow sending utf-8 encoded notifications. (Closes #673) +* Don't replace non-ascii in subjects in notifications. (Closes #673) Command line View it on GitLab: https://gitlab.com/mailman/mailman/-/compare/8354d0a60cc45f6bc706d60036cb2b772f526dba...47a4f235f61ec27dd49bc04df39374a25fd1022e -- View it on GitLab: https://gitlab.com/mailman/mailman/-/compare/8354d0a60cc45f6bc706d60036cb2b772f526dba...47a4f235f61ec27dd49bc04df39374a25fd1022e You're receiving this email because of your account on gitlab.com.
_______________________________________________ Mailman-checkins mailing list -- mailman-checkins@python.org To unsubscribe send an email to mailman-checkins-le...@python.org https://mail.python.org/mailman3/lists/mailman-checkins.python.org/ Member address: arch...@jab.org