mirror of
https://github.com/mjl-/mox.git
synced 2024-12-29 18:03:48 +03:00
26 lines
411 B
Go
26 lines
411 B
Go
|
package smtpserver
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"io"
|
||
|
)
|
||
|
|
||
|
var errMessageTooLarge = errors.New("maximum message size exceeded")
|
||
|
|
||
|
type limitWriter struct {
|
||
|
maxSize int64
|
||
|
w io.Writer
|
||
|
written int64
|
||
|
}
|
||
|
|
||
|
func (w *limitWriter) Write(buf []byte) (int, error) {
|
||
|
if w.written+int64(len(buf)) > w.maxSize {
|
||
|
return 0, errMessageTooLarge
|
||
|
}
|
||
|
n, err := w.w.Write(buf)
|
||
|
if n > 0 {
|
||
|
w.written += int64(n)
|
||
|
}
|
||
|
return n, err
|
||
|
}
|