mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-22 08:42:32 -05:00
b0c0167c54
When sending notification emails about a release, use a properly formatted, RFC-compliant message id, rather than the release's HTML URL wrapped in angle brackets (which would not be compliant). Fixes #3105. Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
// Copyright 2021 The Gogs Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package mailer
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGenerateMessageID(t *testing.T) {
|
|
mailService := setting.Mailer{
|
|
From: "test@gitea.com",
|
|
}
|
|
|
|
setting.MailService = &mailService
|
|
setting.Domain = "localhost"
|
|
|
|
date := time.Date(2000, 1, 2, 3, 4, 5, 6, time.UTC)
|
|
m := NewMessageFrom("", "display-name", "from-address", "subject", "body")
|
|
m.Date = date
|
|
gm := m.ToMessage()
|
|
assert.Equal(t, "<autogen-946782245000-41e8fc54a8ad3a3f@localhost>", gm.GetHeader("Message-ID")[0])
|
|
|
|
m = NewMessageFrom("a@b.com", "display-name", "from-address", "subject", "body")
|
|
m.Date = date
|
|
gm = m.ToMessage()
|
|
assert.Equal(t, "<autogen-946782245000-cc88ce3cfe9bd04f@localhost>", gm.GetHeader("Message-ID")[0])
|
|
|
|
m = NewMessageFrom("a@b.com", "display-name", "from-address", "subject", "body")
|
|
m.SetHeader("Message-ID", "<msg-d@domain.com>")
|
|
gm = m.ToMessage()
|
|
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)
|
|
}
|