From d9d4d5092fde65ace6db45961837fad74d443066 Mon Sep 17 00:00:00 2001 From: jedi Date: Sat, 4 May 2024 02:49:36 +0200 Subject: [PATCH] stash --- core/mail/protocol.py | 30 +++++++++++++++++------------- core/notifications/dispatch.py | 7 ++++--- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/core/mail/protocol.py b/core/mail/protocol.py index 3aa1f98..238a8af 100644 --- a/core/mail/protocol.py +++ b/core/mail/protocol.py @@ -202,17 +202,17 @@ 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]}") # handle undelivered mail header_from : 'Mail Delivery System ") == "": + if match(r'^([a-zA-Z ]*<)?MAILER-DAEMON@', header_from) and envelope.mail_from.strip("<>") == "": log.warning("Ignoring mailer daemon") raise SpecialMailException("Ignoring mailer daemon") @@ -288,22 +288,26 @@ class LMTPHandler: 'general', {"type": "generic.event", "name": "send_message_to_frontend", "event_id": systemevent.id, "message": "email received"}) log.info(f"Sent message to frontend") - if thread: - await channel_layer.group_send( - 'general', {"type": "generic.event", "name": "user_notification", "event_id": systemevent.id, - "ticket_id": thread.id, "new": new}) + if new and reply: log.info('Sending message to %s' % reply['To']) await send_smtp(reply) log.info("Sent auto reply") + if thread: + await channel_layer.group_send( + 'general', {"type": "generic.event", "name": "user_notification", "event_id": systemevent.id, + "ticket_id": thread.id, "new": new}) + else: + print("No thread found") + return '250 Message accepted for delivery' except SpecialMailException as e: import uuid random_filename = 'special-' + str(uuid.uuid4()) with open(random_filename, 'wb') as f: f.write(content) - log.warning(f"Special mail exception: {e}") + log.warning(f"Special mail exception: {e} saved to {random_filename}") return '250 Message accepted for delivery' except Exception as e: from hashlib import sha256 diff --git a/core/notifications/dispatch.py b/core/notifications/dispatch.py index b77c8ea..92c22d4 100644 --- a/core/notifications/dispatch.py +++ b/core/notifications/dispatch.py @@ -22,8 +22,8 @@ async def telegram_notify(message, chat_id): return await http_get(url) -async def email_notify(message, email): - mail = make_notification(message, email) +async def email_notify(message, title, email): + mail = make_notification(message, email, title) await send_smtp(mail) @@ -66,6 +66,7 @@ class NotificationDispatcher: async def dispatch(self, ticket, event_id, new): message = await render_notification_new_ticket_async( ticket) if new else await render_notification_reply_ticket_async(ticket) + title = f"{ticket.name} [#{ticket.short_uuid()}]" print("Dispatching message:", message, "with event_id:", event_id) targets = await self.get_notification_targets() # await telegram_notify(message, TELEGRAM_GROUP_CHAT_ID) @@ -75,6 +76,6 @@ class NotificationDispatcher: await telegram_notify(message, target.channel_target) elif target.channel_type == 'email': print("Sending email notification to:", target.channel_target) - await email_notify(message, target.channel_target) + await email_notify(message, title, target.channel_target) else: print("Unknown channel type:", target.channel_type)