use first mail in tickets instead of last to choose reply address. mitigates problem with shipping confirmation mails
This commit is contained in:
parent
7e3a151ead
commit
892493a300
2 changed files with 36 additions and 27 deletions
|
@ -113,15 +113,17 @@ def reply(request, pk):
|
|||
issue = IssueThread.objects.get(pk=pk)
|
||||
# email = issue.reply(request.data['body']) # TODO evaluate if this is a useful abstraction
|
||||
references = collect_references(issue)
|
||||
most_recent = Email.objects.filter(issue_thread=issue, recipient__endswith='@' + MAIL_DOMAIN).order_by(
|
||||
'-timestamp').first()
|
||||
first_mail = Email.objects.filter(issue_thread=issue, recipient__endswith='@' + MAIL_DOMAIN).order_by(
|
||||
'timestamp').first()
|
||||
if not first_mail:
|
||||
return Response({'status': 'error', 'message': 'no previous mail found, reply would not make sense.'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
mail = Email.objects.create(
|
||||
issue_thread=issue,
|
||||
sender=most_recent.recipient,
|
||||
recipient=most_recent.sender,
|
||||
subject=f'Re: {most_recent.subject}',
|
||||
sender=first_mail.recipient,
|
||||
recipient=first_mail.sender,
|
||||
subject=f'Re: {issue.name} [#{issue.short_uuid()}]',
|
||||
body=request.data['message'],
|
||||
in_reply_to=most_recent.reference,
|
||||
in_reply_to=first_mail.reference,
|
||||
)
|
||||
log = logging.getLogger('mail.log')
|
||||
async_to_sync(send_smtp)(make_reply(mail, references), log)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue