mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 07:43:18 -05:00
b59875aa12
* allways set a message-id on mails * Add unit tests for mailer & Message-ID Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
// Copyright 2021 The Gogs 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 mailer
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGenerateMessageID(t *testing.T) {
|
|
setting.LoadForTest(`
|
|
[mailer]
|
|
ENABLED = true
|
|
FROM = test@domain.com
|
|
`)
|
|
setting.NewServices()
|
|
|
|
date := time.Date(2000, 01, 02, 03, 04, 05, 06, time.UTC)
|
|
m := NewMessageFrom(nil, "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([]string{"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([]string{"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])
|
|
}
|