Go to file
Kailash Nadh 741df52cd1 Fix conn leak in `Quit()`. Closes #13.
Co-authored-by: TestMsr <cs3120@vip.qq.com>
2024-02-27 16:10:35 +05:30
.github/workflows updating github workflows to include pull_request as trigger event 2023-03-23 06:11:57 +00:00
LICENSE First commit 2021-06-27 20:10:50 +05:30
README.md Ad Godoc link to README 2021-06-28 19:07:50 +05:30
go.mod First commit 2021-06-27 20:10:50 +05:30
go.sum First commit 2021-06-27 20:10:50 +05:30
pop3.go Fix conn leak in `Quit()`. Closes #13. 2024-02-27 16:10:35 +05:30
pop3_test.go changing log.Fatal to t.Fatal in pop3_test 2023-03-23 06:21:51 +00:00

README.md

go-pop3

A simple Go POP3 client library for connecting and reading mails from POP3 servers. This is a full rewrite of TheCreeper/go-pop3 with bug fixes and new features.

Install

go get -u github.com/knadh/go-pop3

Example

import (
	"fmt"
	"github.com/knadh/go-pop3"
)

func main() {
	// Initialize the client.
	p := pop3.New(pop3.Opt{
		Host: "pop.gmail.com",
		Port: 995,
		TLSEnabled: true,
	})

	// Create a new connection. POP3 connections are stateful and should end
	// with a Quit() once the opreations are done.
	c, err := p.NewConn()
	if err != nil {
		log.Fatal(err)
	}
	defer c.Quit()

	// Authenticate.
	if err := c.Auth("myuser", "mypassword"); err != nil {
		log.Fatal(err)
	}

	// Print the total number of messages and their size.
	count, size, _ := c.Stat()
	fmt.Println("total messages=", count, "size=", size)

	// Pull the list of all message IDs and their sizes.
	msgs, _ := c.List(0)
	for _, m := range msgs {
		fmt.Println("id=", m.ID, "size=", m.Size)
	}

	// Pull all messages on the server. Message IDs go from 1 to N.
	for id := 1; id <= count; id++ {
		m, _ := c.Retr(id)

		fmt.Println(id, "=", m.Header.Get("subject"))

		// To read the multi-part e-mail bodies, see:
		// https://github.com/emersion/go-message/blob/master/example_test.go#L12
	}

	// Delete all the messages. Server only executes deletions after a successful Quit()
	for id := 1; id <= count; id++ {
		c.Dele(id)
	}
}

PkgGoDev

To-do: tests

Setup a Docker test environment that runs InBucket POP3 + SMTP server to run a dummy POP3 server and test all the commands in the lib.

Licensed under the MIT License.