1
package smtpserver
2
3
import (
4
"errors"
5
"io"
6
)
7
8
var errMessageTooLarge = errors.New("maximum message size exceeded")
9
10
type limitWriter struct {
11
maxSize int64
12
w io.Writer
13
written int64
14
}
15
16
func (w *limitWriter) Write(buf []byte) (int, error) {
17
if w.written+int64(len(buf)) > w.maxSize {
18
return 0, errMessageTooLarge
19
}
20
n, err := w.w.Write(buf)
21
if n > 0 {
22
w.written += int64(n)
23
}
24
return n, err
25
}
26