Add In-Reply-To header to notification emails

We add a Message-ID header to the notification email about new ticket,
the value of ticket's mailing list is used. For other notifications, we
insert an In-Reply-To header with the same value. This implements "flat
replies" as described in https://todo.sr.ht/~sircmpwn/todo.sr.ht/97.

Closes https://todo.sr.ht/~sircmpwn/todo.sr.ht/97
This commit is contained in:
Denis Laxalde 2019-09-10 22:41:07 +02:00 committed by Drew DeVault
parent 4d5126cfc7
commit 23067adce5
4 changed files with 20 additions and 0 deletions

View File

@ -25,6 +25,9 @@ def test_assignment(mailbox):
assert mailbox[0].subject == "~foo/bar#1: Hilfe!"
assert mailbox[0].body.startswith(
"You were assigned to ~foo/bar#1 by ~assigner")
assert mailbox[0].headers["In-Reply-To"] == (
f'<~{tracker.owner.username}/{tracker.name}/{ticket.scoped_id}@example.org>'
)
# Assignment is idempotent
assign(ticket, assignee1, assigner)
@ -40,6 +43,9 @@ def test_assignment(mailbox):
assert mailbox[1].subject == "~foo/bar#1: Hilfe!"
assert mailbox[1].body.startswith(
"You were assigned to ~foo/bar#1 by ~assigner")
assert mailbox[1].headers["In-Reply-To"] == (
f'<~{tracker.owner.username}/{tracker.name}/{ticket.scoped_id}@example.org>'
)
unassign(ticket, assignee1, assigner)
db.session.commit()

View File

@ -45,6 +45,9 @@ def test_ticket_comment(mailbox):
assert e.headers['From'].startswith(submitter.name)
if starts_with:
assert e.body.startswith(starts_with)
assert e.headers["In-Reply-To"] == (
f'<~{tracker.owner.username}/{tracker.name}/{ticket.scoped_id}@example.org>'
)
def assert_event_notifications_created(event):
assert {en.user.email for en in event.notifications} == {

View File

@ -52,6 +52,9 @@ def test_submit_ticket(client, mailbox, submitter_subscribed):
assert description in email.body
assert ticket_url(ticket) in email.body
assert email.headers['From'].startswith(submitter.name)
assert email.headers['Message-ID'] == (
f'<~{tracker.owner.username}/{tracker.name}/1@example.org>'
)
# Check event notification is created for the subscriber
assert len(subscriber.user.notifications) == 1
@ -149,3 +152,7 @@ def test_mentions_in_ticket_description(mailbox):
expected = f"You were mentioned in {ticket.ref()} by {submitter.name}."
assert p1_email.body.startswith(expected)
assert p2_email.body.startswith(expected)
assert p2_email.headers["In-Reply-To"] == (
f'<~{tracker.owner.username}/{tracker.name}/{ticket.scoped_id}@example.org>'
)

View File

@ -170,6 +170,7 @@ def _send_comment_notification(subscription, ticket,
subject = "Re: {}: {}".format(ticket.ref(), ticket.title)
headers = {
"From": "{} <{}>".format(participant.name, notify_from),
"In-Reply-To": f"<{ticket.ref(email=True)}@{posting_domain}>",
"Reply-To": f"{ticket.ref()} <{ticket.ref(email=True)}@{posting_domain}>",
"Sender": smtp_user,
}
@ -231,6 +232,7 @@ def _send_mention_notification(sub, submitter, text, ticket, comment=None):
subject = "{}: {}".format(ticket.ref(), ticket.title)
headers = {
"From": "{} <{}>".format(submitter.name, notify_from),
"In-Reply-To": f"<{ticket.ref(email=True)}@{posting_domain}>",
"Reply-To": f"{ticket.ref()} <{ticket.ref(email=True)}@{posting_domain}>",
"Sender": smtp_user,
}
@ -350,6 +352,7 @@ def notify_assignee(subscription, ticket, assigner, assignee):
subject = "{}: {}".format(ticket.ref(), ticket.title)
headers = {
"From": "~{} <{}>".format(assigner.username, notify_from),
"In-Reply-To": f"<{ticket.ref(email=True)}@{posting_domain}>",
"Reply-To": f"{ticket.ref()} <{ticket.ref(email=True)}@{posting_domain}>",
"Sender": smtp_user,
}
@ -434,6 +437,7 @@ def _send_new_ticket_notification(subscription, ticket):
subject = f"{ticket.ref()}: {ticket.title}"
headers = {
"From": "{} <{}>".format(ticket.submitter.name, notify_from),
"Message-ID": f"<{ticket.ref(email=True)}@{posting_domain}>",
"Reply-To": f"{ticket.ref()} <{ticket.ref(email=True)}@{posting_domain}>",
"Sender": smtp_user,
}