-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (49 loc) · 1.13 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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 ===")
}