Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use v2 in socks5 or http proxy,but return err:unexpected EOF #661

Closed
jarvis657 opened this issue Dec 17, 2024 · 4 comments
Closed

use v2 in socks5 or http proxy,but return err:unexpected EOF #661

jarvis657 opened this issue Dec 17, 2024 · 4 comments

Comments

@jarvis657
Copy link

jarvis657 commented Dec 17, 2024

As mentioned in the subject, I am using v2 and I'm unable to successfully log in through either a SOCKS5 proxy or an HTTP proxy. Here is my code:

dialer, err := proxy.SOCKS5("tcp", "xxxx:17777", &proxy.Auth{
	User:     "user",
	Password: "xxxx",
}, proxy.Direct)
if err != nil {
	fmt.Fprintln(os.Stderr, "can't connect to the proxy:", err)
	os.Exit(1)
}
conn, err := dialer.Dial("tcp", emailConfig.EmailImap)
// Connect to server
    //	//options := &imapclient.Options{
//	TLSConfig: &tls.Config{InsecureSkipVerify: true},
//	//DebugWriter: os.Stdout,
//	//UnilateralDataHandler: nil,
//	WordDecoder: &mime.WordDecoder{CharsetReader: charset.Reader},
//}
//c := imapclient.New(conn, options)  set or not, same error  
    // c, err := imapclient.NewStartTLS(conn, options)    same error  
c := imapclient.New(conn, nil)
if err != nil {
	log.Fatal(err)
}
if err := c.Login(mailAccount, emailConfig.EmailFromPass).Wait(); err != nil {
	log.Fatalf("failed to login: %v", err) 
}

print : failed to login: unexpected EOF

@jarvis657
Copy link
Author

github.com/emersion/go-imap/v2 v2.0.0-beta.4
i used

@jarvis657
Copy link
Author

image
if i change code like this ,return err:imap: BAD [CLIENTBUG] syntax: unexpected char: 's'

dialer, _ := proxy.SOCKS5("tcp", "ip:port", &proxy.Auth{
	User:     "user",
	Password: "pass",
}, &net.Dialer{Timeout: 20 * time.Second, KeepAlive: 30 * time.Second}) // create a socks5 dialer with timeout

conn, _ := dialer.Dial("tcp", emailConfig.EmailImap) // connect
conn = tls.Client(conn, &tls.Config{
	InsecureSkipVerify: true,
}) // use tls
options := &imapclient.Options{
	TLSConfig: &tls.Config{InsecureSkipVerify: true},
	//DebugWriter: os.Stdout,
	//UnilateralDataHandler: nil,
	WordDecoder: &mime.WordDecoder{CharsetReader: charset.Reader},
}
c, err := imapclient.NewStartTLS(conn, options)
//c, err := imapclient.DialTLS(emailConfig.EmailImap, options)
if err != nil {
	log.Fatalf("failed to dial %v IMAP server: %v\n", mailAccount, err)
}

The SOCKS5 proxy is functioning correctly because another Go program of ours can call another service through this proxy and run normally.

@jarvis657
Copy link
Author

image if i change code like this ,return err:imap: BAD [CLIENTBUG] syntax: unexpected char: 's'

dialer, _ := proxy.SOCKS5("tcp", "ip:port", &proxy.Auth{
	User:     "user",
	Password: "pass",
}, &net.Dialer{Timeout: 20 * time.Second, KeepAlive: 30 * time.Second}) // create a socks5 dialer with timeout

conn, _ := dialer.Dial("tcp", emailConfig.EmailImap) // connect
conn = tls.Client(conn, &tls.Config{
	InsecureSkipVerify: true,
}) // use tls
options := &imapclient.Options{
	TLSConfig: &tls.Config{InsecureSkipVerify: true},
	//DebugWriter: os.Stdout,
	//UnilateralDataHandler: nil,
	WordDecoder: &mime.WordDecoder{CharsetReader: charset.Reader},
}
c, err := imapclient.NewStartTLS(conn, options)
//c, err := imapclient.DialTLS(emailConfig.EmailImap, options)
if err != nil {
	log.Fatalf("failed to dial %v IMAP server: %v\n", mailAccount, err)
}

The SOCKS5 proxy is functioning correctly because another Go program of ours can call another service through this proxy and run normally.

c, err := imapclient.NewStartTLS(conn, options) chang to c := imapclient.New(conn, options) ok...
ok....i think ,the api confused~~

@emersion
Copy link
Owner

Seems like this has been resolved, and isn't a go-imap bug in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants