@@ -1454,9 +1454,30 @@ sub smtp_auth_maybe {
$error = $@ || 'Unknown error';
};
- # NOTE: SMTP status code handling will be added in a subsequent commit
- return $result ? 1 : 0;
- }
+ # check if an error was captured
+ if ($error) {
+ # parse SMTP status code from error message in:
+ # https://www.rfc-editor.org/rfc/rfc5321.html
+ if ($error =~ /\b(\d{3})\b/) {
+ my $status_code = $1;
+ if ($status_code =~ /^4/) {
+ # 4yz: Transient Negative Completion reply
+ warn "SMTP temporary error (status code $status_code): $error";
+ return 1;
+ } elsif ($status_code =~ /^5/) {
+ # 5yz: Permanent Negative Completion reply
+ warn "SMTP permanent error (status code $status_code): $error";
+ return 0;
+ }
+ # if no recognized status code is found, treat as permanent error
+ warn "SMTP unknown error: $error";
+ return 0;
+ }
+ return $result ? 1 : 0;
+ } else {
+ return $result ? 1 : 0;
+ }
+}
sub ssl_verify_params {
eval {
Code captured errors but did not process them further. This treated all failures the same without distinguishing SMTP status. Add a regex to extract status codes as defined in RFC 5321: - For 4yz (temporary errors), return 1 and allow retries. - For 5yz (permanent errors), return 0 as failure. - For unrecognized codes, treat as permanent errors. - If no error occurs, return the authentication result. Signed-off-by: Zheng Yuting <05ZYT30@gmail.com> --- git-send-email.perl | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) -- 2.48.1