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) + } +}