From fa166df5ac5249d3cf8ed08b854cfe26b6efa59e Mon Sep 17 00:00:00 2001 From: JustSong Date: Tue, 9 May 2023 16:40:05 +0800 Subject: [PATCH] fix: use title as email's subject if given --- channel/email.go | 20 +++++++++++--------- common/utils.go | 3 +++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/channel/email.go b/channel/email.go index 2861c06..3ca52b0 100644 --- a/channel/email.go +++ b/channel/email.go @@ -2,6 +2,7 @@ package channel import ( "errors" + "fmt" "message-pusher/common" "message-pusher/model" ) @@ -16,16 +17,17 @@ func SendEmailMessage(message *model.Message, user *model.User, channel_ *model. if user.Email == "" { return errors.New("未配置邮箱地址") } - subject := message.Description - if subject == "" { - subject = message.Title + subject := message.Title + content := message.Content + if subject == common.SystemName || subject == "" { + subject = message.Description + } else { + content = fmt.Sprintf("描述:%s\n\n%s", message.Description, message.Content) } - if message.Content != "" { - var err error - message.HTMLContent, err = common.Markdown2HTML(message.Content) - if err != nil { - common.SysLog(err.Error()) - } + var err error + message.HTMLContent, err = common.Markdown2HTML(content) + if err != nil { + common.SysLog(err.Error()) } return common.SendEmail(subject, user.Email, message.HTMLContent) } diff --git a/common/utils.go b/common/utils.go index 878011d..bf6145b 100644 --- a/common/utils.go +++ b/common/utils.go @@ -144,6 +144,9 @@ func Max(a int, b int) int { } func Markdown2HTML(markdown string) (HTML string, err error) { + if markdown == "" { + return "", nil + } var buf bytes.Buffer err = goldmark.Convert([]byte(markdown), &buf) if err != nil {