Turning off IMAP server while no connection

This commit is contained in:
Michal Horejsek
2020-12-21 10:08:03 +01:00
parent a468ce635c
commit 5117672388
4 changed files with 55 additions and 2 deletions

View File

@ -102,6 +102,9 @@ type ClientConfig struct {
// MinBytesPerSecond specifies minimum Bytes per second or the request will be canceled.
// Zero means no limitation.
MinBytesPerSecond int64
NoConnectionHandler func()
ConnectionHandler func()
}
// client is a client of the protonmail API. It implements the Client interface.

View File

@ -37,7 +37,17 @@ func NewProxyTLSDialer(dialer TLSDialer, cm *ClientManager) *ProxyTLSDialer {
}
// DialTLS dials the given network/address. If it fails, it retries using a proxy.
func (d *ProxyTLSDialer) DialTLS(network, address string) (conn net.Conn, err error) {
func (d *ProxyTLSDialer) DialTLS(network, address string) (net.Conn, error) {
conn, err := d.dialTLS(network, address)
if err != nil {
d.cm.config.NoConnectionHandler()
} else {
d.cm.config.ConnectionHandler()
}
return conn, err
}
func (d *ProxyTLSDialer) dialTLS(network, address string) (conn net.Conn, err error) {
if conn, err = d.dialer.DialTLS(network, address); err == nil {
return
}