From 670562a9c57a6e793236afcd0742b410f0fecde0 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 14 Oct 2017 03:59:03 +0800 Subject: [PATCH] Fix slice out of bounds error in mailer (#2479) (#2696) --- modules/mailer/mailer.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go index 1f173e6b9..5b28f92c4 100644 --- a/modules/mailer/mailer.go +++ b/modules/mailer/mailer.go @@ -16,6 +16,7 @@ import ( "strings" "time" + "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" @@ -41,7 +42,7 @@ func NewMessageFrom(to []string, from, subject, body string) *Message { plainBody, err := html2text.FromString(body) if err != nil || setting.MailService.SendAsPlainText { - if strings.Contains(body[:100], "") { + if strings.Contains(base.TruncateString(body, 100), "") { log.Warn("Mail contains HTML but configured to send as plain text.") } msg.SetBody("text/plain", plainBody)