This commit is contained in:
jedi 2024-05-04 01:03:51 +02:00
parent a2dd06f2f9
commit 9074309f01
3 changed files with 13 additions and 7 deletions

View file

@ -166,7 +166,7 @@ def parse_email_body(raw, log=None):
body = body + f'<img src="cid:{attachment.id}">'
log.info("Image %s %s", ctype, attachment.id)
else:
log.info("Attachment %s %s" % (ctype, cdispo))
log.info("Attachment %s %s", ctype, cdispo)
else:
if parsed.get_content_type() == 'text/plain':
body = parsed.get_payload()
@ -292,5 +292,5 @@ class LMTPHandler:
random_filename = 'mail-' + str(uuid.uuid4())
with open(random_filename, 'wb') as f:
f.write(content)
log.error(type(e), e, f"Saved email to {random_filename}")
log.error(f"Saved email to {random_filename} because of error %s (%s)", e, type(e))
return '451 Internal server error'

View file

@ -6,7 +6,7 @@ from urllib.parse import quote as urlencode
from core.settings import TELEGRAM_BOT_TOKEN, TELEGRAM_GROUP_CHAT_ID
from mail.protocol import send_smtp, make_notification
from notifications.models import UserNotificationChannel
from notifications.templates import render_notification_new_ticket, render_notification_reply_ticket
from notifications.templates import render_notification_new_ticket_async, render_notification_reply_ticket_async
from tickets.models import IssueThread
@ -64,7 +64,8 @@ class NotificationDispatcher:
print("Error: Invalid message format")
async def dispatch(self, ticket, event_id, new):
message = render_notification_new_ticket(ticket) if new else await render_notification_reply_ticket(ticket)
message = await render_notification_new_ticket_async(
ticket) if new else await render_notification_reply_ticket_async(ticket)
print("Dispatching message:", message, "with event_id:", event_id)
targets = await self.get_notification_targets()
# await telegram_notify(message, TELEGRAM_GROUP_CHAT_ID)

View file

@ -37,22 +37,27 @@ def render_template(template, **kwargs):
return None
@database_sync_to_async
def render_auto_reply(ticket):
eventslug = ticket.event.slug if ticket.event else "37C3" # TODO 37C3 should not be hardcoded
return render_template('auto_reply', ticket_name=ticket.name, ticket_uuid=ticket.short_uuid(),
ticket_id=ticket.id, event_slug=eventslug, ticket_url=ticket_url(ticket))
@database_sync_to_async
def render_notification_new_ticket(ticket):
eventslug = ticket.event.slug if ticket.event else "37C3" # TODO 37C3 should not be hardcoded
return render_template('new_issue_notification', ticket_name=ticket.name, ticket_uuid=ticket.short_uuid(),
ticket_id=ticket.id, event_slug=eventslug, ticket_url=ticket_url(ticket))
@database_sync_to_async
async def render_notification_new_ticket_async(ticket):
return await database_sync_to_async(render_notification_new_ticket)(ticket)
def render_notification_reply_ticket(ticket):
eventslug = ticket.event.slug if ticket.event else "37C3" # TODO 37C3 should not be hardcoded
return render_template('reply_issue_notification', ticket_name=ticket.name, ticket_uuid=ticket.short_uuid(),
ticket_id=ticket.id, event_slug=eventslug, ticket_url=ticket_url(ticket))
async def render_notification_reply_ticket_async(ticket):
return await database_sync_to_async(render_notification_reply_ticket)(ticket)