aboutsummaryrefslogtreecommitdiffstats
path: root/git-send-email.perl
diff options
context:
space:
mode:
Diffstat (limited to 'git-send-email.perl')
-rwxr-xr-xgit-send-email.perl32
1 files changed, 29 insertions, 3 deletions
diff --git a/git-send-email.perl b/git-send-email.perl
index 0f05f55e50..1f613fa979 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1454,14 +1454,40 @@ sub smtp_auth_maybe {
$error = $@ || 'Unknown error';
};
- # NOTE: SMTP status code handling will be added in a subsequent commit,
- # return 1 when failed due to non-credential reasons
- return $error ? 1 : ($result ? 1 : 0);
+ return ($error
+ ? handle_smtp_error($error)
+ : ($result ? 1 : 0));
});
return $auth;
}
+sub handle_smtp_error {
+ my ($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 transient 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 transient error
+ warn "SMTP unknown error: $error. Treating as transient failure.";
+ return 1;
+ }
+
+ # If no status code is found, treat as transient error
+ warn "SMTP generic error: $error";
+ return 1;
+}
+
sub ssl_verify_params {
eval {
require IO::Socket::SSL;