conn

package
v1.33.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 24 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package conn dials and authenticates IMAP and SMTP connections for the protocol backends.

Index

Constants

View Source
const TracePrefix = "imap> "

TracePrefix 标记已脱敏的 trace 行,报告移除前缀后保留其原始字节。

Variables

View Source
var ClientVersion = "dev"

ClientVersion is sent in the IMAP ID command; release builds set it.

View Source
var ErrSMTPAuthDisabled = errors.New("SMTP AUTH is disabled for the mailbox")

ErrSMTPAuthDisabled is a backend.ErrAuthFailed whose server said SMTP AUTH is turned off for the mailbox (Microsoft's 535 5.7.139), not that the credentials are wrong.

View Source
var SystemProxy = sysproxy.For

SystemProxy is the proxy for a request to u, nil for none: the user's; tests stand in for it.

View Source
var TLSRoots *x509.CertPool

TLSRoots verifies servers' certificates, nil for the system's; tests stand in for it.

Functions

func DialIMAP

func DialIMAP(ctx context.Context, e Endpoint) (*imapclient.Client, error)

DialIMAP connects to e and logs in.

func DialIMAPAbortable

func DialIMAPAbortable(ctx context.Context, e Endpoint, h *imapclient.UnilateralDataHandler) (*imapclient.Client, func(), error)

DialIMAPAbortable is DialIMAP that also returns abort, which closes the network connection at once. Unlike Client.Close it does not wait for a response literal being read, so it can cut off a download. h, if not nil, receives unsolicited server updates (IDLE).

func DialSMTP

func DialSMTP(ctx context.Context, e Endpoint) (*smtp.Client, error)

DialSMTP connects to e and authenticates with PLAIN, or XOAUTH2 when e has an AccessToken.

func LogTrace

func LogTrace(c *imapclient.Client, err error)

LogTrace logs the end of c's traffic, masked, when err is a protocol error: a server response go-imap could not parse. The log is what an error report carries, so a report of such an error shows what the server sent.

func NewXOAuth2Client

func NewXOAuth2Client(username, token string) sasl.Client

NewXOAuth2Client returns a SASL XOAUTH2 client (Google and Microsoft IMAP/SMTP).

Types

type Endpoint

type Endpoint struct {
	Host               string
	Port               int
	Security           Security
	Username, Password string
	AccessToken        string
}

Endpoint describes one server and the credentials to use on it. A non-empty AccessToken selects XOAUTH2 and Password is ignored.

type FailureKind

type FailureKind string

FailureKind is the broad cause of a failed dial, for diagnostics.

const (
	FailureDNS      FailureKind = "dns"
	FailureConnect  FailureKind = "connect"
	FailureTimeout  FailureKind = "timeout"
	FailureTLS      FailureKind = "tls"
	FailureAuth     FailureKind = "auth"
	FailureProtocol FailureKind = "protocol"

	FailureProxyUnreachable FailureKind = "proxy_unreachable"
	FailureProxyRefused     FailureKind = "proxy_refused"
	FailureProxyAuth        FailureKind = "proxy_auth" // the proxy's credentials, never the account's
)

func Classify

func Classify(err error) FailureKind

Classify maps an error from DialIMAP or DialSMTP to a FailureKind; nil gives "".

type Security

type Security string

Security selects the transport protection of a connection.

const (
	TLS      Security = "tls"
	StartTLS Security = "starttls"
	None     Security = "none"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL