1
0
mirror of https://github.com/axllent/mailpit.git synced 2025-04-21 12:17:05 +02:00

Fix: Correctly detect maximum SMTP recipient limits, add test

This commit is contained in:
Ralph Slooten 2025-02-15 22:57:25 +13:00
parent 703e981a8b
commit 1db502ef4e
2 changed files with 23 additions and 6 deletions

View File

@ -362,6 +362,11 @@ func (s *session) serve() {
var to []string var to []string
var buffer bytes.Buffer var buffer bytes.Buffer
// RFC 5321 specifies support for minimum of 100 recipients is required.
if s.srv.MaxRecipients == 0 {
s.srv.MaxRecipients = 100
}
// Send banner. // Send banner.
s.writef("220 %s %s ESMTP Service ready", s.srv.Hostname, s.srv.AppName) s.writef("220 %s %s ESMTP Service ready", s.srv.Hostname, s.srv.AppName)
@ -474,12 +479,7 @@ loop:
break break
} }
// RFC 5321 specifies support for minimum of 100 recipients is required. if len(to) >= s.srv.MaxRecipients {
if s.srv.MaxRecipients == 0 {
s.srv.MaxRecipients = 100
}
if len(to) == s.srv.MaxRecipients {
s.writef("452 4.5.3 Too many recipients") s.writef("452 4.5.3 Too many recipients")
} else { } else {
accept := true accept := true

View File

@ -242,6 +242,23 @@ func TestCmdRCPT(t *testing.T) {
conn.Close() conn.Close()
} }
func TestCmdMaxRecipients(t *testing.T) {
conn := newConn(t, &Server{MaxRecipients: 3})
cmdCode(t, conn, "EHLO host.example.com", "250")
cmdCode(t, conn, "MAIL FROM:<sender@example.com>", "250")
cmdCode(t, conn, "RCPT TO: <recipient1@example.com>", "250")
cmdCode(t, conn, "RCPT TO: <recipient2@example.com>", "250")
cmdCode(t, conn, "RCPT TO: <recipient3@example.com>", "250")
cmdCode(t, conn, "RCPT TO: <recipient4@example.com>", "452")
cmdCode(t, conn, "RCPT TO: <recipient5@example.com>", "452")
cmdCode(t, conn, "QUIT", "221")
conn.Close()
}
func TestCmdDATA(t *testing.T) { func TestCmdDATA(t *testing.T) {
conn := newConn(t, &Server{}) conn := newConn(t, &Server{})
cmdCode(t, conn, "EHLO host.example.com", "250") cmdCode(t, conn, "EHLO host.example.com", "250")