Skip to content

Commit

Permalink
Fixed encoding issue on Python 3 for some mail servers. [master] (#1607)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mauritsvanrees and tisto authored Apr 7, 2023
1 parent c1bed73 commit 9241e72
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions news/3754.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed encoding issue on Python 3 for some mail servers.
This could result in missing characters in an email body.
[maurits]
11 changes: 9 additions & 2 deletions src/plone/restapi/services/email_send/post.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from AccessControl import getSecurityManager
from AccessControl.Permissions import use_mailhost_services
from email.mime.text import MIMEText
from plone.registry.interfaces import IRegistry
from plone.restapi import _
from plone.restapi.bbb import IMailSchema
Expand All @@ -15,6 +14,14 @@

import plone

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


class EmailSendPost(Service):
def reply(self):
Expand Down Expand Up @@ -99,7 +106,7 @@ def reply(self):

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

message = MIMEText(message, "plain", encoding)
message = message_from_string(message)
message["Reply-To"] = sender_from_address
try:
host.send(
Expand Down

0 comments on commit 9241e72

Please sign in to comment.