pop3

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: MIT Imports: 10 Imported by: 0

README

POP3 Client

codecov

POP3 Client written in Golang in accordance to RFC1939.

Usage

Initialize client
// Create a connection to the server
c, err := pop3.DialTLS("REPLACE_THIS_SERVER_ADDRESS:993")
if err != nil {
    log.Fatal(err)
}
defer c.Quit()

// Authenticate with the server
if err = c.Authorization("REPLACE_THIS_USERNAME", "REPLACE_THIS_PASSWORD"); err != nil {
    log.Fatal(err)
}
Commands
// Check if there are any messages to retrieved.
count, _, err := pc.Stat()
if err != nil {
    log.Fatal(err)
}

message, err := pc.Retr(1)
if err != nil {
    log.Fatal(err)
}

log.Println(message.Text)
log.Println(message.GetHeader("Subject"))

if err := pc.Dele(1); err != nil {
    log.Fatal(err)
}

Testing

To run tests, run following command:

go test -race ./...

Contributions & Issues

Contributions are welcome. Please clearly explain the purpose of the PR and follow the current style.

Issues can be resolved quickest if they are descriptive and include both a reduced test case, and a set of steps to reproduce.

Licence

The genert/pop3 library is copyrighted © by Genert Org and licensed for use under the MIT License (MIT).

Please see MIT License for more information.

Documentation

Index

Constants

View Source
const (
	OK  = "+OK"
	ERR = "-ERR"
)

POP3 replies as extracted from rfc1939 section 9.

View Source
const (
	CommandReset = "RSET"

	// CommandStat is a command to retrieve statistics about mailbox.
	CommandStat = "STAT"

	// CommandDelete is a command to delete message from POP3 server.
	CommandDelete = "DELE"

	// CommandList is a command to get list of messages from POP3 server.
	CommandList = "LIST"

	// CommandNoop is a ping-like command that tells POP3 to do nothing.
	// (i.e. send something line pong-response).
	CommandNoop = "NOOP"

	// CommandPassword is a command to send user password to POP3 server.
	CommandPassword = "PASS"

	// CommandQuit is a command to tell POP3 server that you are quitting.
	CommandQuit = "QUIT"

	// CommandRetrieve is a command to retrieve POP3 message from server.
	CommandRetrieve = "RETR"

	// CommandUser is a command to send user login to POP3 server.
	CommandUser = "USER"
)

Variables

This section is empty.

Functions

func IsErr

func IsErr(s string) bool

IsErr checks to see if the reply from the server contains +Err.

func IsOK

func IsOK(s string) bool

IsOK checks to see if the reply from the server contains +OK.

Types

type Client

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

Client for POP3.

func Dial

func Dial(addr string) (c *Client, err error)

Dial opens new connection and creates a new POP3 client.

func DialTLS

func DialTLS(addr string) (c *Client, err error)

DialTLS opens new TLS connection and creates a new POP3 client.

func NewClient

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

NewClient creates a new POP3 client.

func (*Client) Authorization

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

Authorization logs into POP3 server with login and password.

func (*Client) Dele

func (c *Client) Dele(msg int) error

Dele will delete the given message from the maildrop. Changes will only take affect after the Quit command is issued.

func (*Client) ListAll

func (c *Client) ListAll() (list []MessageList, err error)

ListAll returns a MessageList object which contains all messages in the maildrop.

func (*Client) Noop

func (c *Client) Noop() error

Noop will do nothing however can prolong the end of a connection.

func (*Client) Quit

func (c *Client) Quit() error

Quit sends the QUIT message to the POP3 server and closes the connection.

func (*Client) Retr

func (c *Client) Retr(msg int) (*enmime.Envelope, error)

Retr downloads the given message and returns it as a mail.Message object.

func (*Client) Rset

func (c *Client) Rset() error

Rset will unmark any messages that have being marked for deletion in the current session.

func (*Client) Stat

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

Stat retrieves a drop listing for the current maildrop, consisting of the number of messages and the total size (in octets) of the maildrop. In the event of an error, all returned numeric values will be 0.

type Connection

type Connection struct {
	Reader *textproto.Reader
	Writer *textproto.Writer
	// contains filtered or unexported fields
}

Client holds the net conn and read/write buffer objects.

func NewConnection

func NewConnection(conn io.ReadWriteCloser) *Connection

NewConnection initializes a connection.

func (*Connection) Close

func (c *Connection) Close() error

Close closes a connection.

func (*Connection) Cmd

func (c *Connection) Cmd(format string, args ...interface{}) (string, error)

Cmd sends the given command on the connection.

func (*Connection) ReadLine

func (c *Connection) ReadLine() (string, error)

ReadLine reads a single line from the buffer.

func (*Connection) ReadLines

func (c *Connection) ReadLines() (lines []string, err error)

ReadLines reads from the buffer until it hits the message end dot (".").

type MessageList

type MessageList struct {
	// Non unique id reported by the server
	ID int

	// Size of the message
	Size int
}

MessageList represents the metadata returned by the server for a message stored in the maildrop.

Jump to

Keyboard shortcuts

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