From 85a350749b201e7808d59ec330ceb7102e29f702 Mon Sep 17 00:00:00 2001 From: kolaente Date: Fri, 3 Apr 2026 20:10:44 +0200 Subject: [PATCH] refactor(mail): use CryptoRandomString for Message-ID generation Replace manual rand.Read + hex.EncodeToString with the existing utils.CryptoRandomString helper for generating the random part of the Message-ID header. --- pkg/mail/send_mail.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/mail/send_mail.go b/pkg/mail/send_mail.go index 0ff34704c..1183fbd33 100644 --- a/pkg/mail/send_mail.go +++ b/pkg/mail/send_mail.go @@ -17,14 +17,13 @@ package mail import ( - "crypto/rand" "embed" - "encoding/hex" "fmt" "io" "code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/log" + "code.vikunja.io/api/pkg/utils" "code.vikunja.io/api/pkg/version" "github.com/wneessen/go-mail" @@ -83,9 +82,8 @@ func getMessage(opts *Opts) *mail.Msg { // Set an RFC 5322 compliant Message-ID using the public URL domain // instead of relying on os.Hostname() which is unreliable in containers. - randBytes := make([]byte, 16) - _, _ = rand.Read(randBytes) - messageID := hex.EncodeToString(randBytes) + "@" + GetMailDomain() + randPart, _ := utils.CryptoRandomString(32) + messageID := randPart + "@" + GetMailDomain() m.SetMessageIDWithValue(messageID) if opts.From == "" { opts.From = "Vikunja <" + config.MailerFromEmail.GetString() + ">"