From 353e0568c4125f32d5d33e6afcea69a4b65b5802 Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Wed, 21 Aug 2019 00:48:46 +0300 Subject: [PATCH] ndl: improve emails --- tools/nv-driver-locator/nv-driver-locator.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/nv-driver-locator/nv-driver-locator.py b/tools/nv-driver-locator/nv-driver-locator.py index 7c9470f..9347306 100755 --- a/tools/nv-driver-locator/nv-driver-locator.py +++ b/tools/nv-driver-locator/nv-driver-locator.py @@ -97,6 +97,7 @@ class EmailNotifier(BaseNotifier): 'email.mime.multipart').MIMEMultipart self._MIMEBase = importlib.import_module('email.mime.base').MIMEBase self._encoders = importlib.import_module('email.encoders') + self._mimeheader = importlib.import_module('email.header').Header self._m = self._Mailer(from_addr=from_addr, host=host, port=port, @@ -110,13 +111,16 @@ class EmailNotifier(BaseNotifier): def notify(self, obj): msg = self._MIMEMult() - msg['Subject'] = "New Nvidia driver available!" + msg['Subject'] = self._mimeheader("New Nvidia driver available!", "utf-8") msg['From'] = self._from_addr msg['To'] = ', '.join(self._to_addrs) - body = "See attached JSON" - msg.attach(self._MIMEText(body, 'plain')) + obj_text = json.dumps(obj, indent=4, ensure_ascii=False) + msg_text = json.dumps(obj, indent=4, ensure_ascii=True) + body = "See attached JSON or message body below:\n" + body += msg_text + msg.attach(self._MIMEText(body, 'plain', 'utf-8')) p = self._MIMEBase('application', 'octet-stream') - p.set_payload(json.dumps(obj, indent=4).encode('utf-8')) + p.set_payload(obj_text.encode('ascii')) self._encoders.encode_base64(p) p.add_header('Content-Disposition', "attachment; filename=obj.json") msg.attach(p)