add vendoring

This commit is contained in:
Aine
2022-11-16 12:08:51 +02:00
parent 14751cbf3a
commit c1d33fe3cb
1104 changed files with 759066 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
package smtp
import (
"errors"
"io"
)
var ErrTooLongLine = errors.New("smtp: too longer line in input stream")
// lineLimitReader reads from the underlying Reader but restricts
// line length of lines in input stream to a certain length.
//
// If line length exceeds the limit - Read returns ErrTooLongLine
type lineLimitReader struct {
R io.Reader
LineLimit int
curLineLength int
}
func (r *lineLimitReader) Read(b []byte) (int, error) {
if r.curLineLength > r.LineLimit && r.LineLimit > 0 {
return 0, ErrTooLongLine
}
n, err := r.R.Read(b)
if err != nil {
return n, err
}
if r.LineLimit == 0 {
return n, nil
}
for _, chr := range b[:n] {
if chr == '\n' {
r.curLineLength = 0
}
r.curLineLength++
if r.curLineLength > r.LineLimit {
return 0, ErrTooLongLine
}
}
return n, nil
}