mirror of
https://github.com/axllent/mailpit.git
synced 2025-08-13 20:04:49 +02:00
Rename smtp-silently-drop-rejected-recipients to smtp-ignore-rejected-recipients
This commit is contained in:
@@ -126,7 +126,7 @@ func init() {
|
|||||||
rootCmd.Flags().BoolVar(&config.SMTPStrictRFCHeaders, "smtp-strict-rfc-headers", config.SMTPStrictRFCHeaders, "Return SMTP error if message headers contain <CR><CR><LF>")
|
rootCmd.Flags().BoolVar(&config.SMTPStrictRFCHeaders, "smtp-strict-rfc-headers", config.SMTPStrictRFCHeaders, "Return SMTP error if message headers contain <CR><CR><LF>")
|
||||||
rootCmd.Flags().IntVar(&config.SMTPMaxRecipients, "smtp-max-recipients", config.SMTPMaxRecipients, "Maximum SMTP recipients allowed")
|
rootCmd.Flags().IntVar(&config.SMTPMaxRecipients, "smtp-max-recipients", config.SMTPMaxRecipients, "Maximum SMTP recipients allowed")
|
||||||
rootCmd.Flags().StringVar(&config.SMTPAllowedRecipients, "smtp-allowed-recipients", config.SMTPAllowedRecipients, "Only allow SMTP recipients matching a regular expression (default allow all)")
|
rootCmd.Flags().StringVar(&config.SMTPAllowedRecipients, "smtp-allowed-recipients", config.SMTPAllowedRecipients, "Only allow SMTP recipients matching a regular expression (default allow all)")
|
||||||
rootCmd.Flags().BoolVar(&config.SMTPSilentlyDropRejectedRecipients, "smtp-silently-drop-rejected-recipients", config.SMTPSilentlyDropRejectedRecipients, "Accept emails to rejected recipients with 2xx response but silently drop them")
|
rootCmd.Flags().BoolVar(&config.SMTPIgnoreRejectedRecipients, "smtp-ignore-rejected-recipients", config.SMTPIgnoreRejectedRecipients, "Ignore rejected SMTP recipients with 2xx response")
|
||||||
rootCmd.Flags().BoolVar(&smtpd.DisableReverseDNS, "smtp-disable-rdns", smtpd.DisableReverseDNS, "Disable SMTP reverse DNS lookups")
|
rootCmd.Flags().BoolVar(&smtpd.DisableReverseDNS, "smtp-disable-rdns", smtpd.DisableReverseDNS, "Disable SMTP reverse DNS lookups")
|
||||||
|
|
||||||
// SMTP relay
|
// SMTP relay
|
||||||
@@ -302,8 +302,8 @@ func initConfigFromEnv() {
|
|||||||
if len(os.Getenv("MP_SMTP_ALLOWED_RECIPIENTS")) > 0 {
|
if len(os.Getenv("MP_SMTP_ALLOWED_RECIPIENTS")) > 0 {
|
||||||
config.SMTPAllowedRecipients = os.Getenv("MP_SMTP_ALLOWED_RECIPIENTS")
|
config.SMTPAllowedRecipients = os.Getenv("MP_SMTP_ALLOWED_RECIPIENTS")
|
||||||
}
|
}
|
||||||
if getEnabledFromEnv("MP_SMTP_SILENTLY_DROP_REJECTED_RECIPIENTS") {
|
if getEnabledFromEnv("MP_SMTP_IGNORE_REJECTED_RECIPIENTS") {
|
||||||
config.SMTPSilentlyDropRejectedRecipients = true
|
config.SMTPIgnoreRejectedRecipients = true
|
||||||
}
|
}
|
||||||
if getEnabledFromEnv("MP_SMTP_DISABLE_RDNS") {
|
if getEnabledFromEnv("MP_SMTP_DISABLE_RDNS") {
|
||||||
smtpd.DisableReverseDNS = true
|
smtpd.DisableReverseDNS = true
|
||||||
|
@@ -181,8 +181,8 @@ var (
|
|||||||
// SMTPAllowedRecipientsRegexp is the compiled version of SMTPAllowedRecipients
|
// SMTPAllowedRecipientsRegexp is the compiled version of SMTPAllowedRecipients
|
||||||
SMTPAllowedRecipientsRegexp *regexp.Regexp
|
SMTPAllowedRecipientsRegexp *regexp.Regexp
|
||||||
|
|
||||||
// SMTPSilentlyDropRejectedRecipients if true, will accept emails to rejected recipients with 2xx response but silently drop them
|
// SMTPIgnoreRejectedRecipients if true, will accept emails to rejected recipients with 2xx response but silently drop them
|
||||||
SMTPSilentlyDropRejectedRecipients bool
|
SMTPIgnoreRejectedRecipients bool
|
||||||
|
|
||||||
// POP3Listen address - if set then Mailpit will start the POP3 server and listen on this address
|
// POP3Listen address - if set then Mailpit will start the POP3 server and listen on this address
|
||||||
POP3Listen = "[::]:1110"
|
POP3Listen = "[::]:1110"
|
||||||
@@ -584,6 +584,14 @@ func VerifyConfig() error {
|
|||||||
logger.Log().Infof("[smtp] only allowing recipients matching regexp: %s", SMTPAllowedRecipients)
|
logger.Log().Infof("[smtp] only allowing recipients matching regexp: %s", SMTPAllowedRecipients)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if SMTPIgnoreRejectedRecipients {
|
||||||
|
if SMTPAllowedRecipientsRegexp == nil {
|
||||||
|
logger.Log().Warn("[smtp] ignoring rejected recipients has no effect without setting smtp-allowed-recipients")
|
||||||
|
} else {
|
||||||
|
logger.Log().Info("[smtp] ignoring rejected recipients")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := parseRelayConfig(SMTPRelayConfigFile); err != nil {
|
if err := parseRelayConfig(SMTPRelayConfigFile); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -202,7 +202,7 @@ func listenAndServe(addr string, handler MsgIDHandler, authHandler AuthHandler)
|
|||||||
AuthHandler: nil,
|
AuthHandler: nil,
|
||||||
AuthRequired: false,
|
AuthRequired: false,
|
||||||
MaxRecipients: config.SMTPMaxRecipients,
|
MaxRecipients: config.SMTPMaxRecipients,
|
||||||
SilentlyDropRejectedRecipients: config.SMTPSilentlyDropRejectedRecipients,
|
IgnoreRejectedRecipients: config.SMTPIgnoreRejectedRecipients,
|
||||||
DisableReverseDNS: DisableReverseDNS,
|
DisableReverseDNS: DisableReverseDNS,
|
||||||
LogRead: func(remoteIP, verb, line string) {
|
LogRead: func(remoteIP, verb, line string) {
|
||||||
logger.Log().Debugf("[smtpd] %s (%s) %s", verbLogTranslator(verb), remoteIP, line)
|
logger.Log().Debugf("[smtpd] %s (%s) %s", verbLogTranslator(verb), remoteIP, line)
|
||||||
|
@@ -106,7 +106,7 @@ type Server struct {
|
|||||||
MaxSize int // Maximum message size allowed, in bytes
|
MaxSize int // Maximum message size allowed, in bytes
|
||||||
MaxRecipients int // Maximum number of recipients, defaults to 100.
|
MaxRecipients int // Maximum number of recipients, defaults to 100.
|
||||||
MsgIDHandler MsgIDHandler
|
MsgIDHandler MsgIDHandler
|
||||||
SilentlyDropRejectedRecipients bool // Accept emails to rejected recipients with 2xx response but silently drop them
|
IgnoreRejectedRecipients bool // Accept emails to rejected recipients with 2xx response but silently drop them
|
||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
TLSListener bool // Listen for incoming TLS connections only (not recommended as it may reduce compatibility). Ignored if TLS is not configured.
|
TLSListener bool // Listen for incoming TLS connections only (not recommended as it may reduce compatibility). Ignored if TLS is not configured.
|
||||||
@@ -497,7 +497,7 @@ loop:
|
|||||||
if accept {
|
if accept {
|
||||||
to = append(to, match[1])
|
to = append(to, match[1])
|
||||||
s.writef("250 2.1.5 Ok")
|
s.writef("250 2.1.5 Ok")
|
||||||
} else if s.srv.SilentlyDropRejectedRecipients {
|
} else if s.srv.IgnoreRejectedRecipients {
|
||||||
hasRejectedRecipients = true
|
hasRejectedRecipients = true
|
||||||
s.writef("250 2.1.5 Ok")
|
s.writef("250 2.1.5 Ok")
|
||||||
} else {
|
} else {
|
||||||
|
@@ -1622,11 +1622,11 @@ func (m *mockDropRejectedHandler) msgIDHandler(remoteAddr net.Addr, from string,
|
|||||||
return "test-message-id", nil
|
return "test-message-id", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test the SilentlyDropRejectedRecipients option
|
// Test the IgnoreRejectedRecipients option
|
||||||
func TestSilentlyDropRejectedRecipients(t *testing.T) {
|
func TestIgnoreRejectedRecipients(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
silentlyDropRejectedRecipients bool
|
IgnoreRejectedRecipients bool
|
||||||
handlerRcpt func(net.Addr, string, string) bool
|
handlerRcpt func(net.Addr, string, string) bool
|
||||||
rcptCommands []struct{ addr, expectedCode string }
|
rcptCommands []struct{ addr, expectedCode string }
|
||||||
expectedHandlerCalls int
|
expectedHandlerCalls int
|
||||||
@@ -1635,7 +1635,7 @@ func TestSilentlyDropRejectedRecipients(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Disabled_DefaultBehavior",
|
name: "Disabled_DefaultBehavior",
|
||||||
silentlyDropRejectedRecipients: false,
|
IgnoreRejectedRecipients: false,
|
||||||
handlerRcpt: func(remoteAddr net.Addr, from string, to string) bool {
|
handlerRcpt: func(remoteAddr net.Addr, from string, to string) bool {
|
||||||
return !strings.HasSuffix(to, "@rejected.com")
|
return !strings.HasSuffix(to, "@rejected.com")
|
||||||
},
|
},
|
||||||
@@ -1648,7 +1648,7 @@ func TestSilentlyDropRejectedRecipients(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Enabled_MixedRecipients",
|
name: "Enabled_MixedRecipients",
|
||||||
silentlyDropRejectedRecipients: true,
|
IgnoreRejectedRecipients: true,
|
||||||
handlerRcpt: func(remoteAddr net.Addr, from string, to string) bool {
|
handlerRcpt: func(remoteAddr net.Addr, from string, to string) bool {
|
||||||
return !strings.HasSuffix(to, "@rejected.com")
|
return !strings.HasSuffix(to, "@rejected.com")
|
||||||
},
|
},
|
||||||
@@ -1663,7 +1663,7 @@ func TestSilentlyDropRejectedRecipients(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Enabled_AllRejected",
|
name: "Enabled_AllRejected",
|
||||||
silentlyDropRejectedRecipients: true,
|
IgnoreRejectedRecipients: true,
|
||||||
handlerRcpt: func(remoteAddr net.Addr, from string, to string) bool {
|
handlerRcpt: func(remoteAddr net.Addr, from string, to string) bool {
|
||||||
return false // Reject all
|
return false // Reject all
|
||||||
},
|
},
|
||||||
@@ -1676,7 +1676,7 @@ func TestSilentlyDropRejectedRecipients(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Enabled_OnlyValid",
|
name: "Enabled_OnlyValid",
|
||||||
silentlyDropRejectedRecipients: true,
|
IgnoreRejectedRecipients: true,
|
||||||
handlerRcpt: func(remoteAddr net.Addr, from string, to string) bool {
|
handlerRcpt: func(remoteAddr net.Addr, from string, to string) bool {
|
||||||
return strings.HasSuffix(to, "@valid.com")
|
return strings.HasSuffix(to, "@valid.com")
|
||||||
},
|
},
|
||||||
@@ -1690,7 +1690,7 @@ func TestSilentlyDropRejectedRecipients(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Enabled_WithMsgIDHandler",
|
name: "Enabled_WithMsgIDHandler",
|
||||||
silentlyDropRejectedRecipients: true,
|
IgnoreRejectedRecipients: true,
|
||||||
handlerRcpt: func(remoteAddr net.Addr, from string, to string) bool {
|
handlerRcpt: func(remoteAddr net.Addr, from string, to string) bool {
|
||||||
return !strings.HasSuffix(to, "@rejected.com")
|
return !strings.HasSuffix(to, "@rejected.com")
|
||||||
},
|
},
|
||||||
@@ -1713,7 +1713,7 @@ func TestSilentlyDropRejectedRecipients(t *testing.T) {
|
|||||||
AppName: "TestMail",
|
AppName: "TestMail",
|
||||||
MaxRecipients: 100,
|
MaxRecipients: 100,
|
||||||
HandlerRcpt: tt.handlerRcpt,
|
HandlerRcpt: tt.handlerRcpt,
|
||||||
SilentlyDropRejectedRecipients: tt.silentlyDropRejectedRecipients,
|
IgnoreRejectedRecipients: tt.IgnoreRejectedRecipients,
|
||||||
}
|
}
|
||||||
|
|
||||||
if tt.useMsgIDHandler {
|
if tt.useMsgIDHandler {
|
||||||
|
Reference in New Issue
Block a user