summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Tartaglia <me@andreatartaglia.com>2017-09-11 07:39:23 -0700
committerBrian Coca <bcoca@users.noreply.github.com>2017-09-11 10:39:23 -0400
commitb9de989ad4cdf9b347f8da2cd1e15792fc2a45f7 (patch)
tree5a2e041322631cb3671426d39b61abbad19fbd4d
parente5d247fdc0d7595b395eb1bc9629600d32ad5a8a (diff)
downloadansible-b9de989ad4cdf9b347f8da2cd1e15792fc2a45f7.tar.gz
Fix mail module headers encoding (#29109)
* Fixes encoding issue in Subject line * Use Header to correctly set header charset
-rw-r--r--lib/ansible/modules/notification/mail.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/ansible/modules/notification/mail.py b/lib/ansible/modules/notification/mail.py
index 8856b31819..29a955a160 100644
--- a/lib/ansible/modules/notification/mail.py
+++ b/lib/ansible/modules/notification/mail.py
@@ -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