Add Session.SetHTTPBasicAuth

This is not 100% idiot-proof, but still makes it mroe difficult for
plugins to steal credentials.
This commit is contained in:
Simon Ser 2020-01-10 19:35:55 +01:00
parent c38b1d47f9
commit 425445f443
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48

View file

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"sync" "sync"
"time" "time"
"net/http"
imapclient "github.com/emersion/go-imap/client" imapclient "github.com/emersion/go-imap/client"
"github.com/emersion/go-sasl" "github.com/emersion/go-sasl"
@ -104,6 +105,13 @@ func (s *Session) DoSMTP(f func(*smtp.Client) error) error {
return nil return nil
} }
// SetHTTPBasicAuth adds an Authorization header field to the request with
// this session's credentials.
func (s *Session) SetHTTPBasicAuth(req *http.Request) {
// TODO: find a way to make it harder for plugins to steal credentials
req.SetBasicAuth(s.username, s.password)
}
// Close destroys the session. This can be used to log the user out. // Close destroys the session. This can be used to log the user out.
func (s *Session) Close() { func (s *Session) Close() {
select { select {