Skip to content

Commit

Permalink
Allow custom dialers
Browse files Browse the repository at this point in the history
  • Loading branch information
kubuzetto committed Feb 8, 2024
1 parent aaa1bf2 commit aad5700
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pop3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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"`
Expand Down Expand Up @@ -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,
}
}

Expand All @@ -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
}
Expand Down

0 comments on commit aad5700

Please # to comment.