Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Friedrich Staufenbiel committed Apr 7, 2021
1 parent fa0bd3d commit 5dc5868
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# go-pop3-harvest
# go-pop3-harvest
Small golang based commandline app to get all emails from a simple pop3 server.

## Usage
```sh
go-pop3-harvest <host> <user> <pass> <output directory>

# 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).
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
57 changes: 57 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -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 ===")
}
7 changes: 7 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -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 .

0 comments on commit 5dc5868

Please sign in to comment.