1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix mail module headers encoding (#29109)

* Fixes encoding issue in Subject line

* Use Header to correctly set header charset
This commit is contained in:
Andrea Tartaglia 2017-09-11 07:39:23 -07:00 committed by Brian Coca
parent e5d247fdc0
commit b9de989ad4

View file

@ -199,6 +199,7 @@ from email.utils import parseaddr, formataddr
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.header import Header
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
@ -310,14 +311,16 @@ def main():
module.fail_json(rc=1, msg="No Authentication on the server at %s:%s" % (host, port))
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = formataddr((sender_phrase, sender_addr))
msg['Subject'] = Header(subject, charset)
msg['From'] = Header(formataddr((sender_phrase, sender_addr)), charset)
msg.preamble = "Multipart message"
msg.set_charset(charset)
if headers is not None:
for hdr in [x.strip() for x in headers.split('|')]:
try:
h_key, h_val = hdr.split('=')
h_val = to_native(Header(h_val, charset))
msg.add_header(h_key, h_val)
except:
pass