Skip to content

Commit 9241e72

Browse files
Fixed encoding issue on Python 3 for some mail servers. [master] (#1607)
Fixed encoding issue on Python 3 for some mail servers. This could result in missing characters in an email body. See plone/Products.CMFPlone#3754 Co-authored-by: Timo Stollenwerk <[email protected]>
1 parent c1bed73 commit 9241e72

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

news/3754.bugfix

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed encoding issue on Python 3 for some mail servers.
2+
This could result in missing characters in an email body.
3+
[maurits]

src/plone/restapi/services/email_send/post.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from AccessControl import getSecurityManager
22
from AccessControl.Permissions import use_mailhost_services
3-
from email.mime.text import MIMEText
43
from plone.registry.interfaces import IRegistry
54
from plone.restapi import _
65
from plone.restapi.bbb import IMailSchema
@@ -15,6 +14,14 @@
1514

1615
import plone
1716

17+
try:
18+
# Products.MailHost has a patch to fix quoted-printable soft line breaks.
19+
# See https://github.com/zopefoundation/Products.MailHost/issues/35
20+
from Products.MailHost.MailHost import message_from_string
21+
except ImportError:
22+
# If the patch is ever removed, we fall back to the standard library.
23+
from email import message_from_string
24+
1825

1926
class EmailSendPost(Service):
2027
def reply(self):
@@ -99,7 +106,7 @@ def reply(self):
99106

100107
message = f"{message_intro} \n {message}"
101108

102-
message = MIMEText(message, "plain", encoding)
109+
message = message_from_string(message)
103110
message["Reply-To"] = sender_from_address
104111
try:
105112
host.send(

0 commit comments

Comments
 (0)