Merge pull request 'services: Use proper Message-IDs for release mails' (#3309) from algernon/forgejo:are-we-dot-atom-text-yet into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3309 Reviewed-by: Otto <otto@codeberg.org> Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
commit
b6992ed6b9
3 changed files with 21 additions and 2 deletions
|
@ -389,6 +389,10 @@ func createReference(issue *issues_model.Issue, comment *issues_model.Comment, a
|
||||||
return fmt.Sprintf("<%s/%s/%d%s@%s>", issue.Repo.FullName(), path, issue.Index, extra, setting.Domain)
|
return fmt.Sprintf("<%s/%s/%d%s@%s>", issue.Repo.FullName(), path, issue.Index, extra, setting.Domain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createMessageIDForRelease(rel *repo_model.Release) string {
|
||||||
|
return fmt.Sprintf("<%s/releases/%d@%s>", rel.Repo.FullName(), rel.ID, setting.Domain)
|
||||||
|
}
|
||||||
|
|
||||||
func generateAdditionalHeaders(ctx *mailCommentContext, reason string, recipient *user_model.User) map[string]string {
|
func generateAdditionalHeaders(ctx *mailCommentContext, reason string, recipient *user_model.User) map[string]string {
|
||||||
repo := ctx.Issue.Repo
|
repo := ctx.Issue.Repo
|
||||||
|
|
||||||
|
|
|
@ -86,11 +86,11 @@ func mailNewRelease(ctx context.Context, lang string, tos []string, rel *repo_mo
|
||||||
|
|
||||||
msgs := make([]*Message, 0, len(tos))
|
msgs := make([]*Message, 0, len(tos))
|
||||||
publisherName := rel.Publisher.DisplayName()
|
publisherName := rel.Publisher.DisplayName()
|
||||||
relURL := "<" + rel.HTMLURL() + ">"
|
msgID := createMessageIDForRelease(rel)
|
||||||
for _, to := range tos {
|
for _, to := range tos {
|
||||||
msg := NewMessageFrom(to, publisherName, setting.MailService.FromEmail, subject, mailBody.String())
|
msg := NewMessageFrom(to, publisherName, setting.MailService.FromEmail, subject, mailBody.String())
|
||||||
msg.Info = subject
|
msg.Info = subject
|
||||||
msg.SetHeader("Message-ID", relURL)
|
msg.SetHeader("Message-ID", msgID)
|
||||||
msgs = append(msgs, msg)
|
msgs = append(msgs, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -36,3 +37,17 @@ func TestGenerateMessageID(t *testing.T) {
|
||||||
gm = m.ToMessage()
|
gm = m.ToMessage()
|
||||||
assert.Equal(t, "<msg-d@domain.com>", gm.GetHeader("Message-ID")[0])
|
assert.Equal(t, "<msg-d@domain.com>", gm.GetHeader("Message-ID")[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGenerateMessageIDForRelease(t *testing.T) {
|
||||||
|
setting.Domain = "localhost"
|
||||||
|
|
||||||
|
rel := repo_model.Release{
|
||||||
|
ID: 42,
|
||||||
|
Repo: &repo_model.Repository{
|
||||||
|
OwnerName: "test",
|
||||||
|
Name: "tag-test",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
m := createMessageIDForRelease(&rel)
|
||||||
|
assert.Equal(t, "<test/tag-test/releases/42@localhost>", m)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue