diff --git a/contact/email.go b/contact/email.go index 57194fb..72a9bd9 100755 --- a/contact/email.go +++ b/contact/email.go @@ -56,7 +56,7 @@ func (e *Emailer) ReadIMAP() (chan *mail.Message, error) { from := uint32(1) to := mbox.Messages if e.Limit > 0 && to > uint32(e.Limit) { - to = uint32(e.Limit) + from = to - uint32(e.Limit-1) } seqset := new(imap.SeqSet) seqset.AddRange(from, to) @@ -100,7 +100,7 @@ func (e *Emailer) ReadPOP3() (chan *mail.Message, error) { return nil, err } for j, id := range ids { - if e.Limit > 0 && j >= e.Limit { + if e.Limit > 0 && len(ids)-1-j >= e.Limit { break } raw, err := c.Retr(id) diff --git a/recv.go b/recv.go index f12bae8..d43df05 100755 --- a/recv.go +++ b/recv.go @@ -1,9 +1,13 @@ package main import ( + "fmt" + "io" + "io/ioutil" "local/args" "local/sandbox/contact/contact" - "log" + "strings" + "time" ) func main() { @@ -23,6 +27,21 @@ func main() { panic(err) } 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, + ) } }