1
0
mirror of https://github.com/pocket-id/pocket-id.git synced 2026-02-04 17:24:48 +00:00

fix: emails are considered as medium spam by rspamd (#337)

This commit is contained in:
Alexander Lehmann
2025-03-16 17:46:45 +01:00
committed by GitHub
parent e45d9e970d
commit 39b7f6678c
2 changed files with 30 additions and 1 deletions

View File

@@ -18,6 +18,8 @@ import (
"os" "os"
ttemplate "text/template" ttemplate "text/template"
"time" "time"
"github.com/google/uuid"
"strings"
) )
type EmailService struct { type EmailService struct {
@@ -84,6 +86,29 @@ func SendEmail[V any](srv *EmailService, toEmail email.Address, template email.T
c.AddHeaderRaw("Content-Type", c.AddHeaderRaw("Content-Type",
fmt.Sprintf("multipart/alternative;\n boundary=%s;\n charset=UTF-8", boundary), fmt.Sprintf("multipart/alternative;\n boundary=%s;\n charset=UTF-8", boundary),
) )
c.AddHeader("MIME-Version", "1.0")
c.AddHeader("Date", time.Now().Format(time.RFC1123Z))
// to create a message-id, we need the FQDN of the sending server, but that may be a docker hostname or localhost
// so we use the domain of the from address instead (the same as Thunderbird does)
// if the address does not have an @ (which would be unusual), we use hostname
from_address := srv.appConfigService.DbConfig.SmtpFrom.Value
domain := ""
if strings.Contains(from_address, "@") {
domain = strings.Split(from_address, "@")[1]
} else {
hostname, err := os.Hostname()
if err != nil {
// can that happen? we just give up
return fmt.Errorf("failed to get own hostname: %w", err)
} else {
domain = hostname
}
}
c.AddHeader("Message-ID", "<" + uuid.New().String() + "@" + domain + ">")
c.Body(body) c.Body(body)
// Connect to the SMTP server // Connect to the SMTP server

View File

@@ -45,7 +45,11 @@ func genAddressHeader(name string, addresses []Address, maxLength int) string {
} else { } else {
email = fmt.Sprintf("<%s>", addr.Email) email = fmt.Sprintf("<%s>", addr.Email)
} }
writeHeaderQ(hl, addr.Name) if isPrintableASCII(addr.Name) {
writeHeaderAtom(hl, addr.Name)
} else {
writeHeaderQ(hl, addr.Name)
}
writeHeaderAtom(hl, " ") writeHeaderAtom(hl, " ")
writeHeaderAtom(hl, email) writeHeaderAtom(hl, email)
} }