Skip to content

Commit

Permalink
imap: add support for plain auth
Browse files Browse the repository at this point in the history
If the server reports the AUTH=PLAIN SASL mechanism, use it in priority
over LOGIN which has been deprecated in favor of SASL.

Pass an empty identity argument which results in identity=username. Aerc
does not have the ability to configure it.

Signed-off-by: Robin Jarry <[email protected]>
Tested-by: Runxi Yu <[email protected]>
  • Loading branch information
rjarry committed Jan 16, 2025
1 parent 3d509bb commit aef7bb0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions worker/imap/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"git.sr.ht/~rjarry/aerc/lib/log"
"github.com/emersion/go-imap"
"github.com/emersion/go-imap/client"
"github.com/emersion/go-sasl"
)

// connect establishes a new tcp connection to the imap server, logs in and
Expand Down Expand Up @@ -88,6 +89,13 @@ func (w *IMAPWorker) connect() (*client.Client, error) {
username, password, w.config.name, c); err != nil {
return nil, err
}
} else if plain, err := c.SupportAuth("PLAIN"); err != nil {
return nil, err
} else if plain {
auth := sasl.NewPlainClient("", username, password)
if err := c.Authenticate(auth); err != nil {
return nil, err
}
} else if err := c.Login(username, password); err != nil {
return nil, err
}
Expand Down

0 comments on commit aef7bb0

Please sign in to comment.