diff --git a/cmd/root.go b/cmd/root.go index 338efaf..7483e4c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -100,6 +100,7 @@ func init() { rootCmd.Flags().StringVar(&config.SMTPTLSCert, "smtp-tls-cert", config.SMTPTLSCert, "TLS certificate for SMTP (STARTTLS) - requires smtp-tls-key") rootCmd.Flags().StringVar(&config.SMTPTLSKey, "smtp-tls-key", config.SMTPTLSKey, "TLS key for SMTP (STARTTLS) - requires smtp-tls-cert") rootCmd.Flags().BoolVar(&config.SMTPAuthAllowInsecure, "smtp-auth-allow-insecure", config.SMTPAuthAllowInsecure, "Enable insecure PLAIN & LOGIN authentication") + rootCmd.Flags().BoolVar(&config.SMTPStrictRFCHeaders, "smtp-strict-rfc-headers", config.SMTPStrictRFCHeaders, "Return SMTP error if message headers contain ") rootCmd.Flags().StringVar(&config.SMTPRelayConfigFile, "smtp-relay-config", config.SMTPRelayConfigFile, "SMTP configuration file to allow releasing messages") rootCmd.Flags().BoolVar(&config.SMTPRelayAllIncoming, "smtp-relay-all", config.SMTPRelayAllIncoming, "Relay all incoming messages via external SMTP server (caution!)") @@ -185,6 +186,9 @@ func initConfigFromEnv() { if getEnabledFromEnv("MP_SMTP_AUTH_ALLOW_INSECURE") { config.SMTPAuthAllowInsecure = true } + if getEnabledFromEnv("MP_STRICT_RFC_HEADERS") { + config.SMTPStrictRFCHeaders = true + } // Relay server config if len(os.Getenv("MP_SMTP_RELAY_CONFIG")) > 0 { diff --git a/config/config.go b/config/config.go index 072b0f9..fe18ea9 100644 --- a/config/config.go +++ b/config/config.go @@ -90,6 +90,10 @@ var ( // SMTPRelayConfig to parse a yaml file and store config of relay SMTP server SMTPRelayConfig smtpRelayConfigStruct + // SMTPStrictRFCHeaders will return an error if the email headers contain (\r\r\n) + // @see https://github.com/axllent/mailpit/issues/87 & https://github.com/axllent/mailpit/issues/153 + SMTPStrictRFCHeaders bool + // ReleaseEnabled is whether message releases are enabled, requires a valid SMTPRelayConfigFile ReleaseEnabled = false diff --git a/server/smtpd/smtpd.go b/server/smtpd/smtpd.go index 67b2aa2..d78f4a5 100644 --- a/server/smtpd/smtpd.go +++ b/server/smtpd/smtpd.go @@ -17,6 +17,12 @@ import ( ) func mailHandler(origin net.Addr, from string, to []string, data []byte) error { + if !config.SMTPStrictRFCHeaders { + // replace all (\r\r\n) with (\r\n) + // @see https://github.com/axllent/mailpit/issues/87 & https://github.com/axllent/mailpit/issues/153 + data = bytes.ReplaceAll(data, []byte("\r\r\n"), []byte("\r\n")) + } + msg, err := mail.ReadMessage(bytes.NewReader(data)) if err != nil { logger.Log().Errorf("[smtpd] error parsing message: %s", err.Error())