Include thread related headers in issue/coment mail (#7484)

* Include thread related headers in issue/coment mail

Make it so mail programs will group comments from an issue into the same
thread by setting Message-ID on initial issue and then using In-Reply-To
and References headers to reference that later on.

* Add tests

* more tests

* fix typo
This commit is contained in:
mrsdizzie
2019-07-17 15:02:42 -04:00
committed by techknowlogick
parent 5d3e351864
commit 944d904980
3 changed files with 115 additions and 1 deletions

View File

@ -156,7 +156,13 @@ func composeTplData(subject, body, link string) map[string]interface{} {
}
func composeIssueCommentMessage(issue *Issue, doer *User, content string, comment *Comment, tplName base.TplName, tos []string, info string) *mailer.Message {
subject := issue.mailSubject()
var subject string
if comment != nil {
subject = "Re: " + issue.mailSubject()
} else {
subject = issue.mailSubject()
}
err := issue.LoadRepo()
if err != nil {
log.Error("LoadRepo: %v", err)
@ -179,6 +185,15 @@ func composeIssueCommentMessage(issue *Issue, doer *User, content string, commen
msg := mailer.NewMessageFrom(tos, doer.DisplayName(), setting.MailService.FromEmail, subject, mailBody.String())
msg.Info = fmt.Sprintf("Subject: %s, %s", subject, info)
// Set Message-ID on first message so replies know what to reference
if comment == nil {
msg.SetHeader("Message-ID", "<"+issue.ReplyReference()+">")
} else {
msg.SetHeader("In-Reply-To", "<"+issue.ReplyReference()+">")
msg.SetHeader("References", "<"+issue.ReplyReference()+">")
}
return msg
}