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.
This commit is contained in:
parent
07aa3c1b04
commit
85a350749b
|
|
@ -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() + ">"
|
||||
|
|
|
|||
Loading…
Reference in New Issue