Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core


Commits:
241275cf by Mark Sapiro at 2022-07-28T23:37:16+00:00
Flatten messages as_bytes() for sending.

Fixes #1022 

This is probably not a complete fix for #1022, but it's the best we can do 
in Mailman. Any remaining issues need to be addressed in the Python email 
library.

- - - - -
c081bf75 by Mark Sapiro at 2022-07-28T23:37:16+00:00
Merge branch 'bytes' into 'master'

Flatten messages as_bytes() for sending.

Closes #1022

See merge request mailman/mailman!1026
- - - - -


3 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/mta/base.py
- src/mailman/mta/connection.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -67,6 +67,8 @@ Bugs fixed
   mail...@example.com in From: and To:.  (Closes #1018)
 * Subject prefixing on lists with non-ascii preferred language no longer drops
   parts of folded subject headers.  (Closes #1021)
+* Outgoing messages are now flattened using the as_bytes() method for better
+  RFC compliance.  (Closes #1022)
 
 REST
 ====


=====================================
src/mailman/mta/base.py
=====================================
@@ -71,7 +71,7 @@ class BaseDelivery:
         # email address for predictability and testability.
         try:
             refused = self._connection.sendmail(
-                sender, sorted(recipients), msg.as_string())
+                sender, sorted(recipients), msg.as_bytes())
         except smtplib.SMTPRecipientsRefused as error:
             log.error('%s recipients refused: %s', message_id, error)
             refused = error.recipients


=====================================
src/mailman/mta/connection.py
=====================================
@@ -130,7 +130,13 @@ class Connection:
         # smtplib.SMTP.sendmail requires the message string to be pure ascii.
         # We have seen malformed messages with non-ascii unicodes, so ensure
         # we have pure ascii.
-        msgtext = msgtext.encode('ascii', 'replace').decode('ascii')
+        # msgtext can be a string or bytes. Handle either, but the result
+        # should be a string because passing bytes to smtplib.SMTP.sendmail
+        # doesn't convert the line endings.
+        if isinstance(msgtext, str):
+            msgtext = msgtext.encode('ascii', 'replace').decode('ascii')
+        else:
+            msgtext = msgtext.decode('ascii', 'replace')
         try:
             log.debug('envsender: %s, recipients: %s, size(msgtext): %s',
                       envsender, recipients, len(msgtext))



View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/1443e1edab40aba5778a554a4baecf3fd788ca62...c081bf75f2f2ff798ac8a815aa46ed6795d2d30d

-- 
View it on GitLab: 
https://gitlab.com/mailman/mailman/-/compare/1443e1edab40aba5778a554a4baecf3fd788ca62...c081bf75f2f2ff798ac8a815aa46ed6795d2d30d
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

Reply via email to