Skip to content

Commit a9d7ec5

Browse files
committed
imapclient: set default dial timeout to 30s
Users can use New if they want more control.
1 parent e767b0d commit a9d7ec5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

imapclient/client.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ const (
4646
literalWriteTimeout = 5 * time.Minute
4747
)
4848

49+
var dialer = &net.Dialer{
50+
Timeout: 30 * time.Second,
51+
}
52+
4953
// SelectedMailbox contains metadata for the currently selected mailbox.
5054
type SelectedMailbox struct {
5155
Name string
@@ -212,7 +216,7 @@ func DialTLS(address string, options *Options) (*Client, error) {
212216
tlsConfig.NextProtos = []string{"imap"}
213217
}
214218

215-
conn, err := tls.Dial("tcp", address, tlsConfig)
219+
conn, err := tls.DialWithDialer(dialer, "tcp", address, tlsConfig)
216220
if err != nil {
217221
return nil, err
218222
}
@@ -230,7 +234,7 @@ func DialStartTLS(address string, options *Options) (*Client, error) {
230234
return nil, err
231235
}
232236

233-
conn, err := net.Dial("tcp", address)
237+
conn, err := dialer.Dial("tcp", address)
234238
if err != nil {
235239
return nil, err
236240
}

0 commit comments

Comments
 (0)