2021-12-08 07:34:23 +00:00
|
|
|
// Copyright 2021 The Gogs Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-12-08 07:34:23 +00:00
|
|
|
|
|
|
|
package mailer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2021-12-15 05:39:34 +00:00
|
|
|
|
2021-12-08 07:34:23 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGenerateMessageID(t *testing.T) {
|
2022-01-05 06:27:53 +00:00
|
|
|
mailService := setting.Mailer{
|
2021-12-10 19:43:28 +00:00
|
|
|
From: "test@gitea.com",
|
|
|
|
}
|
|
|
|
|
|
|
|
setting.MailService = &mailService
|
|
|
|
setting.Domain = "localhost"
|
2021-12-08 07:34:23 +00:00
|
|
|
|
2022-01-05 06:27:53 +00:00
|
|
|
date := time.Date(2000, 1, 2, 3, 4, 5, 6, time.UTC)
|
2023-01-22 14:23:52 +00:00
|
|
|
m := NewMessageFrom("", "display-name", "from-address", "subject", "body")
|
2021-12-08 07:34:23 +00:00
|
|
|
m.Date = date
|
|
|
|
gm := m.ToMessage()
|
|
|
|
assert.Equal(t, "<autogen-946782245000-41e8fc54a8ad3a3f@localhost>", gm.GetHeader("Message-ID")[0])
|
|
|
|
|
2023-01-22 14:23:52 +00:00
|
|
|
m = NewMessageFrom("a@b.com", "display-name", "from-address", "subject", "body")
|
2021-12-08 07:34:23 +00:00
|
|
|
m.Date = date
|
|
|
|
gm = m.ToMessage()
|
|
|
|
assert.Equal(t, "<autogen-946782245000-cc88ce3cfe9bd04f@localhost>", gm.GetHeader("Message-ID")[0])
|
|
|
|
|
2023-01-22 14:23:52 +00:00
|
|
|
m = NewMessageFrom("a@b.com", "display-name", "from-address", "subject", "body")
|
2021-12-08 07:34:23 +00:00
|
|
|
m.SetHeader("Message-ID", "<msg-d@domain.com>")
|
|
|
|
gm = m.ToMessage()
|
|
|
|
assert.Equal(t, "<msg-d@domain.com>", gm.GetHeader("Message-ID")[0])
|
|
|
|
}
|