From cfdbcc8ee1f9eb54cc932d74d07d323e3b85c63e Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 7 Mar 2023 23:59:42 +0100 Subject: [PATCH] =?UTF-8?q?Omezen=C3=AD=20na=20po=C4=8Det=20adres=20v=20hl?= =?UTF-8?q?avi=C4=8Dce=20mail=C5=AF=20z=20testwebu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Není úplně žádoucí, aby se v mailu z testwebu poslala spousta adres, protože je to náchylné na automatické zpracování v případě, že se k takovému mailu dostane někdo další. --- various/mail_prefixer.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/various/mail_prefixer.py b/various/mail_prefixer.py index 14d4386b..2af0b3f7 100644 --- a/various/mail_prefixer.py +++ b/various/mail_prefixer.py @@ -7,6 +7,11 @@ Used to distinguish testing emails from production ones.""" from django.core.mail.backends.smtp import EmailBackend as DjangoSMTPBackend from django.conf import settings +def omezovatko_poctu_mailu(maily:list, maximum:int) -> str: + if len(maily) <= maximum: return str(maily) + # Aspoň zhruba simulujeme tisk pole… + return '[' + ", ".join(f"'{mail}'" for mail in maily[:maximum - 1]) + f', … ({len(maily)} e-mailů) ]' + class PrefixingMailBackend(DjangoSMTPBackend): # method _send is not probably meant to be monkey_patched, so we patch send_messages instead. def send_messages(self, messages): @@ -16,10 +21,13 @@ class PrefixingMailBackend(DjangoSMTPBackend): if message.from_email != settings.SERVER_EMAIL: message.subject = prefix + ' ' + message.subject + to = omezovatko_poctu_mailu(message.to, 3) + cc = omezovatko_poctu_mailu(message.cc, 3) + bcc = omezovatko_poctu_mailu(message.bcc, 3) message.body = f"""Bylo by posláno na e-maily: - To: {message.to} - Cc: {message.cc} - Bcc: {message.bcc} + To: {to} + Cc: {cc} + Bcc: {bcc} """+ "\n\n" + message.body message.to = settings.TESTOVACI_EMAILOVA_KONFERENCE message.cc = []