diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53c37a1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +dist \ No newline at end of file diff --git a/README.md b/README.md index b435184..b5d8462 100644 --- a/README.md +++ b/README.md @@ -1 +1,19 @@ -# go-pop3-harvest \ No newline at end of file +# go-pop3-harvest +Small golang based commandline app to get all emails from a simple pop3 server. + +## Usage +```sh +go-pop3-harvest + +# examples +go-pop3-harvest 10.0.0.1:110 myUser myPw . +go-pop3-harvest 10.0.0.1:110 myUser myPw outdir +``` + +## Install +* Clone the repo +* In the repo directory `go install` +* If you have ~/go/bin in your path you can start using the tool + +## Contributing +I am keen to collaborate, just open a PR or feel free to get in touch (check my profile for contact details). \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..b5342e4 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/fstau/go-pop3-harvest + +go 1.15 + +require github.com/simia-tech/go-pop3 v0.0.0-20150626094726-c9c20550a244 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..35538f0 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/simia-tech/go-pop3 v0.0.0-20150626094726-c9c20550a244 h1:izFQm9qRSp+dKUYciqiHfYnrpDNqDdiuecqGQryGlRU= +github.com/simia-tech/go-pop3 v0.0.0-20150626094726-c9c20550a244/go.mod h1:3smecozaRWHAj4cDRRnlRPVb6O44N+3S7K45/C37HpU= diff --git a/main.go b/main.go new file mode 100644 index 0000000..478af3c --- /dev/null +++ b/main.go @@ -0,0 +1,57 @@ +package main + +import ( + "fmt" + "io/ioutil" + "os" + + "github.com/simia-tech/go-pop3" +) + +func write(number int, data []byte, outDir string, user string) { + os.MkdirAll(outDir, os.FileMode(0777)) + filename := fmt.Sprintf("%s/%s-%d", outDir, user, number) + ioutil.WriteFile(filename, data, 0644) +} + +func parseArgs() (string, string, string, string) { + args := os.Args[1:] + if len(args) != 4 { + panic("Did not supply enough arguments. Usage: harvestpop3 host user pass output_directory.") + } + host := args[0] + user := args[1] + pass := args[2] + outDir := args[3] + + fmt.Println(host, user, pass, outDir) + return host, user, pass, outDir +} + +func main() { + var user string + var pass string + var host string + var outDir string + + host, user, pass, outDir = parseArgs() + + fmt.Println("=== Harvesting Mails ===") + client, err := pop3.Dial(host) + if err != nil { + panic(err) + } + err = client.Auth(user, pass) + if err != nil { + panic(err) + } + messages, _ := client.ListAll() + for message := range messages { + str, err := client.Retr(uint32(message) + 1) + if err != nil { + panic(err) + } + write(message, []byte(str), outDir, user) + } + fmt.Println("=== DONE ===") +} diff --git a/makefile b/makefile new file mode 100644 index 0000000..b942419 --- /dev/null +++ b/makefile @@ -0,0 +1,7 @@ +build: + env GOOS=darwin GOARCH=amd64 go build -o dist/go-pop3-harvest_darwin_amd64 . + env GOOS=linux GOARCH=amd64 go build -o dist/go-pop3-harvest_linux_amd64 . + env GOOS=linux GOARCH=386 go build -o dist/go-pop3-harvest_linux_386 . + env GOOS=linux GOARCH=arm go build -o dist/go-pop3-harvest_linux_arm . + env GOOS=windows GOARCH=amd64 go build -o dist/go-pop3-harvest_windows_amd64.exe . + env GOOS=windows GOARCH=386 go build -o dist/go-pop3-harvest_windows_386.exe . \ No newline at end of file