From c2738474d5f4bcdd83bdc09c372f27fe677201ab Mon Sep 17 00:00:00 2001 From: Julian Date: Sat, 22 Jun 2024 23:36:30 +0200 Subject: [bugfix] add Date and Message-ID headers for email (#3031) * [bugfix] add Date and Message-ID headers for email This should make spam filters more happy, as most of them grant some negative score for not having those headers. Also the Date is convenient for the user receiving the mail. * make golangci-lint happy --- internal/email/common.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'internal/email/common.go') diff --git a/internal/email/common.go b/internal/email/common.go index 5864a82f7..25a469a39 100644 --- a/internal/email/common.go +++ b/internal/email/common.go @@ -26,7 +26,9 @@ import ( "path/filepath" "strings" "text/template" + "time" + "github.com/google/uuid" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/gtserror" ) @@ -37,7 +39,7 @@ func (s *sender) sendTemplate(template string, subject string, data any, toAddre return err } - msg, err := assembleMessage(subject, buf.String(), s.from, toAddresses...) + msg, err := assembleMessage(subject, buf.String(), s.from, s.msgIDHost, toAddresses...) if err != nil { return err } @@ -65,7 +67,7 @@ func loadTemplates(templateBaseDir string) (*template.Template, error) { // assembleMessage assembles a valid email message following: // - https://datatracker.ietf.org/doc/html/rfc2822 // - https://pkg.go.dev/net/smtp#SendMail -func assembleMessage(mailSubject string, mailBody string, mailFrom string, mailTo ...string) ([]byte, error) { +func assembleMessage(mailSubject string, mailBody string, mailFrom string, msgIDHost string, mailTo ...string) ([]byte, error) { if strings.ContainsAny(mailSubject, "\r\n") { return nil, errors.New("email subject must not contain newline characters") } @@ -103,7 +105,9 @@ func assembleMessage(mailSubject string, mailBody string, mailFrom string, mailT // msg headers.' msg.WriteString("To: Undisclosed Recipients:;" + CRLF) } + msg.WriteString("Date: " + time.Now().Format(time.RFC822Z) + CRLF) msg.WriteString("From: " + mailFrom + CRLF) + msg.WriteString("Message-ID: <" + uuid.New().String() + "@" + msgIDHost + ">" + CRLF) msg.WriteString("Subject: " + mailSubject + CRLF) msg.WriteString("MIME-Version: 1.0" + CRLF) msg.WriteString("Content-Transfer-Encoding: 8bit" + CRLF) -- cgit v1.2.3