Beispiel #1
0
// Dial returns a new Client connected to the scripted server or an error if the
// connection could not be established.
func (t *T) Dial() (*imap.Client, error) {
	cn := t.cn
	if t.cn = nil; cn == nil {
		t.Fatalf(cl("t.Dial() or t.DialTLS() already called for this server"))
	}
	var err error
	if t.c, err = imap.NewClient(cn, ServerName, Timeout); err != nil {
		cn.Close()
	}
	return t.c, err
}
Beispiel #2
0
// DialTLS returns a new Client connected to the scripted server or an error if
// the connection could not be established. The server is expected to negotiate
// encryption before sending the initial greeting. Config should be nil when
// used in combination with the predefined STARTTLS script action.
func (t *T) DialTLS(config *tls.Config) (*imap.Client, error) {
	cn := t.cn
	if t.cn = nil; cn == nil {
		t.Fatalf(cl("t.Dial() or t.DialTLS() already called for this server"))
	}
	if config == nil {
		config = clientTLS()
	}
	tlsConn := tls.Client(cn, config)
	var err error
	if t.c, err = imap.NewClient(tlsConn, ServerName, Timeout); err != nil {
		cn.Close()
	}
	return t.c, err
}
Beispiel #3
0
func dialImap(addr string) (c *imap.Client, err error) {
	var conn net.Conn
	if strings.HasSuffix(addr, ":993") {
		//c, err = imap.DialTLS(addr, tlsConfig)
		conn, err = tls.DialWithDialer((&net.Dialer{Timeout: DialTimeout}), "tcp", addr, tlsConfig)
	} else {
		conn, err = net.DialTimeout("tcp", addr, DialTimeout)
	}
	if err != nil {
		return nil, e.New(err)
	}
	c, err = imap.NewClient(conn, addr, DialTimeout)
	if err != nil {
		return nil, e.New(err)
	}
	return c, nil
}