#42: Return error in b64linebreaker.go when no out is set

This commit is contained in:
Winni Neessen 2022-09-08 15:43:14 +02:00
parent 3eb4bc9c52
commit 910248d999
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -5,9 +5,13 @@
package mail
import (
"fmt"
"io"
)
// ErrNoOutWriter is an error message that should be used if a Base64LineBreaker has no out io.Writer set
const ErrNoOutWriter = "no io.Writer set for Base64LineBreaker"
// Base64LineBreaker is a io.WriteCloser that writes Base64 encoded data streams
// with line breaks at a given line length
type Base64LineBreaker struct {
@ -22,6 +26,7 @@ var nl = []byte(SingleNewLine)
// line length is reached
func (l *Base64LineBreaker) Write(b []byte) (n int, err error) {
if l.out == nil {
err = fmt.Errorf(ErrNoOutWriter)
return
}
if l.used+len(b) < MaxBodyLength {