1package smtpserver
2
3import (
4 "errors"
5 "io"
6)
7
8var errMessageTooLarge = errors.New("maximum message size exceeded")
9
10type limitWriter struct {
11 maxSize int64
12 w io.Writer
13 written int64
14}
15
16func (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