diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-02-28 13:37:32 +0100 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-02-28 13:37:32 +0100 |
commit | 013a2ef2659d1296457bc6b12c49a9480aa3551e (patch) | |
tree | 544a63c75311f6f48ba7c507b73685068e28a72d /internal/imap | |
parent | 4f112c16dfac61deb128b48e9d516f78ab55fc95 (diff) | |
download | feed2imap-go-013a2ef2659d1296457bc6b12c49a9480aa3551e.tar.gz feed2imap-go-013a2ef2659d1296457bc6b12c49a9480aa3551e.tar.bz2 feed2imap-go-013a2ef2659d1296457bc6b12c49a9480aa3551e.zip |
IMAP: Set a timeout for connection
Diffstat (limited to 'internal/imap')
-rw-r--r-- | internal/imap/imap.go | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/internal/imap/imap.go b/internal/imap/imap.go index 20713a4..51687ff 100644 --- a/internal/imap/imap.go +++ b/internal/imap/imap.go @@ -2,7 +2,9 @@ package imap import ( "fmt" + "net" "strings" + "time" imapClient "github.com/emersion/go-imap/client" @@ -10,6 +12,12 @@ import ( "github.com/Necoro/feed2imap-go/pkg/log" ) +var dialer imapClient.Dialer + +func init() { + dialer = &net.Dialer{Timeout: 30 * time.Second} +} + func newImapClient(url config.Url) (*imapClient.Client, error) { var ( c *imapClient.Client @@ -17,12 +25,12 @@ func newImapClient(url config.Url) (*imapClient.Client, error) { ) if url.ForceTLS() { - if c, err = imapClient.DialTLS(url.HostPort(), nil); err != nil { + if c, err = imapClient.DialWithDialerTLS(dialer, url.HostPort(), nil); err != nil { return nil, fmt.Errorf("connecting (TLS) to %s: %w", url.Host, err) } log.Print("Connected to ", url.HostPort(), " (TLS)") } else { - if c, err = imapClient.Dial(url.HostPort()); err != nil { + if c, err = imapClient.DialWithDialer(dialer, url.HostPort()); err != nil { return nil, fmt.Errorf("connecting to %s: %w", url.Host, err) } } |