This commit is contained in:
Darren Hoo 2025-05-14 00:47:56 +09:00 committed by GitHub
commit aaac94dcdb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -42,16 +42,13 @@ func (source *Source) Authenticate(ctx context.Context, user *user_model.User, u
} }
if err := Authenticate(auth, source); err != nil { if err := Authenticate(auth, source); err != nil {
// Check standard error format first, // when authentication via smtp fails, wraps ErrInvalidArgument
// then fallback to worse case. // with the original textproto.Error as the cause,
tperr, ok := err.(*textproto.Error) // so it will show username_password_incorrect to the user
if (ok && tperr.Code == 535) || // while log the original error so that admin can check.
strings.Contains(err.Error(), "Username and Password not accepted") { // see: routers/web/auth/auth.go SiginPost
return nil, user_model.ErrUserNotExist{Name: userName} if tperr, ok := err.(*textproto.Error); ok {
} return nil, errors.Join(util.ErrInvalidArgument, tperr)
if (ok && tperr.Code == 534) ||
strings.Contains(err.Error(), "Application-specific password required") {
return nil, user_model.ErrUserNotExist{Name: userName}
} }
return nil, err return nil, err
} }