This commit is contained in:
j3d1 2024-05-02 22:37:34 +02:00
parent 857af74bd5
commit 059ded15a1
3 changed files with 28 additions and 8 deletions

14
core/.coveragerc Normal file
View file

@ -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

View file

@ -5,6 +5,7 @@ from urllib.parse import quote as urlencode
from core.settings import TELEGRAM_BOT_TOKEN, TELEGRAM_GROUP_CHAT_ID from core.settings import TELEGRAM_BOT_TOKEN, TELEGRAM_GROUP_CHAT_ID
from mail.models import UserNotificationChannel from mail.models import UserNotificationChannel
from mail.protocol import send_smtp, make_notification
async def http_get(url): async def http_get(url):
@ -19,6 +20,11 @@ async def telegram_notify(message, chat_id):
return await http_get(url) return await http_get(url)
async def email_notify(message, email):
mail = await make_notification(message, email)
await send_smtp(mail)
class NotificationDispatcher: class NotificationDispatcher:
channel_layer = None channel_layer = None
room_group_name = "general" room_group_name = "general"
@ -58,6 +64,6 @@ class NotificationDispatcher:
if target.channel_type == 'telegram': if target.channel_type == 'telegram':
await telegram_notify(message, target.channel_target) await telegram_notify(message, target.channel_target)
elif target.channel_type == 'email': elif target.channel_type == 'email':
print("Sending mail to:", target.channel_target) await email_notify(message, target.channel_target)
else: else:
print("Unknown channel type:", target.channel_type) print("Unknown channel type:", target.channel_type)

View file

@ -198,13 +198,13 @@ def receive_email(envelope, log=None):
header_in_reply_to = parsed.get('In-Reply-To') header_in_reply_to = parsed.get('In-Reply-To')
header_message_id = parsed.get('Message-ID') header_message_id = parsed.get('Message-ID')
if header_from != envelope.mail_from: #if header_from != envelope.mail_from:
log.warning("Header from does not match envelope from") # log.warning("Header from does not match envelope from")
log.info(f"Header from: {header_from}, envelope from: {envelope.mail_from}") # log.info(f"Header from: {header_from}, envelope from: {envelope.mail_from}")
#
if header_to != envelope.rcpt_tos[0]: #if header_to != envelope.rcpt_tos[0]:
log.warning("Header to does not match envelope to") # log.warning("Header to does not match envelope to")
log.info(f"Header to: {header_to}, envelope to: {envelope.rcpt_tos[0]}") # 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() 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 sender = envelope.mail_from if envelope.mail_from else header_from