mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[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
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user