fix(mail): restore IMAP SOCKS5 dial timeout behavior
Preserve the 30s dial timeout semantics for proxy connections by using a timeout-backed forward dialer, and add a regression test to lock this behavior. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+13
-1
@@ -37,6 +37,18 @@ type IMAPWatcher struct {
|
||||
OnReceived func(task *database.Task)
|
||||
}
|
||||
|
||||
const imapDialTimeout = 30 * time.Second
|
||||
|
||||
type timeoutDialer struct {
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
func (d timeoutDialer) Dial(network, address string) (net.Conn, error) {
|
||||
return (&net.Dialer{Timeout: d.timeout}).Dial(network, address)
|
||||
}
|
||||
|
||||
var socks5DialerFactory = proxy.SOCKS5
|
||||
|
||||
// NewIMAPWatcher creates a new IMAP watcher.
|
||||
func NewIMAPWatcher(cfg *config.Config, db *gorm.DB) *IMAPWatcher {
|
||||
return &IMAPWatcher{
|
||||
@@ -177,7 +189,7 @@ func dialTLSViaSOCKS5(addr, proxyURL string, options *imapclient.Options) (*imap
|
||||
auth = &proxy.Auth{User: u.User.Username(), Password: pw}
|
||||
}
|
||||
|
||||
dialer, err := proxy.SOCKS5("tcp", u.Host, auth, proxy.Direct)
|
||||
dialer, err := socks5DialerFactory("tcp", u.Host, auth, timeoutDialer{timeout: imapDialTimeout})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create socks5 dialer: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user