fix pop3 fetching, limit recv to N bytes
This commit is contained in:
25
email.go
25
email.go
@@ -86,23 +86,29 @@ func (e *Emailer) ReadIMAP() (chan *mail.Message, error) {
|
||||
}
|
||||
|
||||
func (e *Emailer) ReadPOP3() (chan *mail.Message, error) {
|
||||
emails := []*mail.Message{}
|
||||
limit := e.Limit
|
||||
if limit < 1 {
|
||||
limit = 1000
|
||||
}
|
||||
emails := make(chan *mail.Message, limit)
|
||||
defer close(emails)
|
||||
|
||||
c, err := pop3.DialTLS(e.POP3)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer c.Rset()
|
||||
|
||||
if err := c.Auth(e.From, e.Password); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ids, _, err := c.ListAll()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for j, id := range ids {
|
||||
if e.Limit > 0 && len(ids)-1-j >= e.Limit {
|
||||
break
|
||||
}
|
||||
|
||||
for _, id := range ids {
|
||||
raw, err := c.Retr(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -111,10 +117,13 @@ func (e *Emailer) ReadPOP3() (chan *mail.Message, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
emails = append(emails, msg)
|
||||
select {
|
||||
case emails <- msg:
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
//return emails, nil //c.Quit()
|
||||
return emails, nil
|
||||
}
|
||||
|
||||
func (e *Emailer) Send(to, subj, msg string) error {
|
||||
|
||||
Reference in New Issue
Block a user