Documentation
¶
Overview ¶
Package conn dials and authenticates IMAP and SMTP connections for the protocol backends.
Index ¶
- Constants
- Variables
- func DialIMAP(ctx context.Context, e Endpoint) (*imapclient.Client, error)
- func DialIMAPAbortable(ctx context.Context, e Endpoint, h *imapclient.UnilateralDataHandler) (*imapclient.Client, func(), error)
- func DialPOP3(ctx context.Context, e Endpoint) (c *pop3.Conn, close func(), err error)
- func DialSMTP(ctx context.Context, e Endpoint) (*smtp.Client, error)
- func LogTrace(c *imapclient.Client, err error)
- func NewXOAuth2Client(username, token string) sasl.Client
- func RefusalReply(err error) string
- type Endpoint
- type FailureKind
- type Security
Constants ¶
const TracePrefix = "imap> "
TracePrefix 标记已脱敏的 trace 行,报告移除前缀后保留其原始字节。
Variables ¶
var ClientVersion = "dev"
ClientVersion is sent in the IMAP ID command; release builds set it.
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.
var SystemProxy = sysproxy.For
SystemProxy is the proxy for a request to u, nil for none: the user's; tests stand in for it.
var TLSRoots *x509.CertPool
TLSRoots verifies servers' certificates, nil for the system's; tests stand in for it.
Functions ¶
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 DialPOP3 ¶ added in v1.34.0
DialPOP3 connects to e and signs in with USER/PASS. close cuts the network connection at once, so a ctx that ends can unblock a read: go-pop3 takes no context. The library has no STLS, so it is done here before the connection is handed over.
func DialSMTP ¶
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 ¶
NewXOAuth2Client returns a SASL XOAUTH2 client (Google and Microsoft IMAP/SMTP).
func RefusalReply ¶ added in v1.34.0
RefusalReply is the server's reply to a refused login in err (a NO/BAD or an SMTP status, credentials masked), "" when err carries none.
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 "".