Skip to content

Commit f62f04c

Browse files
GiteaBotwxiaoguang
andauthored
Fix incorrect message id for release email (go-gitea#30825) (go-gitea#30833)
Backport go-gitea#30825 by wxiaoguang Make generateMessageIDForRelease outputs the same format as generateMessageIDForIssue (old `createReference`) Co-authored-by: wxiaoguang <[email protected]>
1 parent 253c97b commit f62f04c

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

services/mailer/mail.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
289289
}
290290

291291
// Make sure to compose independent messages to avoid leaking user emails
292-
msgID := createReference(ctx.Issue, ctx.Comment, ctx.ActionType)
293-
reference := createReference(ctx.Issue, nil, activities_model.ActionType(0))
292+
msgID := generateMessageIDForIssue(ctx.Issue, ctx.Comment, ctx.ActionType)
293+
reference := generateMessageIDForIssue(ctx.Issue, nil, activities_model.ActionType(0))
294294

295295
var replyPayload []byte
296296
if ctx.Comment != nil {
@@ -362,7 +362,7 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
362362
return msgs, nil
363363
}
364364

365-
func createReference(issue *issues_model.Issue, comment *issues_model.Comment, actionType activities_model.ActionType) string {
365+
func generateMessageIDForIssue(issue *issues_model.Issue, comment *issues_model.Comment, actionType activities_model.ActionType) string {
366366
var path string
367367
if issue.IsPull {
368368
path = "pulls"
@@ -389,6 +389,10 @@ func createReference(issue *issues_model.Issue, comment *issues_model.Comment, a
389389
return fmt.Sprintf("<%s/%s/%d%s@%s>", issue.Repo.FullName(), path, issue.Index, extra, setting.Domain)
390390
}
391391

392+
func generateMessageIDForRelease(release *repo_model.Release) string {
393+
return fmt.Sprintf("<%s/releases/%d@%s>", release.Repo.FullName(), release.ID, setting.Domain)
394+
}
395+
392396
func generateAdditionalHeaders(ctx *mailCommentContext, reason string, recipient *user_model.User) map[string]string {
393397
repo := ctx.Issue.Repo
394398

services/mailer/mail_release.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ func mailNewRelease(ctx context.Context, lang string, tos []string, rel *repo_mo
8686

8787
msgs := make([]*Message, 0, len(tos))
8888
publisherName := rel.Publisher.DisplayName()
89-
relURL := "<" + rel.HTMLURL() + ">"
89+
msgID := generateMessageIDForRelease(rel)
9090
for _, to := range tos {
9191
msg := NewMessageFrom(to, publisherName, setting.MailService.FromEmail, subject, mailBody.String())
9292
msg.Info = subject
93-
msg.SetHeader("Message-ID", relURL)
93+
msg.SetHeader("Message-ID", msgID)
9494
msgs = append(msgs, msg)
9595
}
9696

services/mailer/mail_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ func TestGenerateAdditionalHeaders(t *testing.T) {
288288
}
289289
}
290290

291-
func Test_createReference(t *testing.T) {
291+
func TestGenerateMessageIDForIssue(t *testing.T) {
292292
_, _, issue, comment := prepareMailerTest(t)
293293
_, _, pullIssue, _ := prepareMailerTest(t)
294294
pullIssue.IsPull = true
@@ -388,10 +388,18 @@ func Test_createReference(t *testing.T) {
388388
}
389389
for _, tt := range tests {
390390
t.Run(tt.name, func(t *testing.T) {
391-
got := createReference(tt.args.issue, tt.args.comment, tt.args.actionType)
391+
got := generateMessageIDForIssue(tt.args.issue, tt.args.comment, tt.args.actionType)
392392
if !strings.HasPrefix(got, tt.prefix) {
393-
t.Errorf("createReference() = %v, want %v", got, tt.prefix)
393+
t.Errorf("generateMessageIDForIssue() = %v, want %v", got, tt.prefix)
394394
}
395395
})
396396
}
397397
}
398+
399+
func TestGenerateMessageIDForRelease(t *testing.T) {
400+
msgID := generateMessageIDForRelease(&repo_model.Release{
401+
ID: 1,
402+
Repo: &repo_model.Repository{OwnerName: "owner", Name: "repo"},
403+
})
404+
assert.Equal(t, "<owner/repo/releases/1@localhost>", msgID)
405+
}

0 commit comments

Comments
 (0)