Mm 46416 add default random message (#21176)

Automatic Merge
This commit is contained in:
Azanul Haque
2022-10-04 15:22:09 +05:30
committed by GitHub
parent 069049db03
commit e599a6cbf3
3 changed files with 13 additions and 6 deletions

View File

@@ -113,7 +113,7 @@ func (a *App) sendNotificationEmail(c request.CTX, notification *PostNotificatio
return errors.Wrap(err, "unable to render the email notification template")
}
templateString := "<%s@mattermost.com>"
templateString := "<%s@" + utils.GetHostnameFromSiteURL(a.GetSiteURL()) + ">"
messageID := ""
inReplyTo := ""
references := ""

View File

@@ -6,6 +6,7 @@ package mail
import (
"context"
"crypto/tls"
"fmt"
"io"
"mime"
"net"
@@ -17,6 +18,7 @@ import (
"github.com/pkg/errors"
gomail "gopkg.in/mail.v2"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/shared/mlog"
)
@@ -282,10 +284,10 @@ func sendMailUsingConfigAdvanced(mail mailData, config *SMTPConfig) error {
defer c.Quit()
defer c.Close()
return SendMail(c, mail, time.Now())
return sendMail(c, mail, time.Now(), config)
}
func SendMail(c smtpClient, mail mailData, date time.Time) error {
func sendMail(c smtpClient, mail mailData, date time.Time, config *SMTPConfig) error {
mlog.Debug("sending mail", mlog.String("to", mail.smtpTo), mlog.String("subject", mail.subject))
htmlMessage := mail.htmlBody
@@ -315,6 +317,10 @@ func SendMail(c smtpClient, mail mailData, date time.Time) error {
if mail.messageID != "" {
headers["Message-ID"] = []string{mail.messageID}
} else {
randomStringLength := 16
msgID := fmt.Sprintf("<%s-%d@%s>", model.NewRandomString(randomStringLength), time.Now().Unix(), config.Hostname)
headers["Message-ID"] = []string{msgID}
}
if mail.inReplyTo != "" {

View File

@@ -363,13 +363,13 @@ func TestSendMail(t *testing.T) {
"\r\nMessage-ID: <abc123@mattermost.com>\r\n",
"",
},
"doesn't add message-id header": {
"always adds message-id header": {
mail.Address{},
"",
"",
"",
"\r\nMessage-ID: <",
"",
"\r\nMessage-ID:",
},
"adds in-reply-to header": {
mail.Address{},
@@ -408,7 +408,8 @@ func TestSendMail(t *testing.T) {
for testName, tc := range testCases {
t.Run(testName, func(t *testing.T) {
mail := mailData{"", "", mail.Address{}, "", tc.replyTo, "", "", nil, nil, tc.messageID, tc.inReplyTo, tc.references}
err = SendMail(mocm, mail, time.Now())
cfg := getConfig()
err = sendMail(mocm, mail, time.Now(), cfg)
require.NoError(t, err)
if tc.contains != "" {
require.Contains(t, string(mocm.data), tc.contains)