summaryrefslogtreecommitdiff
path: root/internal/email/common.go
diff options
context:
space:
mode:
authorLibravatar Julian <j.r@jugendhacker.de>2024-06-22 23:36:30 +0200
committerLibravatar GitHub <noreply@github.com>2024-06-22 23:36:30 +0200
commitc2738474d5f4bcdd83bdc09c372f27fe677201ab (patch)
tree1df6cc7f8882774274cb72c90a34ea3febc42448 /internal/email/common.go
parent[chore] update github.com/ncruces/go-sqlite3 -> v0.16.3 (#3029) (diff)
downloadgotosocial-c2738474d5f4bcdd83bdc09c372f27fe677201ab.tar.xz
[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
Diffstat (limited to 'internal/email/common.go')
-rw-r--r--internal/email/common.go8
1 files changed, 6 insertions, 2 deletions
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)