From a39802b5bf88276cee61931dfd3e697cb2d29be5 Mon Sep 17 00:00:00 2001 From: jedi Date: Thu, 2 May 2024 22:37:34 +0200 Subject: [PATCH] stash --- core/.coveragerc | 14 ++++++++++++++ core/mail/notifications.py | 8 +++++++- core/mail/protocol.py | 14 +++++++------- 3 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 core/.coveragerc diff --git a/core/.coveragerc b/core/.coveragerc new file mode 100644 index 0000000..14c1fba --- /dev/null +++ b/core/.coveragerc @@ -0,0 +1,14 @@ +[run] +source = . + +[report] +fail_under = 100 +show_missing = True +skip_covered = True +omit = + */tests/* + */migrations/* + core/asgi.py + core/wsgi.py + core/settings.py + manage.py \ No newline at end of file diff --git a/core/mail/notifications.py b/core/mail/notifications.py index a279873..082183d 100644 --- a/core/mail/notifications.py +++ b/core/mail/notifications.py @@ -5,6 +5,7 @@ from urllib.parse import quote as urlencode from core.settings import TELEGRAM_BOT_TOKEN, TELEGRAM_GROUP_CHAT_ID from mail.models import UserNotificationChannel +from mail.protocol import send_smtp, make_notification async def http_get(url): @@ -19,6 +20,11 @@ async def telegram_notify(message, chat_id): return await http_get(url) +async def email_notify(message, email): + mail = await make_notification(message, email) + await send_smtp(mail) + + class NotificationDispatcher: channel_layer = None room_group_name = "general" @@ -58,6 +64,6 @@ class NotificationDispatcher: if target.channel_type == 'telegram': await telegram_notify(message, target.channel_target) elif target.channel_type == 'email': - print("Sending mail to:", target.channel_target) + await email_notify(message, target.channel_target) else: print("Unknown channel type:", target.channel_type) diff --git a/core/mail/protocol.py b/core/mail/protocol.py index 2ea7b2c..2d80e3b 100644 --- a/core/mail/protocol.py +++ b/core/mail/protocol.py @@ -198,13 +198,13 @@ def receive_email(envelope, log=None): header_in_reply_to = parsed.get('In-Reply-To') header_message_id = parsed.get('Message-ID') - if header_from != envelope.mail_from: - log.warning("Header from does not match envelope from") - log.info(f"Header from: {header_from}, envelope from: {envelope.mail_from}") - - if header_to != envelope.rcpt_tos[0]: - log.warning("Header to does not match envelope to") - log.info(f"Header to: {header_to}, envelope to: {envelope.rcpt_tos[0]}") + #if header_from != envelope.mail_from: + # log.warning("Header from does not match envelope from") + # log.info(f"Header from: {header_from}, envelope from: {envelope.mail_from}") +# + #if header_to != envelope.rcpt_tos[0]: + # log.warning("Header to does not match envelope to") + # log.info(f"Header to: {header_to}, envelope to: {envelope.rcpt_tos[0]}") recipient = envelope.rcpt_tos[0].lower() if envelope.rcpt_tos else header_to.lower() sender = envelope.mail_from if envelope.mail_from else header_from