Commit 28d9f006 authored by medmunds's avatar medmunds
Browse files

Use email.policy.default in Python 3 implementation

Improves standards compatibility and utf-8 handling
in Python 3.3-3.8. (email.policy.default becomes the
default in Python 3.9.)
parent 8f688e5e
...@@ -285,8 +285,11 @@ _smtp_send_python() { ...@@ -285,8 +285,11 @@ _smtp_send_python() {
try: try:
try: try:
from email.message import EmailMessage from email.message import EmailMessage
from email.policy import default as email_policy_default
except ImportError: except ImportError:
from email.mime.text import MIMEText as EmailMessage # Python 2 # Python 2 (or < 3.3)
from email.mime.text import MIMEText as EmailMessage
email_policy_default = None
from email.utils import formatdate as rfc2822_date from email.utils import formatdate as rfc2822_date
from smtplib import SMTP, SMTP_SSL, SMTPException from smtplib import SMTP, SMTP_SSL, SMTPException
from socket import error as SocketError from socket import error as SocketError
...@@ -311,7 +314,7 @@ subject="""$SMTP_SUBJECT""" ...@@ -311,7 +314,7 @@ subject="""$SMTP_SUBJECT"""
content="""$SMTP_CONTENT""" content="""$SMTP_CONTENT"""
try: try:
msg = EmailMessage() msg = EmailMessage(policy=email_policy_default)
msg.set_content(content) msg.set_content(content)
except (AttributeError, TypeError): except (AttributeError, TypeError):
# Python 2 MIMEText # Python 2 MIMEText
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment