forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include thread related headers in issue/coment mail (go-gitea#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
- Loading branch information
Showing
3 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright 2019 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package models | ||
|
||
import ( | ||
"html/template" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/modules/setting" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const tmpl = ` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<title>{{.Subject}}</title> | ||
</head> | ||
<body> | ||
<p>{{.Body}}</p> | ||
<p> | ||
--- | ||
<br> | ||
<a href="{{.Link}}">View it on Gitea</a>. | ||
</p> | ||
</body> | ||
</html> | ||
` | ||
|
||
func TestComposeIssueCommentMessage(t *testing.T) { | ||
assert.NoError(t, PrepareTestDatabase()) | ||
var MailService setting.Mailer | ||
|
||
MailService.From = "[email protected]" | ||
setting.MailService = &MailService | ||
|
||
doer := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) | ||
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1, Owner: doer}).(*Repository) | ||
issue := AssertExistsAndLoadBean(t, &Issue{ID: 1, Repo: repo, Poster: doer}).(*Issue) | ||
comment := AssertExistsAndLoadBean(t, &Comment{ID: 2, Issue: issue}).(*Comment) | ||
|
||
email := template.Must(template.New("issue/comment").Parse(tmpl)) | ||
InitMailRender(email) | ||
|
||
tos := []string{"[email protected]", "[email protected]"} | ||
msg := composeIssueCommentMessage(issue, doer, "test body", comment, mailIssueComment, tos, "issue comment") | ||
|
||
subject := msg.GetHeader("Subject") | ||
inreplyTo := msg.GetHeader("In-Reply-To") | ||
references := msg.GetHeader("References") | ||
|
||
assert.Equal(t, subject[0], "Re: "+issue.mailSubject(), "Comment reply subject should contain Re:") | ||
assert.Equal(t, inreplyTo[0], "<user2/repo1/issues/1@localhost>", "In-Reply-To header doesn't match") | ||
assert.Equal(t, references[0], "<user2/repo1/issues/1@localhost>", "References header doesn't match") | ||
|
||
} | ||
|
||
func TestComposeIssueMessage(t *testing.T) { | ||
assert.NoError(t, PrepareTestDatabase()) | ||
var MailService setting.Mailer | ||
|
||
MailService.From = "[email protected]" | ||
setting.MailService = &MailService | ||
|
||
doer := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) | ||
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1, Owner: doer}).(*Repository) | ||
issue := AssertExistsAndLoadBean(t, &Issue{ID: 1, Repo: repo, Poster: doer}).(*Issue) | ||
|
||
email := template.Must(template.New("issue/comment").Parse(tmpl)) | ||
InitMailRender(email) | ||
|
||
tos := []string{"[email protected]", "[email protected]"} | ||
msg := composeIssueCommentMessage(issue, doer, "test body", nil, mailIssueComment, tos, "issue create") | ||
|
||
subject := msg.GetHeader("Subject") | ||
messageID := msg.GetHeader("Message-ID") | ||
|
||
assert.Equal(t, subject[0], issue.mailSubject(), "Subject not equal to issue.mailSubject()") | ||
assert.Nil(t, msg.GetHeader("In-Reply-To")) | ||
assert.Nil(t, msg.GetHeader("References")) | ||
assert.Equal(t, messageID[0], "<user2/repo1/issues/1@localhost>", "Message-ID header doesn't match") | ||
} |