From e5da6157190fb6761688a8313ba06f318ace2821 Mon Sep 17 00:00:00 2001
From: Emmanuel Ormancey <emmanuel.ormancey@cern.ch>
Date: Wed, 30 Jun 2021 16:08:32 +0200
Subject: [PATCH] Added new smimesmtp backend

---
 .env                                     | 6 +++---
 notifications_consumer/config.py         | 2 +-
 vendor/django_mail/backends/smimesmtp.py | 5 ++---
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/.env b/.env
index ee716e3..3501355 100644
--- a/.env
+++ b/.env
@@ -32,7 +32,7 @@ CERN_OIDC_CLIENT_SECRET=fill-me
 EMAIL_AES_SECRET_KEY=fill-mefill-mefill-mefill-mefill
 
 # SMIME signed emails
-EMAIL_BACKEND=vendor.django_mail.backends.smimesmtp.EmailBackend
-EMAIL_SMIME_CERT_FILE_PATH=/etc/notifications-noreply.pem
-EMAIL_SMIME_CERT_KEY_FILE_PATH=/etc/notifications-noreply-key.pem
+#EMAIL_BACKEND=vendor.django_mail.backends.smimesmtp.EmailBackend
+#EMAIL_SMIME_CERT_FILE_PATH=/etc/notifications-noreply.pem
+#EMAIL_SMIME_CERT_KEY_FILE_PATH=/etc/notifications-noreply-key.pem
 
diff --git a/notifications_consumer/config.py b/notifications_consumer/config.py
index ee74764..3b9b4aa 100644
--- a/notifications_consumer/config.py
+++ b/notifications_consumer/config.py
@@ -59,7 +59,7 @@ class Config:
     EMAIL_SMIME_CERT_FILE_PATH = os.getenv("EMAIL_SMIME_CERT_FILE_PATH")
     EMAIL_SMIME_CERT_KEY_FILE_PATH = os.getenv("EMAIL_SMIME_CERT_KEY_FILE_PATH")
 
-    NOREPLY_ADDRESS = os.getenv("NOREPLY_ADDRESS", "noreply@cern.ch")
+    NOREPLY_ADDRESS = os.getenv("NOREPLY_ADDRESS", "notifications-noreply@cern.ch")
 
     EMAIL_RECIPIENT_REGEX = r"^(.*?)\+(.*?)\+(.*?)$"
     EMAIL_RECIPIENT_PATTERN = re.compile(EMAIL_RECIPIENT_REGEX)
diff --git a/vendor/django_mail/backends/smimesmtp.py b/vendor/django_mail/backends/smimesmtp.py
index 02d6f94..ddebfce 100644
--- a/vendor/django_mail/backends/smimesmtp.py
+++ b/vendor/django_mail/backends/smimesmtp.py
@@ -162,10 +162,9 @@ class EmailBackend(BaseEmailBackend):
 
         try:
             self.connection.sendmail(
-                from_email, 
+                from_email,
                 recipients,
-                # Ugly fix for obscure boundary with newline when using SafeMIMEMultipart
-                signed_message.as_string().replace('\n', '\r\n').replace('; boundary', ';\r\n boundary') 
+                signed_message.as_string()
             )
         except smtplib.SMTPException:
             if not self.fail_silently:
-- 
GitLab