GithubHelp home page GithubHelp logo

gozeloglu / gop-3 Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 0.0 80 KB

POP-3 client package for Go.

Home Page: https://pkg.go.dev/github.com/gozeloglu/gop-3

Go 100.00%
mailserver pop3 pop3-client pop3-protocol pop3-library go golang rfc-1939

gop-3's Introduction

gop-3 GoDoc Go Report Card Release GitHub go.mod Go version (subdirectory of monorepo) RFC 1939 LICENSE

Post Office Protocol - Version 3 (POP3) Go Client

GOP-3 (Go + POP-3) is a POP-3 client for Go. It has experimental purpose and it is still under development. RFC 1939 document has been followed while developing package.

Features - Commands

  • USER
  • PASS
  • STAT
  • LIST
  • DELE
  • RETR
  • NOOP
  • RSET
  • QUIT
  • TOP

Installation

You can download with the following command.

go get github.com/gozeloglu/gop-3

Example

package main

import (
	"fmt"
	"github.com/gozeloglu/gop-3"
	"log"
	"os"
)

func main() {
	pop, err := pop3.Connect("mail.pop3.com:110", nil, false)
	if err != nil {
		log.Fatalf(err.Error())
	}

	fmt.Println(pop.GreetingMsg())  // Message starts with "+OK"
	fmt.Println(pop.IsAuthorized()) // true
	fmt.Println(pop.IsEncrypted())  // false

	// USER command
	username := os.Getenv("POP3_USER") // Read from env
	u, err := pop.User(username)
	if err != nil {
		log.Fatalf(err.Error())
	}
	fmt.Println(u)

	// PASS command
	password := os.Getenv("POP3_PASSWORD") // Read from env
	pass, err := pop.Pass(password)
	if err != nil {
		log.Fatalf(err.Error())
	}
	fmt.Println(pass)

	// STAT command
	stat, err := pop.Stat()
	if err != nil {
		log.Fatalf(err.Error())
	}
	fmt.Println(stat)

	// LIST command
	l, _ := pop.List()
	if len(l) == 0 {
		fmt.Println(l)
	}

	// LIST <mail-num> command
	ll, _ := pop.List(1)
	fmt.Println(ll[0])
	
	// TOP msgNum n 
	top, _ := pop.Top(1, 10)
	fmt.Println(top)

	// DELE command
	dele, err := pop.Dele("1")
	if err != nil {
		log.Fatalf(err.Error())
	}
	fmt.Println(dele)

	// RETR command 
	retr, err := pop.Retr("1")
	if err != nil {
		log.Fatalf(err.Error())
	}
	for _, m := range retr {
		fmt.Println(m)
	}

	// NOOP command
	noop, err := pop.Noop()
	if err != nil {
		log.Fatalf(err.Error())
	}
	fmt.Println(noop)

	// RSET command
	rset, err := pop.Rset()
	if err != nil {
		log.Fatalf(err.Error())
	}
	fmt.Println(rset)

	// QUIT state
	q, err := pop.Quit()
	if err != nil {
		log.Fatalf(err.Error())
	}
	fmt.Println(q) // Prints: "QUIT"
}

Run & Test

Note: If you run the tests, you firstly need to have a GMail account that enables POP3 connections. Also, you have to save mail address and password in your local environment.

If you make changes, make sure that all tests are passed. You can run the tests with the following command.

go test pop3/* -v 

If you want to run only one test, you can type the following command.

go test pop3/* -v -run <test_function_name>

Example:

go test pop3/* -v -run TestStat

References

LICENSE

MIT

gop-3's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gop-3's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.