This commit is contained in:
j3d1 2024-05-04 02:49:36 +02:00
parent d7a383f1e7
commit 42509388bd
2 changed files with 21 additions and 16 deletions

View file

@ -212,7 +212,7 @@ def receive_email(envelope, log=None):
# handle undelivered mail header_from : 'Mail Delivery System <MAILER-DAEMON@...' # handle undelivered mail header_from : 'Mail Delivery System <MAILER-DAEMON@...'
if match(r'^[a-zA-Z ]*<?MAILER-DAEMON@', header_from) and envelope.mail_from.strip("<>") == "": if match(r'^([a-zA-Z ]*<)?MAILER-DAEMON@', header_from) and envelope.mail_from.strip("<>") == "":
log.warning("Ignoring mailer daemon") log.warning("Ignoring mailer daemon")
raise SpecialMailException("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, 'general', {"type": "generic.event", "name": "send_message_to_frontend", "event_id": systemevent.id,
"message": "email received"}) "message": "email received"})
log.info(f"Sent message to frontend") 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: if new and reply:
log.info('Sending message to %s' % reply['To']) log.info('Sending message to %s' % reply['To'])
await send_smtp(reply) await send_smtp(reply)
log.info("Sent auto 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' return '250 Message accepted for delivery'
except SpecialMailException as e: except SpecialMailException as e:
import uuid import uuid
random_filename = 'special-' + str(uuid.uuid4()) random_filename = 'special-' + str(uuid.uuid4())
with open(random_filename, 'wb') as f: with open(random_filename, 'wb') as f:
f.write(content) 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' return '250 Message accepted for delivery'
except Exception as e: except Exception as e:
from hashlib import sha256 from hashlib import sha256

View file

@ -22,8 +22,8 @@ async def telegram_notify(message, chat_id):
return await http_get(url) return await http_get(url)
async def email_notify(message, email): async def email_notify(message, title, email):
mail = make_notification(message, email) mail = make_notification(message, email, title)
await send_smtp(mail) await send_smtp(mail)
@ -66,6 +66,7 @@ class NotificationDispatcher:
async def dispatch(self, ticket, event_id, new): async def dispatch(self, ticket, event_id, new):
message = await render_notification_new_ticket_async( message = await render_notification_new_ticket_async(
ticket) if new else await render_notification_reply_ticket_async(ticket) 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) print("Dispatching message:", message, "with event_id:", event_id)
targets = await self.get_notification_targets() targets = await self.get_notification_targets()
# await telegram_notify(message, TELEGRAM_GROUP_CHAT_ID) # await telegram_notify(message, TELEGRAM_GROUP_CHAT_ID)
@ -75,6 +76,6 @@ class NotificationDispatcher:
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 email notification to:", target.channel_target) print("Sending email notification to:", target.channel_target)
await email_notify(message, target.channel_target) await email_notify(message, title, target.channel_target)
else: else:
print("Unknown channel type:", target.channel_type) print("Unknown channel type:", target.channel_type)