recv now has -json for pretty print
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/mail"
|
"net/mail"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -21,6 +23,7 @@ func main() {
|
|||||||
as.Append(args.STRING, "u", "username", emailer.From)
|
as.Append(args.STRING, "u", "username", emailer.From)
|
||||||
as.Append(args.STRING, "p", "password", emailer.Password)
|
as.Append(args.STRING, "p", "password", emailer.Password)
|
||||||
as.Append(args.INT, "b", "dont read more than this many characters", 4096)
|
as.Append(args.INT, "b", "dont read more than this many characters", 4096)
|
||||||
|
as.Append(args.BOOL, "json", "output as json", false)
|
||||||
if err := as.Parse(); err != nil {
|
if err := as.Parse(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -42,6 +45,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
emails := make([]map[string]any, 0, emailer.Limit)
|
||||||
for msg := range msgs {
|
for msg := range msgs {
|
||||||
b, _ := ioutil.ReadAll(io.LimitReader(msg.Body, int64(as.GetInt("b"))))
|
b, _ := ioutil.ReadAll(io.LimitReader(msg.Body, int64(as.GetInt("b"))))
|
||||||
s := strings.ReplaceAll(string(b), "\r\n", "\n")
|
s := strings.ReplaceAll(string(b), "\r\n", "\n")
|
||||||
@@ -52,12 +56,26 @@ func main() {
|
|||||||
}
|
}
|
||||||
d, _ := msg.Header.Date()
|
d, _ := msg.Header.Date()
|
||||||
d = d.In(time.Local)
|
d = d.In(time.Local)
|
||||||
fmt.Printf(
|
if as.GetBool("json") {
|
||||||
"@%+v @%+v: \n\t%+v: \n\t%s\n",
|
emails = append(emails, map[string]any{
|
||||||
d.Format("06-01-02T15:04Z07"),
|
"t": d.Format("06-01-02T15:04Z07"),
|
||||||
msg.Header.Get("From"),
|
"from": msg.Header.Get("From"),
|
||||||
msg.Header.Get("Subject"),
|
"subject": msg.Header.Get("Subject"),
|
||||||
s,
|
"body": s,
|
||||||
)
|
})
|
||||||
|
} else {
|
||||||
|
fmt.Printf(
|
||||||
|
"@%+v @%+v: \n\t%+v: \n\t%s\n",
|
||||||
|
d.Format("06-01-02T15:04Z07"),
|
||||||
|
msg.Header.Get("From"),
|
||||||
|
msg.Header.Get("Subject"),
|
||||||
|
s,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if as.GetBool("json") {
|
||||||
|
enc := json.NewEncoder(os.Stdout)
|
||||||
|
enc.SetIndent("", " ")
|
||||||
|
enc.Encode(emails)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user