From aad5700325e726c2e7fa238c92d76b3683477f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Devrim=20=C5=9Eahin?= Date: Thu, 8 Feb 2024 20:56:49 +0300 Subject: [PATCH] Allow custom dialers --- pop3.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pop3.go b/pop3.go index 4297313..6d4c876 100644 --- a/pop3.go +++ b/pop3.go @@ -17,7 +17,8 @@ import ( // Client implements a Client e-mail client. type Client struct { - opt Opt + opt Opt + dialer *net.Dialer } // Conn is a stateful connection with the POP3 server/ @@ -34,6 +35,7 @@ type Opt struct { // Default is 3 seconds. DialTimeout time.Duration `json:"dial_timeout"` + Dialer *net.Dialer `json:"-"` TLSEnabled bool `json:"tls_enabled"` TLSSkipVerify bool `json:"tls_skip_verify"` @@ -64,8 +66,13 @@ func New(opt Opt) *Client { opt.DialTimeout = time.Second * 3 } + dialer := opt.Dialer + if dialer == nil { + dialer = &net.Dialer{Timeout: opt.DialTimeout} + } + return &Client{ - opt: opt, + opt: opt, dialer: dialer, } } @@ -75,7 +82,7 @@ func (c *Client) NewConn() (*Conn, error) { addr = fmt.Sprintf("%s:%d", c.opt.Host, c.opt.Port) ) - conn, err := net.DialTimeout("tcp", addr, c.opt.DialTimeout) + conn, err := c.dialer.Dial("tcp", addr) if err != nil { return nil, err }