pop3

package
v0.1.83 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*textproto.Conn
}

Client represents a POP3 client connection. It embeds a textproto.Conn for low-level protocol communication.

func Dial

func Dial(ctx context.Context, addr string) (*Client, error)

Dial establishes a plain TCP connection to the POP3 server at the given address. The connection respects the provided context for timeout or cancellation.

func DialTLS

func DialTLS(ctx context.Context, addr string) (*Client, error)

DialTLS establishes a secure POP3-over-TLS connection to the given address. The server name is automatically derived from the address for certificate verification.

func NewClient

func NewClient(conn net.Conn) (*Client, error)

NewClient initializes a POP3 client from an existing connection. It reads the server greeting line and validates that it starts with "+OK".

func (*Client) Auth added in v0.1.81

func (c *Client) Auth(user, pass string) error

Auth authenticates the user using the USER/PASS commands. Returns an error if either step fails.

func (*Client) Cmd

func (c *Client) Cmd(s string, isMulti bool, args ...any) (string, error)

Cmd sends a POP3 command with optional arguments and reads the response. If isMulti is true, the response is treated as multi-line and read until a line containing only "." is encountered. All lines are concatenated and returned.

func (*Client) Dele

func (c *Client) Dele(ids ...int) error

Dele marks one or more messages for deletion. The deletions are finalized only after a successful Quit().

func (*Client) List

func (c *Client) List(id int) ([]MessageID, error)

List returns message IDs and sizes from the mailbox. If id > 0, only that specific message is listed (single-line response). If id == 0, all messages are listed (multi-line response).

func (*Client) Noop

func (c *Client) Noop() error

Noop sends a NOOP command to keep the connection alive. Useful for preventing idle timeouts.

func (*Client) Quit

func (c *Client) Quit() error

Quit sends the QUIT command and closes the connection gracefully. Deletions are committed only if QUIT succeeds.

func (*Client) Retr

func (c *Client) Retr(id int) (string, error)

Retr retrieves the full message text by ID, including headers and body.

func (*Client) Rset

func (c *Client) Rset() error

Rset resets the deletion marks on all messages in the current session.

func (*Client) Stat

func (c *Client) Stat() (count int, size int, err error)

Stat returns the number of messages and the total mailbox size (in bytes).

func (*Client) Top

func (c *Client) Top(id int, numLines int) (string, error)

Top retrieves message headers and the first numLines of the body.

func (*Client) Uidl

func (c *Client) Uidl(id int) ([]MessageID, error)

Uidl returns message IDs and their unique identifiers (UIDs). If id > 0, only that specific message is listed. The UIDL command may not be supported by all servers.

type MessageID

type MessageID struct {
	ID   int    // Numerical message index (1-based)
	Size int    // Message size in bytes
	UID  string // Optional UID (only for UIDL command)
}

MessageID represents a single message entry as returned by LIST or UIDL. It includes the message index, size, and optional UID.

Jump to

Keyboard shortcuts

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