diff --git a/internal/textproto/reader.go b/internal/textproto/reader.go index 41246da2..010396df 100644 --- a/internal/textproto/reader.go +++ b/internal/textproto/reader.go @@ -180,7 +180,7 @@ func (r *Reader) skipSpace() int { break } if c != ' ' && c != '\t' { - r.R.UnreadByte() + _ = r.R.UnreadByte() break } n++ @@ -373,7 +373,7 @@ func (d *dotReader) Read(b []byte) (n int, err error) { } // Not part of .\r\n. // Consume leading dot and emit saved \r. - br.UnreadByte() + _ = br.UnreadByte() c = '\r' d.state = stateData @@ -383,7 +383,7 @@ func (d *dotReader) Read(b []byte) (n int, err error) { break } // Not part of \r\n. Emit saved \r - br.UnreadByte() + _ = br.UnreadByte() c = '\r' d.state = stateData @@ -418,7 +418,7 @@ func (r *Reader) closeDot() { for r.dot != nil { // When Read reaches EOF or an error, // it will set r.dot == nil. - r.dot.Read(buf) + _, _ = r.dot.Read(buf) } } @@ -589,7 +589,7 @@ var nl = []byte("\n") // that will be in this header. If it gets confused, it returns 0. func (r *Reader) upcomingHeaderNewlines() (n int) { // Try to determine the 'hint' size. - r.R.Peek(1) // force a buffer load if empty + _, _ = r.R.Peek(1) // force a buffer load if empty s := r.R.Buffered() if s == 0 { return diff --git a/internal/textproto/reader_email.go b/internal/textproto/reader_email.go index 09e2d84f..0cc8e362 100644 --- a/internal/textproto/reader_email.go +++ b/internal/textproto/reader_email.go @@ -6,6 +6,10 @@ import ( "math" ) +// ReadEmailMIMEHeader reads a MIME-style header from r. +// +// This is a modified version of the stock func that better handles the characters +// we must support in email, instead of just HTTP. func (r *Reader) ReadEmailMIMEHeader() (MIMEHeader, error) { return readEmailMIMEHeader(r, math.MaxInt64) } @@ -91,6 +95,11 @@ func readEmailMIMEHeader(r *Reader, lim int64) (MIMEHeader, error) { } } +// CanonicalEmailMIMEHeaderKey returns the canonical format of the +// MIME header key s. +// +// This is a modified version of the stock func that better handles the characters +// we must support in email, instead of just HTTP. func CanonicalEmailMIMEHeaderKey(s string) string { // Quick check for canonical encoding. upper := true diff --git a/internal/textproto/reader_test.go b/internal/textproto/reader_test.go index 9618b874..2c7d2aa4 100644 --- a/internal/textproto/reader_test.go +++ b/internal/textproto/reader_test.go @@ -387,9 +387,9 @@ func TestIssue46363(t *testing.T) { r, w := net.Pipe() go func() { // ReadMIMEHeader calls canonicalMIMEHeaderKey, which reads from commonHeader - NewConn(r).ReadMIMEHeader() + _, _ = NewConn(r).ReadMIMEHeader() }() - w.Write([]byte("A: 1\r\nB: 2\r\nC: 3\r\n\r\n")) + _, _ = w.Write([]byte("A: 1\r\nB: 2\r\nC: 3\r\n\r\n")) // CanonicalMIMEHeaderKey calls commonHeaderOnce.Do(initCommonHeader) which initializes commonHeader CanonicalMIMEHeaderKey("a") diff --git a/internal/textproto/writer.go b/internal/textproto/writer.go index 2ece3f51..cc1c2247 100644 --- a/internal/textproto/writer.go +++ b/internal/textproto/writer.go @@ -29,7 +29,7 @@ var dotcrnl = []byte{'.', '\r', '\n'} func (w *Writer) PrintfLine(format string, args ...any) error { w.closeDot() fmt.Fprintf(w.W, format, args...) - w.W.Write(crnl) + _, _ = w.W.Write(crnl) return w.W.Flush() } @@ -73,7 +73,7 @@ func (d *dotWriter) Write(b []byte) (n int, err error) { d.state = wstateData if c == '.' { // escape leading dot - bw.WriteByte('.') + _ = bw.WriteByte('.') } fallthrough @@ -82,7 +82,7 @@ func (d *dotWriter) Write(b []byte) (n int, err error) { d.state = wstateCR } if c == '\n' { - bw.WriteByte('\r') + _ = bw.WriteByte('\r') d.state = wstateBeginLine }