Migrate to go-imap v2

v1 is no longer actively maintained.

Co-authored-by: Conrad Hoffmann <ch@bitfehler.net>
This commit is contained in:
Simon Ser 2024-02-19 17:21:12 +00:00 committed by Conrad Hoffmann
parent ebb5aede92
commit a95896216f
3 changed files with 40 additions and 17 deletions

View file

@ -5,8 +5,7 @@ import (
"github.com/rs/zerolog/log"
"github.com/emersion/go-imap/client"
"github.com/emersion/go-sasl"
"github.com/emersion/go-imap/v2/imapclient"
)
type IMAPProvider struct {
@ -50,8 +49,7 @@ func (prov *IMAPProvider) doAuth(next http.Handler,
}
defer conn.Close()
auth := sasl.NewPlainClient("", user, pass)
if err := conn.Authenticate(auth); err != nil {
if err := conn.Login(user, pass).Wait(); err != nil {
log.Debug().Str("user", user).Err(err).Msg("auth error")
http.Error(w, "Invalid username or password", http.StatusUnauthorized)
return
@ -67,10 +65,10 @@ func (prov *IMAPProvider) doAuth(next http.Handler,
next.ServeHTTP(w, r)
}
func (prov *IMAPProvider) dial() (*client.Client, error) {
func (prov *IMAPProvider) dial() (*imapclient.Client, error) {
if prov.tls {
return client.DialTLS(prov.addr, nil)
return imapclient.DialTLS(prov.addr, nil)
} else {
return client.Dial(prov.addr)
return imapclient.DialInsecure(prov.addr, nil)
}
}