diff --git a/go.mod b/go.mod index c51f0df..d65fd4a 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/emersion/go-imap v1.2.1 github.com/emersion/go-mbox v1.0.3 github.com/emersion/go-message v0.17.0 - github.com/emersion/go-smtp v0.19.0 + github.com/emersion/go-smtp v0.21.1 github.com/emersion/go-vcard v0.0.0-20230815062825-8fda7d206ec9 github.com/emersion/go-webdav v0.3.2-0.20220524091811-5d845721d8f7 golang.org/x/crypto v0.15.0 diff --git a/go.sum b/go.sum index a763765..c6363af 100644 --- a/go.sum +++ b/go.sum @@ -19,8 +19,8 @@ github.com/emersion/go-message v0.17.0/go.mod h1:/9Bazlb1jwUNB0npYYBsdJ2EMOiiyN3 github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ= github.com/emersion/go-sasl v0.0.0-20231106173351-e73c9f7bad43 h1:hH4PQfOndHDlpzYfLAAfl63E8Le6F2+EL/cdhlkyRJY= github.com/emersion/go-sasl v0.0.0-20231106173351-e73c9f7bad43/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ= -github.com/emersion/go-smtp v0.19.0 h1:iVCDtR2/JY3RpKoaZ7u6I/sb52S3EzfNHO1fAWVHgng= -github.com/emersion/go-smtp v0.19.0/go.mod h1:qm27SGYgoIPRot6ubfQ/GpiPy/g3PaZAVRxiO/sDUgQ= +github.com/emersion/go-smtp v0.21.1 h1:VQeZSZAKk8ueYii1yR5Zalmy7jI287eWDUqSaJ68vRM= +github.com/emersion/go-smtp v0.21.1/go.mod h1:qm27SGYgoIPRot6ubfQ/GpiPy/g3PaZAVRxiO/sDUgQ= github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594 h1:IbFBtwoTQyw0fIM5xv1HF+Y+3ZijDR839WMulgxCcUY= github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594/go.mod h1:aqO8z8wPrjkscevZJFVE1wXJrLpC5LtJG7fqLOsPb2U= github.com/emersion/go-vcard v0.0.0-20191221110513-5f81fa0d3cc7/go.mod h1:HMJKR5wlh/ziNp+sHEDV2ltblO4JD2+IdDOWtGcQBTM= diff --git a/smtp/smtp.go b/smtp/smtp.go index 6df1006..31ecb99 100644 --- a/smtp/smtp.go +++ b/smtp/smtp.go @@ -11,6 +11,7 @@ import ( "github.com/ProtonMail/go-crypto/openpgp" "github.com/ProtonMail/go-crypto/openpgp/packet" "github.com/emersion/go-message/mail" + "github.com/emersion/go-sasl" "github.com/emersion/go-smtp" "github.com/emersion/hydroxide/auth" @@ -377,7 +378,16 @@ type session struct { allReceivers []string } -func (s *session) AuthPlain(username, password string) error { +var _ interface { + smtp.Session + smtp.AuthSession +} = (*session)(nil) + +func (s *session) AuthMechanisms() []string { + return []string{sasl.Plain} +} + +func (s *session) authPlain(username, password string) error { c, privateKeys, err := s.be.sessions.Auth(username, password) if err != nil { return err @@ -403,6 +413,15 @@ func (s *session) AuthPlain(username, password string) error { return nil } +func (s *session) Auth(mech string) (sasl.Server, error) { + return sasl.NewPlainServer(func(identity, username, password string) error { + if identity != "" && identity != username { + return fmt.Errorf("invalid SASL PLAIN identity") + } + return s.authPlain(username, password) + }), nil +} + func (s *session) Mail(from string, options *smtp.MailOptions) error { if s.c == nil { return smtp.ErrAuthRequired