diff mbox series

[AUH,1/2] emailhandler: correctly send binary attachments

Message ID 20220719105052.638381-1-alex@linutronix.de
State New
Headers show
Series [AUH,1/2] emailhandler: correctly send binary attachments | expand

Commit Message

Alexander Kanavin July 19, 2022, 10:50 a.m. UTC
MIMEBase should not be used directly and results in
sending raw binary data without encoding it with base64.

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
---
 modules/utils/emailhandler.py | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/modules/utils/emailhandler.py b/modules/utils/emailhandler.py
index 8c8b85b..1ed4bfc 100644
--- a/modules/utils/emailhandler.py
+++ b/modules/utils/emailhandler.py
@@ -30,7 +30,7 @@  from logging import info as I
 from smtplib import SMTP
 import mimetypes
 from email.mime.text import MIMEText
-from email.mime.base import MIMEBase
+from email.mime.application import MIMEApplication
 from email.mime.multipart import MIMEMultipart
 from email.generator import Generator
 import shutil
@@ -89,8 +89,7 @@  class Email(object):
             if maintype == "text":
                 attachment = MIMEText(open(file).read(), _subtype=subtype)
             else:
-                attachment = MIMEBase(maintype, _subtype=subtype)
-                attachment.set_payload(open(file, 'rb').read())
+                attachment = MIMEApplication(open(file, 'rb').read(), _subtype=subtype)
 
             attachment.add_header('Content-Disposition', 'attachment; filename="%s"'
                                   % os.path.basename(file))
@@ -108,4 +107,3 @@  class Email(object):
             smtp.close()
         except Exception as e:
             E("Could not send email: %s" % str(e))
-