pop3client

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package pop3client is borrowed directly from https://github.com/knadh/go-pop3 to reduce dependencies. This is used solely for testing the POP3 server

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements a Client e-mail client.

func New

func New(opt Opt) *Client

New returns a new client object using an existing connection.

func (*Client) NewConn

func (c *Client) NewConn() (*Conn, error)

NewConn creates and returns live POP3 server connection.

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn is a stateful connection with the POP3 server/

func (*Conn) Auth

func (c *Conn) Auth(user, password string) error

Auth authenticates the given credentials with the server.

func (*Conn) Cmd

func (c *Conn) Cmd(cmd string, isMulti bool, args ...interface{}) (*bytes.Buffer, error)

Cmd sends a command to the server. POP3 responses are either single line or multi-line. The first line always with -ERR in case of an error or +OK in case of a successful operation. OK+ is always followed by a response on the same line which is either the actual response data in case of single line responses, or a help message followed by multiple lines of actual response data in case of multiline responses. See https://www.shellhacks.com/retrieve-email-pop3-server-command-line/ for examples.

func (*Conn) Dele

func (c *Conn) Dele(msgID ...int) error

Dele deletes one or more messages. The server only executes the deletions after a successful Quit().

func (*Conn) List

func (c *Conn) List(msgID int) ([]MessageID, error)

List returns a list of (message ID, message Size) pairs. If the optional msgID > 0, then only that particular message is listed. The message IDs are sequential, 1 to N.

func (*Conn) Noop

func (c *Conn) Noop() error

Noop issues a do-nothing NOOP command to the server. This is useful for prolonging open connections.

func (*Conn) Pass

func (c *Conn) Pass(s string) error

Pass sends the password to the server.

func (*Conn) Quit

func (c *Conn) Quit() error

Quit sends the QUIT command to server and gracefully closes the connection. Message deletions (DELE command) are only executed by the server on a graceful quit and close.

func (*Conn) ReadAll

func (c *Conn) ReadAll() (*bytes.Buffer, error)

ReadAll reads all lines from the connection until the POP3 multiline terminator "." is encountered and returns a bytes.Buffer of all the read lines.

func (*Conn) ReadOne

func (c *Conn) ReadOne() ([]byte, error)

ReadOne reads a single line response from the conn.

func (*Conn) Retr

func (c *Conn) Retr(msgID int) (*mail.Message, error)

Retr downloads a message by the given msgID, parses it and returns it as a *mail.Message.

func (*Conn) RetrRaw

func (c *Conn) RetrRaw(msgID int) (*bytes.Buffer, error)

RetrRaw downloads a message by the given msgID and returns the raw []byte of the entire message.

func (*Conn) Rset

func (c *Conn) Rset() error

Rset clears the messages marked for deletion in the current session.

func (*Conn) Send

func (c *Conn) Send(b string) error

Send sends a POP3 command to the server. The given comand is suffixed with "\r\n".

func (*Conn) Stat

func (c *Conn) Stat() (int, int, error)

Stat returns the number of messages and their total size in bytes in the inbox.

func (*Conn) Top

func (c *Conn) Top(msgID int, numLines int) (*mail.Message, error)

Top retrieves a message by its ID with full headers and numLines lines of the body.

func (*Conn) Uidl

func (c *Conn) Uidl(msgID int) ([]MessageID, error)

Uidl returns a list of (message ID, message UID) pairs. If the optional msgID is > 0, then only that particular message is listed. It works like Top() but only works on servers that support the UIDL command. Messages size field is not available in the UIDL response.

func (*Conn) User

func (c *Conn) User(s string) error

User sends the username to the server.

type Dialer

type Dialer interface {
	Dial(network, address string) (net.Conn, error)
}

Dialer interface

type MessageID

type MessageID struct {
	// ID is the numerical index (non-unique) of the message.
	ID int
	// Size in bytes
	Size int
	// UID is only present if the response is to the UIDL command.
	UID string
}

MessageID contains the ID and size of an individual message.

type Opt

type Opt struct {
	// Host name
	Host string `json:"host"`
	// Port number
	Port int `json:"port"`
	// DialTimeout default is 3 seconds.
	DialTimeout time.Duration `json:"dial_timeout"`
	// Dialer
	Dialer Dialer `json:"-"`
	// TLSEnabled sets whether SLS is enabled
	TLSEnabled bool `json:"tls_enabled"`
	// TLSSkipVerify skips TLS verification (ie: self-signed)
	TLSSkipVerify bool `json:"tls_skip_verify"`
}

Opt represents the client configuration.

Jump to

Keyboard shortcuts

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