mv /cmd to /cmd/*
This commit is contained in:
48
cmd/recv/main.go
Executable file
48
cmd/recv/main.go
Executable file
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gogs.inhome.blapointe.com/local-sandbox/contact"
|
||||
"gogs.inhome.blapointe.com/local/args"
|
||||
)
|
||||
|
||||
func main() {
|
||||
emailer := contact.NewEmailer()
|
||||
as := args.NewArgSet()
|
||||
as.Append(args.STRING, "imap", "imap server:port", "imap.gmail.com:993")
|
||||
as.Append(args.INT, "n", "limit (<1 for inf)", 10)
|
||||
if err := as.Parse(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
emailer.IMAP = as.Get("imap").GetString()
|
||||
emailer.Limit = as.Get("n").GetInt()
|
||||
|
||||
msgs, err := emailer.Read()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for msg := range msgs {
|
||||
b, _ := ioutil.ReadAll(io.LimitReader(msg.Body, 1024))
|
||||
s := strings.ReplaceAll(string(b), "\r\n", " ")
|
||||
s = strings.ReplaceAll(string(s), "\n", " ")
|
||||
s = strings.ReplaceAll(string(s), "\r", " ")
|
||||
if !strings.Contains(s, " ") {
|
||||
s = "..."
|
||||
}
|
||||
d, _ := msg.Header.Date()
|
||||
d = d.In(time.Local)
|
||||
fmt.Printf(
|
||||
"@%+v @%+v: %+v: %s\n",
|
||||
d.Format("06-01-02T15:04Z07"),
|
||||
msg.Header.Get("From"),
|
||||
msg.Header.Get("Subject"),
|
||||
s,
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user