From 4d70590d0501ede2176a8e72ff5ddafcc84091b4 Mon Sep 17 00:00:00 2001
From: MrMeeb
Date: Wed, 1 Mar 2023 12:00:06 +0000
Subject: [PATCH] 4.22.3
---
app/.pre-commit-config.yaml | 1 +
app/app/mail_sender.py | 12 ++++--
app/app/message_utils.py | 25 +++++++++++-
.../dashboard/alias_contact_manager.html | 4 +-
app/templates/dashboard/custom_domain.html | 4 +-
.../dashboard/domain_detail/auto-create.html | 2 +-
.../dashboard/domain_detail/dns.html | 6 +--
app/templates/dashboard/pricing.html | 8 ++--
app/templates/dashboard/refused_email.html | 6 ++-
app/templates/dashboard/setting.html | 3 +-
app/templates/dashboard/subdomain.html | 2 +-
.../developer/client_details/base.html | 1 +
.../developer/client_details/basic_info.html | 4 +-
app/templates/developer/index.html | 1 +
app/templates/discover/index.html | 4 +-
app/templates/emails/_emailhelpers.html | 2 +-
app/templates/footer.html | 14 +++----
app/templates/header.html | 11 ++++--
app/templates/menu.html | 7 +++-
app/tests/example_emls/bad_base64format.eml | 39 +++++++++++++++++++
app/tests/test_message_utils.py | 13 ++++++-
21 files changed, 133 insertions(+), 36 deletions(-)
create mode 100644 app/tests/example_emls/bad_base64format.eml
diff --git a/app/.pre-commit-config.yaml b/app/.pre-commit-config.yaml
index 60c43ee..2da4462 100644
--- a/app/.pre-commit-config.yaml
+++ b/app/.pre-commit-config.yaml
@@ -21,3 +21,4 @@ repos:
- id: djlint-jinja
files: '.*\.html'
entry: djlint --reformat
+
diff --git a/app/app/mail_sender.py b/app/app/mail_sender.py
index 2705ddd..dd143d7 100644
--- a/app/app/mail_sender.py
+++ b/app/app/mail_sender.py
@@ -17,7 +17,7 @@ from attr import dataclass
from app import config
from app.email import headers
from app.log import LOG
-from app.message_utils import message_to_bytes
+from app.message_utils import message_to_bytes, message_format_base64_parts
@dataclass
@@ -173,8 +173,12 @@ class MailSender:
self._save_request_to_unsent_dir(send_request)
return False
- def _save_request_to_unsent_dir(self, send_request: SendRequest):
- file_name = f"DeliveryFail-{int(time.time())}-{uuid.uuid4()}.{SendRequest.SAVE_EXTENSION}"
+ def _save_request_to_unsent_dir(
+ self, send_request: SendRequest, prefix: str = "DeliveryFail"
+ ):
+ file_name = (
+ f"{prefix}-{int(time.time())}-{uuid.uuid4()}.{SendRequest.SAVE_EXTENSION}"
+ )
file_path = os.path.join(config.SAVE_UNSENT_DIR, file_name)
file_contents = send_request.to_bytes()
with open(file_path, "wb") as fd:
@@ -256,7 +260,7 @@ def sl_sendmail(
send_request = SendRequest(
envelope_from,
envelope_to,
- msg,
+ message_format_base64_parts(msg),
mail_options,
rcpt_options,
is_forward,
diff --git a/app/app/message_utils.py b/app/app/message_utils.py
index a5a199b..34f57d4 100644
--- a/app/app/message_utils.py
+++ b/app/app/message_utils.py
@@ -1,21 +1,42 @@
+import re
from email import policy
from email.message import Message
+from app.email import headers
from app.log import LOG
+# Spam assassin might flag as spam with a different line length
+BASE64_LINELENGTH = 76
+
def message_to_bytes(msg: Message) -> bytes:
"""replace Message.as_bytes() method by trying different policies"""
for generator_policy in [None, policy.SMTP, policy.SMTPUTF8]:
try:
return msg.as_bytes(policy=generator_policy)
- except:
+ except Exception:
LOG.w("as_bytes() fails with %s policy", policy, exc_info=True)
msg_string = msg.as_string()
try:
return msg_string.encode()
- except:
+ except Exception:
LOG.w("as_string().encode() fails", exc_info=True)
return msg_string.encode(errors="replace")
+
+
+def message_format_base64_parts(msg: Message) -> Message:
+ for part in msg.walk():
+ if part.get(
+ headers.CONTENT_TRANSFER_ENCODING
+ ) == "base64" and part.get_content_type() in ("text/plain", "text/html"):
+ # Remove line breaks
+ body = re.sub("[\r\n]", "", part.get_payload())
+ # Split in 80 column lines
+ chunks = [
+ body[i : i + BASE64_LINELENGTH]
+ for i in range(0, len(body), BASE64_LINELENGTH)
+ ]
+ part.set_payload("\r\n".join(chunks))
+ return msg
diff --git a/app/templates/dashboard/alias_contact_manager.html b/app/templates/dashboard/alias_contact_manager.html
index a1fff07..a9b355d 100644
--- a/app/templates/dashboard/alias_contact_manager.html
+++ b/app/templates/dashboard/alias_contact_manager.html
@@ -50,7 +50,9 @@
This Youtube video can also quickly walk you through the steps:
-
+
How to send emails from an alias
diff --git a/app/templates/dashboard/custom_domain.html b/app/templates/dashboard/custom_domain.html
index b967f77..324b291 100644
--- a/app/templates/dashboard/custom_domain.html
+++ b/app/templates/dashboard/custom_domain.html
@@ -23,7 +23,9 @@
This feature is only available on Premium plan.
-
+
Upgrade
diff --git a/app/templates/dashboard/domain_detail/auto-create.html b/app/templates/dashboard/domain_detail/auto-create.html
index 1ad9a08..87f3e66 100644
--- a/app/templates/dashboard/domain_detail/auto-create.html
+++ b/app/templates/dashboard/domain_detail/auto-create.html
@@ -78,7 +78,7 @@
data-clipboard-text=".*suffix">.*suffix
To test out regex, we recommend using regex tester tool like
- https://regex101.com↗
+ https://regex101.com↗