Documentation
¶
Overview ¶
Package smtpproxy is based heavily on https://github.com/emersion/go-smtp, with increased transparency of response codes and no sasl dependency.
Package smtpproxy is based heavily on https://github.com/emersion/go-smtp, with increased transparency of response codes and no sasl dependency.
Package smtpproxy is based heavily on https://github.com/emersion/go-smtp, with increased transparency of response codes and no sasl dependency.
Package smtpproxy is based heavily on https://github.com/emersion/go-smtp, with increased transparency of response codes and no sasl dependency.
Package smtpproxy is based heavily on https://github.com/emersion/go-smtp, with increased transparency of response codes and no sasl dependency.
Package smtpproxy is based heavily on https://github.com/emersion/go-smtp, with increased transparency of response codes and no sasl dependency.
Package smtpproxy is based heavily on https://github.com/emersion/go-smtp, with increased transparency of response codes and no sasl dependency.
Package smtpproxy is based heavily on https://github.com/emersion/go-smtp, with increased transparency of response codes and no sasl dependency.
Index ¶
- Variables
- func CreateProxy(inHostPort, outHostPort string, verboseOpt bool, cert, privkey []byte, ...) (*Server, *ProxyBackend, error)
- func NewLineSplitterWriter(len int, sep []byte, w io.Writer) io.Writer
- func ParseCmd(line string) (cmd string, arg string, err error)
- type Backend
- type Client
- func (c *Client) Capabilities() []string
- func (c *Client) Close() error
- func (c *Client) Data() (io.WriteCloser, int, string, error)
- func (c *Client) Extension(ext string) (bool, string)
- func (c *Client) Hello(localName string) (int, string, error)
- func (c *Client) MyCmd(expectCode int, format string, args ...interface{}) (int, string, error)
- func (c *Client) StartTLS(config *tls.Config) (int, string, error)
- func (c *Client) TLSConnectionState() (state tls.ConnectionState, ok bool)
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) ReadLine() (string, error)
- func (c *Conn) Server() *Server
- func (c *Conn) Session() Session
- func (c *Conn) SetSession(session Session)
- func (c *Conn) State() ConnectionState
- func (c *Conn) TLSConnectionState() (state tls.ConnectionState, ok bool)
- func (c *Conn) WriteResponse(code int, enhCode EnhancedCode, text ...string)
- type ConnectionState
- type EnhancedCode
- type Logger
- type ProxyBackend
- type SMTPError
- type Server
- type Session
- type SessionFunc
Constants ¶
This section is empty.
Variables ¶
var EnhancedCodeNotSet = EnhancedCode{0, 0, 0}
EnhancedCodeNotSet is a nil value of EnhancedCode field in SMTPError, used to indicate that backend failed to provide enhanced status code. X.0.0 will be used (X is derived from error code).
var NoEnhancedCode = EnhancedCode{-1, -1, -1}
NoEnhancedCode is used to indicate that enhanced error code should not be included in response.
Note that RFC 2034 requires an enhanced code to be included in all 2xx, 4xx and 5xx responses. This constant is exported for use by extensions, you should probably use EnhancedCodeNotSet instead.
Functions ¶
func CreateProxy ¶
func CreateProxy(inHostPort, outHostPort string, verboseOpt bool, cert, privkey []byte, insecureSkipVerify bool, dbgFile *os.File) (*Server, *ProxyBackend, error)
CreateProxy sets up a proxy server with provided parameters and options, also returns the backend.
func NewLineSplitterWriter ¶
NewLineSplitterWriter creates a new instance
Types ¶
type Client ¶
type Client struct { Text *textproto.Conn // Text is the textproto.Conn used by the Client. It is exported to allow for clients to add extensions. DataResponseCode int // proxy error reporting for data phase (as writeCloser can only return "error" class) DataResponseMsg string // contains filtered or unexported fields }
A Client represents a client connection to an SMTP server. Stripped out unused functionality for proxy
func Dial ¶
Dial returns a new Client connected to an SMTP server at addr. The addr must include a port, as in "mail.example.com:smtp".
func DialTLS ¶
DialTLS returns a new Client connected to an SMTP server via TLS at addr. The addr must include a port, as in "mail.example.com:smtps".
func NewClient ¶
NewClient returns a new Client using an existing connection and host as a server name to be used when authenticating.
func (*Client) Capabilities ¶
Capabilities reports all supported by the client, as a slice of strings Second param indicates is STARTTLS is available Return in lexically sorted order, so we get the same results each time
func (*Client) Data ¶
Data issues a DATA command to the server and returns a writer that can be used to write the mail headers and body. The caller should close the writer before calling any more methods on c. A call to Data must be preceded by one or more calls to Rcpt.
func (*Client) Extension ¶
Extension reports whether an extension is support by the server. The extension name is case-insensitive. If the extension is supported, Extension also returns a string that contains any parameters the server specifies for the extension.
func (*Client) Hello ¶
Hello sends a HELO or EHLO to the server as the given host name. Calling this method is only necessary if the client needs control over the host name used. The client will introduce itself as "localhost" automatically otherwise. If Hello is called, it must be called before any of the other methods.
This version does not specifically check for repeat calling of (E)HELO, we'll let the upstream server tell us that
func (*Client) StartTLS ¶
StartTLS sends the STARTTLS command and encrypts all further communication. This is stripped down to not attempt (E)HLOs first.
func (*Client) TLSConnectionState ¶
func (c *Client) TLSConnectionState() (state tls.ConnectionState, ok bool)
TLSConnectionState returns the client's TLS connection state. The return values are their zero values if StartTLS did not succeed.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is the incoming connection
func (*Conn) SetSession ¶
SetSession - setting the user resets any message being generated
func (*Conn) TLSConnectionState ¶
func (c *Conn) TLSConnectionState() (state tls.ConnectionState, ok bool)
TLSConnectionState returns the connection's TLS connection state. Zero values are returned if the connection doesn't use TLS.
func (*Conn) WriteResponse ¶
func (c *Conn) WriteResponse(code int, enhCode EnhancedCode, text ...string)
WriteResponse back to the incoming connection. If you do not want an enhanced code added, pass in value NoEnhancedCode.
type ConnectionState ¶
type ConnectionState struct { Hostname string LocalAddr net.Addr RemoteAddr net.Addr TLS tls.ConnectionState }
ConnectionState gives useful info about the incoming connection, including the TLS status
type EnhancedCode ¶
type EnhancedCode [3]int
EnhancedCode as per https://tools.ietf.org/html/rfc3463
type Logger ¶
type Logger interface { Printf(format string, v ...interface{}) Println(v ...interface{}) }
Logger interface is used by Server to report unexpected internal errors.
type ProxyBackend ¶
type ProxyBackend struct {
// contains filtered or unexported fields
}
The ProxyBackend implements SMTP server methods.
func NewBackend ¶
func NewBackend(outHostPort string, verbose bool, insecureSkipVerify bool) *ProxyBackend
NewBackend creates a proxy backend with specified params
func (ProxyBackend) Init ¶
func (bkd ProxyBackend) Init() (Session, error)
Init the backend. Here we establish the upstream connection
func (*ProxyBackend) MakeSession ¶
func (bkd *ProxyBackend) MakeSession(c *Client) Session
MakeSession returns a session for this client and backend
func (*ProxyBackend) SetVerbose ¶
func (bkd *ProxyBackend) SetVerbose(v bool)
SetVerbose allows changing logging options on-the-fly
type SMTPError ¶
type SMTPError struct { Code int EnhancedCode EnhancedCode Message string }
SMTPError specifies the error code and message that needs to be returned to the client
type Server ¶
type Server struct { // TCP or Unix address to listen on. Addr string // The server TLS configuration. TLSConfig *tls.Config Domain string Debug io.Writer ErrorLog Logger ReadTimeout time.Duration WriteTimeout time.Duration // If set, the AUTH command will not be advertised and authentication // attempts will be rejected. This setting overrides AllowInsecureAuth. AuthDisabled bool // The server backend. Backend Backend // contains filtered or unexported fields }
Server is an SMTP server.
func NewServer ¶
NewServer creates a new SMTP server, with a Backend interface, supporting many connections
func (*Server) ListenAndServe ¶
ListenAndServe listens on the network address s.Addr and then calls Serve to handle requests on incoming connections.
If s.Addr is blank and LMTP is disabled, ":smtp" is used.
type Session ¶
type Session interface { // Greet a session. Returns capabilities of the upstream host Greet(ehlotype string) ([]string, int, string, error) // StartTLS requests the backend to upgrade its connection StartTLS() (int, string, error) // These backend functions follow a regular pattern matching SessionFunc above Auth(expectcode int, cmd, arg string) (int, string, error) Mail(expectcode int, cmd, arg string) (int, string, error) Rcpt(expectcode int, cmd, arg string) (int, string, error) Reset(expectcode int, cmd, arg string) (int, string, error) Quit(expectcode int, cmd, arg string) (int, string, error) // DataCommand pass upstream, returning a place to write the data AND the usual responses DataCommand() (w io.WriteCloser, code int, msg string, err error) // Data body (dot delimited) pass upstream, returning the usual responses Data(r io.Reader, w io.WriteCloser) (int, string, error) // This is called if we see any unknown command Unknown(expectcode int, cmd, arg string) (int, string, error) }
Session backend functions