-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Friedrich Staufenbiel
committed
Apr 7, 2021
1 parent
fa0bd3d
commit 5dc5868
Showing
6 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ===") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 . |