protonmail: add Client.Debug
This prints HTTP requests and responses.
This commit is contained in:
parent
4ede51e2b0
commit
d97056a61a
|
@ -26,10 +26,13 @@ import (
|
||||||
smtpbackend "github.com/emersion/hydroxide/smtp"
|
smtpbackend "github.com/emersion/hydroxide/smtp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var debug bool
|
||||||
|
|
||||||
func newClient() *protonmail.Client {
|
func newClient() *protonmail.Client {
|
||||||
return &protonmail.Client{
|
return &protonmail.Client{
|
||||||
RootURL: "https://mail.protonmail.com/api",
|
RootURL: "https://mail.protonmail.com/api",
|
||||||
AppVersion: "Web_3.16.6",
|
AppVersion: "Web_3.16.6",
|
||||||
|
Debug: debug,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +137,7 @@ Flags:
|
||||||
CardDAV port on which hydroxide listens, defaults to 8080`
|
CardDAV port on which hydroxide listens, defaults to 8080`
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
debug := flag.Bool("debug", false, "Enable debug logs")
|
flag.BoolVar(&debug, "debug", false, "Enable debug logs")
|
||||||
|
|
||||||
smtpHost := flag.String("smtp-host", "127.0.0.1", "Allowed SMTP email hostname on which hydroxide listens, defaults to 127.0.0.1")
|
smtpHost := flag.String("smtp-host", "127.0.0.1", "Allowed SMTP email hostname on which hydroxide listens, defaults to 127.0.0.1")
|
||||||
smtpPort := flag.String("smtp-port", "1025", "SMTP port on which hydroxide listens, defaults to 1025")
|
smtpPort := flag.String("smtp-port", "1025", "SMTP port on which hydroxide listens, defaults to 1025")
|
||||||
|
@ -335,12 +338,12 @@ func main() {
|
||||||
case "smtp":
|
case "smtp":
|
||||||
addr := *smtpHost + ":" + *smtpPort
|
addr := *smtpHost + ":" + *smtpPort
|
||||||
authManager := auth.NewManager(newClient)
|
authManager := auth.NewManager(newClient)
|
||||||
log.Fatal(listenAndServeSMTP(addr, *debug, authManager))
|
log.Fatal(listenAndServeSMTP(addr, debug, authManager))
|
||||||
case "imap":
|
case "imap":
|
||||||
addr := *imapHost + ":" + *imapPort
|
addr := *imapHost + ":" + *imapPort
|
||||||
authManager := auth.NewManager(newClient)
|
authManager := auth.NewManager(newClient)
|
||||||
eventsManager := events.NewManager()
|
eventsManager := events.NewManager()
|
||||||
log.Fatal(listenAndServeIMAP(addr, *debug, authManager, eventsManager))
|
log.Fatal(listenAndServeIMAP(addr, debug, authManager, eventsManager))
|
||||||
case "carddav":
|
case "carddav":
|
||||||
addr := *carddavHost + ":" + *carddavPort
|
addr := *carddavHost + ":" + *carddavPort
|
||||||
authManager := auth.NewManager(newClient)
|
authManager := auth.NewManager(newClient)
|
||||||
|
@ -356,10 +359,10 @@ func main() {
|
||||||
|
|
||||||
done := make(chan error, 3)
|
done := make(chan error, 3)
|
||||||
go func() {
|
go func() {
|
||||||
done <- listenAndServeSMTP(smtpAddr, *debug, authManager)
|
done <- listenAndServeSMTP(smtpAddr, debug, authManager)
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
done <- listenAndServeIMAP(imapAddr, *debug, authManager, eventsManager)
|
done <- listenAndServeIMAP(imapAddr, debug, authManager, eventsManager)
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
done <- listenAndServeCardDAV(carddavAddr, authManager, eventsManager)
|
done <- listenAndServeCardDAV(carddavAddr, authManager, eventsManager)
|
||||||
|
|
|
@ -55,6 +55,7 @@ func (err *APIError) Error() string {
|
||||||
type Client struct {
|
type Client struct {
|
||||||
RootURL string
|
RootURL string
|
||||||
AppVersion string
|
AppVersion string
|
||||||
|
Debug bool
|
||||||
|
|
||||||
HTTPClient *http.Client
|
HTTPClient *http.Client
|
||||||
ReAuth func() error
|
ReAuth func() error
|
||||||
|
@ -77,7 +78,9 @@ func (c *Client) newRequest(method, path string, body io.Reader) (*http.Request,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//log.Printf(">> %v %v\n", method, path)
|
if c.Debug {
|
||||||
|
log.Printf(">> %v %v\n", req.Method, req.URL.Path)
|
||||||
|
}
|
||||||
|
|
||||||
req.Header.Set("X-Pm-Appversion", c.AppVersion)
|
req.Header.Set("X-Pm-Appversion", c.AppVersion)
|
||||||
req.Header.Set(headerAPIVersion, strconv.Itoa(Version))
|
req.Header.Set(headerAPIVersion, strconv.Itoa(Version))
|
||||||
|
@ -92,13 +95,15 @@ func (c *Client) newJSONRequest(method, path string, body interface{}) (*http.Re
|
||||||
}
|
}
|
||||||
b := buf.Bytes()
|
b := buf.Bytes()
|
||||||
|
|
||||||
//log.Printf(">> %v %v\n%v", method, path, string(b))
|
|
||||||
|
|
||||||
req, err := c.newRequest(method, path, bytes.NewReader(b))
|
req, err := c.newRequest(method, path, bytes.NewReader(b))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.Debug {
|
||||||
|
log.Print(string(b))
|
||||||
|
}
|
||||||
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.GetBody = func() (io.ReadCloser, error) {
|
req.GetBody = func() (io.ReadCloser, error) {
|
||||||
return ioutil.NopCloser(bytes.NewReader(b)), nil
|
return ioutil.NopCloser(bytes.NewReader(b)), nil
|
||||||
|
@ -157,7 +162,10 @@ func (c *Client) doJSON(req *http.Request, respData interface{}) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//log.Printf("<< %v %v\n%#v", req.Method, req.URL.Path, respData)
|
if c.Debug {
|
||||||
|
log.Printf("<< %v %v", req.Method, req.URL.Path)
|
||||||
|
log.Printf("%#v", respData)
|
||||||
|
}
|
||||||
|
|
||||||
if maybeError, ok := respData.(maybeError); ok {
|
if maybeError, ok := respData.(maybeError); ok {
|
||||||
if err := maybeError.Err(); err != nil {
|
if err := maybeError.Err(); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue