# [GSoC PATCH v2 0/1] improve smtp auth error handling logic

3 messages from 2025-03-11 to 2025-03-11. Participants: Zheng Yuting, Yuting Zheng.
Thread: https://gitlist.dev/t/63091

## Zheng Yuting, 2025-03-11 06:24

Subject: [GSoC PATCH v2 0/1] improve smtp auth error handling logic
Message-ID: <20250311062440.3566116-1-05ZYT30@gmail.com>
URL: https://gitlist.dev/e/20250311062440.3566116-1-05ZYT30%40gmail.com

```
This patch enhances error handling in the smtp_auth_maybe() function by
distinguishing between temporary errors and permanent authentication
failures.

Zheng Yuting (1):
  improve smtp authentication error handling logic

 git-send-email.perl | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

--
2.49.0.rc0.57.gdb91954e18

```

## Zheng Yuting, 2025-03-11 06:24

Subject: [GSoC PATCH v2 1/1] improve smtp authentication error handling logic
Message-ID: <20250311062440.3566116-2-05ZYT30@gmail.com>
URL: https://gitlist.dev/e/20250311062440.3566116-2-05ZYT30%40gmail.com
In-Reply-To: <20250311062440.3566116-1-05ZYT30@gmail.com>

```
---
 git-send-email.perl | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index 798d59b84f..a012d61abb 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1419,19 +1419,19 @@ 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({
 		'protocol' => 'smtp',
 		'host' => smtp_host_string(),
 		'username' => $smtp_authuser,
-		# if there's no password, "git credential fill" will
-		# give us one, otherwise it'll just pass this one.
 		'password' => $smtp_authpass
+
 	}, sub {
 		my $cred = shift;
-
+		my $result;
+		my $error;
 		if ($smtp_auth) {
 			my $sasl = Authen::SASL->new(
 				mechanism => $smtp_auth,
@@ -1441,13 +1441,27 @@ sub smtp_auth_maybe {
 					authname => $cred->{'username'},
 				}
 			);
-
 			return !!$smtp->auth($sasl);
+		} else {
+			# Handle plain authentication errors
+			eval {
+				$result = $smtp->auth($cred->{'username'}, $cred->{'password'});
+				1; # Ensure true value is returned
+			} or do {
+				$error = $@ || 'Unknown error';
+			};
 		}
-
-		return !!$smtp->auth($cred->{'username'}, $cred->{'password'});
+		# Unified error handling logic
+		if ($error) {
+			# Match temporary errors
+			if ($error =~ /timeout|temporary|greylist|throttled|quota\s+exceeded|queue|overload|try\s+again|connection\s+lost|network\s+error/i) {
+				warn "SMTP temporary error: $error";
+				return 1;
+			}
+			return 0;
+		}
+		return !!$result;
 	});
-
 	return $auth;
 }

--
2.49.0.rc0.57.gdb91954e18

```

## Yuting Zheng, 2025-03-11 06:49

Subject: Re: [GSoC PATCH v2 1/1] improve smtp authentication error handling logic
Message-ID: <CAMvj1+r4K4ppX4GC_-1R5TjfhGcGGH6ccT5V51w-QS8nS+LZwA@mail.gmail.com>
URL: https://gitlist.dev/e/CAMvj1%2Br4K4ppX4GC_-1R5TjfhGcGGH6ccT5V51w-QS8nS%2BLZwA%40mail.gmail.com
In-Reply-To: <20250311062440.3566116-2-05ZYT30@gmail.com>

```
Hi everyone,

I am a new contributor; please forgive my mistake.
I mistakenly released the v2 patch without any code changes.
Please disregard this version and avoid reverting based on it.
I will release a corrected patch with the intended updates shortly.

Apologies for any inconvenience.

Best regards,
Zheng Yuting

On Tue, Mar 11, 2025 at 2:25 PM Zheng Yuting <05zyt30@gmail.com> wrote:
>
> ---
>  git-send-email.perl | 30 ++++++++++++++++++++++--------
>  1 file changed, 22 insertions(+), 8 deletions(-)
>
> diff --git a/git-send-email.perl b/git-send-email.perl
> index 798d59b84f..a012d61abb 100755
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -1419,19 +1419,19 @@ 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({
>                 'protocol' => 'smtp',
>                 'host' => smtp_host_string(),
>                 'username' => $smtp_authuser,
> -               # if there's no password, "git credential fill" will
> -               # give us one, otherwise it'll just pass this one.
>                 'password' => $smtp_authpass
> +
>         }, sub {
>                 my $cred = shift;
> -
> +               my $result;
> +               my $error;
>                 if ($smtp_auth) {
>                         my $sasl = Authen::SASL->new(
>                                 mechanism => $smtp_auth,
> @@ -1441,13 +1441,27 @@ sub smtp_auth_maybe {
>                                         authname => $cred->{'username'},
>                                 }
>                         );
> -
>                         return !!$smtp->auth($sasl);
> +               } else {
> +                       # Handle plain authentication errors
> +                       eval {
> +                               $result = $smtp->auth($cred->{'username'}, $cred->{'password'});
> +                               1; # Ensure true value is returned
> +                       } or do {
> +                               $error = $@ || 'Unknown error';
> +                       };
>                 }
> -
> -               return !!$smtp->auth($cred->{'username'}, $cred->{'password'});
> +               # Unified error handling logic
> +               if ($error) {
> +                       # Match temporary errors
> +                       if ($error =~ /timeout|temporary|greylist|throttled|quota\s+exceeded|queue|overload|try\s+again|connection\s+lost|network\s+error/i) {
> +                               warn "SMTP temporary error: $error";
> +                               return 1;
> +                       }
> +                       return 0;
> +               }
> +               return !!$result;
>         });
> -
>         return $auth;
>  }
>
> --
> 2.49.0.rc0.57.gdb91954e18

```
