From 1c5db7706997004a166ea23496483a3cf0fa3ead Mon Sep 17 00:00:00 2001 From: Kabeer Ahmed Date: Fri, 13 Nov 2026 10:59:13 +0500 Subject: [PATCH] fix(exterrors): Keep 4.x.x enhanced code for temporary errors in SMTPEnchCode SMTPEnchCode set the class digit to 4 for temporary errors and then unconditionally overwrote it with 5, so every caller got a 5.x.x enhanced code. For remote delivery this produced replies like "451 5.4.0 No usable MXs" where the basic code says retry and the enhanced code says permanent failure. Only set 5 when the error is not temporary. Refs #893 Signed-off-by: Kabeer Ahmed --- framework/exterrors/smtp.go | 3 ++- framework/exterrors/smtp_test.go | 39 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 framework/exterrors/smtp_test.go diff --git a/framework/exterrors/smtp.go b/framework/exterrors/smtp.go index 01e16f42..7236f5b6 100644 --- a/framework/exterrors/smtp.go +++ b/framework/exterrors/smtp.go @@ -140,7 +140,8 @@ func SMTPCode(err error, temporaryCode, permanentCode int) int { func SMTPEnchCode(err error, code EnhancedCode) EnhancedCode { if IsTemporary(err) { code[0] = 4 + } else { + code[0] = 5 } - code[0] = 5 return code } diff --git a/framework/exterrors/smtp_test.go b/framework/exterrors/smtp_test.go new file mode 100644 index 00000000..56179ff5 --- /dev/null +++ b/framework/exterrors/smtp_test.go @@ -0,0 +1,39 @@ +/* +Maddy Mail Server - Composable all-in-one email server. +Copyright © 2019-2020 Max Mazurov , Maddy Mail Server contributors + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +package exterrors + +import ( + "errors" + "testing" +) + +func TestSMTPEnchCode(t *testing.T) { + temp := WithTemporary(errors.New("temp"), true) + perm := WithTemporary(errors.New("perm"), false) + + if got := SMTPEnchCode(temp, EnhancedCode{0, 4, 0}); got != (EnhancedCode{4, 4, 0}) { + t.Errorf("temporary error: got %v, want 4.4.0", got) + } + if got := SMTPEnchCode(perm, EnhancedCode{0, 4, 0}); got != (EnhancedCode{5, 4, 0}) { + t.Errorf("permanent error: got %v, want 5.4.0", got) + } + if got := SMTPEnchCode(errors.New("plain"), EnhancedCode{0, 4, 0}); got != (EnhancedCode{5, 4, 0}) { + t.Errorf("plain error: got %v, want 5.4.0", got) + } +}