go-email icon indicating copy to clipboard operation
go-email copied to clipboard

Simpler leftTrimReader

Open xeoncross opened this issue 6 years ago • 0 comments

// trimReader is a custom io.Reader that will trim any leading
// whitespace, as this can cause email imports to fail.
type trimReader struct {
	rd io.Reader
}

// Read trims off any unicode whitespace from the originating reader
func (tr trimReader) Read(buf []byte) (int, error) {
	n, err := tr.rd.Read(buf)
	t := bytes.TrimLeftFunc(buf[:n], unicode.IsSpace)
	n = copy(buf, t)
	return n, err
}

https://github.com/jordan-wright/email/blob/master/email.go#L66

xeoncross avatar Apr 11 '18 01:04 xeoncross