Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable lineLimitReader when handle BDAT data #139

Merged
merged 7 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,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 @@ -60,15 +61,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 @@ -739,6 +741,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 @@ -753,12 +757,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