@@ -1419,7 +1419,7 @@ sub smtp_auth_maybe {
die "invalid smtp auth: '${smtp_auth}'";
}
- # TODO: Authentication may fail not because credentials were
+ # Authentication may fail not because credentials were
# invalid but due to other reasons, in which we should not
# reject credentials.
$auth = Git::credential({
@@ -1431,25 +1431,32 @@ sub smtp_auth_maybe {
'password' => $smtp_authpass
}, sub {
my $cred = shift;
+ my $result;
+ my $error;
+
+ # catch all SMTP auth error in a unified eval block
+ eval {
+ if ($smtp_auth) {
+ my $sasl = Authen::SASL->new(
+ mechanism => $smtp_auth,
+ callback => {
+ user => $cred->{'username'},
+ pass => $cred->{'password'},
+ authname => $cred->{'username'},
+ }
+ );
+ $result = $smtp->auth($sasl);
+ } else {
+ $result = $smtp->auth($cred->{'username'}, $cred->{'password'});
+ }
+ 1; # ensure true value is returned if no exception is thrown
+ } or do {
+ $error = $@ || 'Unknown error';
+ };
- if ($smtp_auth) {
- my $sasl = Authen::SASL->new(
- mechanism => $smtp_auth,
- callback => {
- user => $cred->{'username'},
- pass => $cred->{'password'},
- authname => $cred->{'username'},
- }
- );
-
- return !!$smtp->auth($sasl);
- }
-
- return !!$smtp->auth($cred->{'username'}, $cred->{'password'});
- });
-
- return $auth;
-}
+ # NOTE: SMTP status code handling will be added in a subsequent commit
+ return $result ? 1 : 0;
+ }
sub ssl_verify_params {
eval {
Auth relied solely on return values without catching errors, misjudging non-credential errors as auth failures without details. Wrap the entire auth process in an eval {} block to catch all exceptions, including non-credential errors. Add $error to store exceptions for future handling and $result for auth results. Uses 'or do' to replace direct returns. Merges if/else branches, integrates SASL and basic auth, with comments for future status code handling. Signed-off-by: Zheng Yuting <05ZYT30@gmail.com> --- git-send-email.perl | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) -- 2.48.1