diff options
-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) } } |