diff --git a/imap/imap.go b/imap/imap.go index a28d8ee..d2fa628 100644 --- a/imap/imap.go +++ b/imap/imap.go @@ -4,6 +4,7 @@ import ( "bufio" "crypto/tls" "fmt" + "io" "log" "net/mail" "strconv" @@ -183,7 +184,7 @@ func (c *connection) write(s string) { func (c *connection) read(desc string) string { buf := make([]byte, 0) - reader := bufio.NewReader(c.Conn) + reader := bufio.NewReader(io.LimitReader(c.Conn, maxRead)) var err error var conclusion string if desc == "server hello" { @@ -195,7 +196,7 @@ func (c *connection) read(desc string) string { var line []byte c.SetReadDeadline(time.Now().Add(timeout * time.Millisecond)) line, tmpErr := reader.ReadBytes('\n') - if tmpErr == nil && len(buf)+len(line) <= maxRead { + if tmpErr == nil { if l := string(line); strings.HasPrefix(l, conclusion) { if strings.HasPrefix(l, conclusion+"OK") { break