Fix e-mail From/Return-Path envelope sender. Closes #908, closes #1008.

This commit is contained in:
Kailash Nadh 2022-11-10 00:01:24 +05:30
parent c2d41e0671
commit 74322cda36
3 changed files with 21 additions and 10 deletions

2
go.mod
View file

@ -15,7 +15,7 @@ require (
github.com/knadh/go-pop3 v0.3.0
github.com/knadh/goyesql/v2 v2.1.2
github.com/knadh/koanf v1.2.3
github.com/knadh/smtppool v1.0.0
github.com/knadh/smtppool v1.0.1
github.com/knadh/stuffbin v1.1.0
github.com/labstack/echo/v4 v4.9.0
github.com/lib/pq v1.10.3

2
go.sum
View file

@ -84,6 +84,8 @@ github.com/knadh/koanf v1.2.3 h1:2Rkr0YhhYk+4QEOm800Q3Pu0Wi87svTxM6uuEb4WhYw=
github.com/knadh/koanf v1.2.3/go.mod h1:xpPTwMhsA/aaQLAilyCCqfpEiY1gpa160AiCuWHJUjY=
github.com/knadh/smtppool v1.0.0 h1:1c8A7+nD8WdMMzvd3yY5aoY9QBgyGTA+Iq1IdlgKGJw=
github.com/knadh/smtppool v1.0.0/go.mod h1:3DJHouXAgPDBz0kC50HukOsdapYSwIEfJGwuip46oCA=
github.com/knadh/smtppool v1.0.1 h1:gNASLB4x4W5jhVHRApwr9d2xSpsuannAFJVt/bVR8pA=
github.com/knadh/smtppool v1.0.1/go.mod h1:3DJHouXAgPDBz0kC50HukOsdapYSwIEfJGwuip46oCA=
github.com/knadh/stuffbin v1.1.0 h1:f5S5BHzZALjuJEgTIOMC9NidEnBJM7Ze6Lu1GHR/lwU=
github.com/knadh/stuffbin v1.1.0/go.mod h1:yVCFaWaKPubSNibBsTAJ939q2ABHudJQxRWZWV5yh+4=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=

View file

@ -11,7 +11,10 @@ import (
"github.com/knadh/smtppool"
)
const emName = "email"
const (
emName = "email"
hdrReturnPath = "Return-Path"
)
// Server represents an SMTP server's credentials.
type Server struct {
@ -125,16 +128,22 @@ func (e *Emailer) Push(m messenger.Message) error {
}
em.Headers = textproto.MIMEHeader{}
// Attach e-mail level headers.
if len(m.Headers) > 0 {
em.Headers = m.Headers
}
// Attach SMTP level headers.
if len(srv.EmailHeaders) > 0 {
for k, v := range srv.EmailHeaders {
em.Headers.Set(k, v)
}
for k, v := range srv.EmailHeaders {
em.Headers.Set(k, v)
}
// Attach e-mail level headers.
for k, v := range m.Headers {
em.Headers.Set(k, v[0])
}
// If the `Return-Path` header is set, it should be set as the
// the SMTP envelope sender (via the Sender field of the email struct).
if sender := em.Headers.Get(hdrReturnPath); sender != "" {
em.Sender = sender
em.Headers.Del(hdrReturnPath)
}
switch m.ContentType {