Skip to content

Commit

Permalink
Merge pull request #4 from emersion/master
Browse files Browse the repository at this point in the history
Disable lineLimitReader when handle BDAT data
  • Loading branch information
linanh authored Mar 24, 2021
2 parents fd0c72b + f92bf7f commit 00de75a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ type Conn struct {
locker sync.Mutex
binarymime bool

bdatPipe *io.PipeWriter
bdatStatus *statusCollector // used for BDAT on LMTP
dataResult chan error
bytesReceived int // counts total size of chunks when BDAT is used
lineLimitReader *lineLimitReader
bdatPipe *io.PipeWriter
bdatStatus *statusCollector // used for BDAT on LMTP
dataResult chan error
bytesReceived int // counts total size of chunks when BDAT is used

fromReceived bool
recipients []string
Expand All @@ -66,15 +67,16 @@ func newConn(c net.Conn, s *Server) *Conn {
}

func (c *Conn) init() {
c.lineLimitReader = &lineLimitReader{
R: c.conn,
LineLimit: c.server.MaxLineLength,
}
rwc := struct {
io.Reader
io.Writer
io.Closer
}{
Reader: &lineLimitReader{
R: c.conn,
LineLimit: c.server.MaxLineLength,
},
Reader: c.lineLimitReader,
Writer: c.conn,
Closer: c.conn,
}
Expand Down Expand Up @@ -859,6 +861,8 @@ func (c *Conn) handleBdat(arg string) {
}()
}

c.lineLimitReader.LineLimit = 0

chunk := io.LimitReader(c.text.R, int64(size))
_, err = io.Copy(c.bdatPipe, chunk)
if err != nil {
Expand All @@ -873,12 +877,15 @@ func (c *Conn) handleBdat(arg string) {
}

c.reset()
c.lineLimitReader.LineLimit = c.server.MaxLineLength
return
}

c.bytesReceived += int(size)

if last {
c.lineLimitReader.LineLimit = c.server.MaxLineLength

c.bdatPipe.Close()

err := <-c.dataResult
Expand Down
2 changes: 1 addition & 1 deletion lengthlimit_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type lineLimitReader struct {
}

func (r *lineLimitReader) Read(b []byte) (int, error) {
if r.curLineLength > r.LineLimit {
if r.curLineLength > r.LineLimit && r.LineLimit > 0 {
return 0, ErrTooLongLine
}

Expand Down

0 comments on commit 00de75a

Please sign in to comment.