fix pop3 fetching, limit recv to N bytes

This commit is contained in:
Bel LaPointe
2023-10-16 08:47:16 -06:00
parent 6b04a324f3
commit 7d372adb78
2 changed files with 23 additions and 13 deletions

View File

@@ -20,6 +20,7 @@ func main() {
as.Append(args.INT, "n", "limit (<1 for inf)", 10)
as.Append(args.STRING, "u", "username", emailer.From)
as.Append(args.STRING, "p", "password", emailer.Password)
as.Append(args.INT, "b", "dont read more than this many characters", 4096)
if err := as.Parse(); err != nil {
panic(err)
}
@@ -42,17 +43,17 @@ func main() {
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", " ")
b, _ := ioutil.ReadAll(io.LimitReader(msg.Body, int64(as.GetInt("b"))))
s := strings.ReplaceAll(string(b), "\r\n", "\n")
s = strings.ReplaceAll(string(s), "\n", "\n")
s = strings.ReplaceAll(string(s), "\r", "\n")
if !strings.Contains(s, " ") {
s = "..."
}
d, _ := msg.Header.Date()
d = d.In(time.Local)
fmt.Printf(
"@%+v @%+v: %+v: %s\n",
"@%+v @%+v: \n\t%+v: \n\t%s\n",
d.Format("06-01-02T15:04Z07"),
msg.Header.Get("From"),
msg.Header.Get("Subject"),