stash
This commit is contained in:
parent
dbbd63ab1e
commit
d9d4d5092f
2 changed files with 21 additions and 16 deletions
|
@ -212,7 +212,7 @@ def receive_email(envelope, log=None):
|
|||
|
||||
# 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")
|
||||
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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue