fix rec out format, set local time, fix n

master v0.0.1
Bel LaPointe 2022-04-20 18:16:03 -06:00
parent 096424ff3b
commit d4768ad367
2 changed files with 23 additions and 4 deletions

View File

@ -56,7 +56,7 @@ func (e *Emailer) ReadIMAP() (chan *mail.Message, error) {
from := uint32(1) from := uint32(1)
to := mbox.Messages to := mbox.Messages
if e.Limit > 0 && to > uint32(e.Limit) { if e.Limit > 0 && to > uint32(e.Limit) {
to = uint32(e.Limit) from = to - uint32(e.Limit-1)
} }
seqset := new(imap.SeqSet) seqset := new(imap.SeqSet)
seqset.AddRange(from, to) seqset.AddRange(from, to)
@ -100,7 +100,7 @@ func (e *Emailer) ReadPOP3() (chan *mail.Message, error) {
return nil, err return nil, err
} }
for j, id := range ids { for j, id := range ids {
if e.Limit > 0 && j >= e.Limit { if e.Limit > 0 && len(ids)-1-j >= e.Limit {
break break
} }
raw, err := c.Retr(id) raw, err := c.Retr(id)

23
recv.go
View File

@ -1,9 +1,13 @@
package main package main
import ( import (
"fmt"
"io"
"io/ioutil"
"local/args" "local/args"
"local/sandbox/contact/contact" "local/sandbox/contact/contact"
"log" "strings"
"time"
) )
func main() { func main() {
@ -23,6 +27,21 @@ func main() {
panic(err) panic(err)
} }
for msg := range msgs { for msg := range msgs {
log.Println(msg) 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,
)
} }
} }