how to connect to imap through socks ? Go

huangapple go评论79阅读模式
英文:

how to connect to imap through socks ? Go

问题

我正在尝试通过 socks5 连接到一个 IMAP 服务器。为此,我从 Imap 包中导出了一些函数,但我在设置 socks5 拨号器时遇到了问题(第一步)。
我认为问题的原因是我将 nil 作为 forward 参数(类型为 Dial)传递了进去。forward 参数应该是什么?在 godoc 中没有记录。

func dialSocks(socks string) (Dial proxy.Dialer, err error) {
    Dial, err = proxy.SOCKS5("tcp", socks, nil, nil)
    return
}

func dialTLS(addr string, config *tls.Config) (c *imap.Client, err error) {
    addr = defaultPort(addr, "993")
    d, err := dialSocks("101.120.113.185:1328")
    if err != nil {
        log.Error(err)
        return
    }
    conn, err := d.Dial("tcp", addr)
    if err == nil {
        host, _, _ := net.SplitHostPort(addr)
        tlsConn := tls.Client(conn, setServerName(config, host))
        if c, err = imap.NewClient(tlsConn, host, 60*time.Second); err != nil {
            conn.Close()
        }
    }
    return
}

func defaultPort(addr, port string) string {
    _, _, err := net.SplitHostPort(addr)
    if err != nil {
        addr = net.JoinHostPort(addr, port)
    }
    return addr
}
英文:

I'm trying to connect to an IMAP server through a socks5. To do so I've exported some functions from the Imap package but I got stuck at the socks5 dialer setup(1st step:) .
I think the reason is that I'm passing nil as forward (of type Dial) argument . What is the forward argument supposed to be ? It is not documented (in godoc)

func dialSocks(socks string) (Dial proxy.Dialer, err error) {
	Dial, err = proxy.SOCKS5("tcp", socks, nil, nil)
	return
}

func dialTLS(addr string, config *tls.Config) (c *imap.Client, err error) {
	addr = defaultPort(addr, "993")
	d, err := dialSocks("101.120.113.185:1328")
	if err != nil {
		log.Error(err)
		return
	}
	conn, err := d.Dial("tcp", addr)
	if err == nil {
		host, _, _ := net.SplitHostPort(addr)
		tlsConn := tls.Client(conn, setServerName(config, host))
		if c, err = imap.NewClient(tlsConn, host, 60*time.Second); err != nil {
			conn.Close()
		}
	}
	return
}

func defaultPort(addr, port string) string {
	_, _, err := net.SplitHostPort(addr)
	if err != nil {
		addr = net.JoinHostPort(addr, port)
	}
	return addr
}

答案1

得分: 1

forward是用于连接到代理的Dialer

如果你愿意的话,你可以在这里使用proxy.Direct(如果你查看源代码,这是包内的默认设置),但它只是将调用委托给net.Dial(network, addr)。如果你想要更多选项,可以插入自己的Dialer。

英文:

forward is the Dialer used to connect to the proxy.

You can use proxy.Direct here if you want (which is the default within the package, if you look at the source), but all that is doing is delegating to net.Dial(network, addr). If you want more options, insert your own Dialer.

huangapple
  • 本文由 发表于 2014年8月6日 11:24:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/25151742.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定