From: Pietro Cerutti Date: Wed, 25 Apr 2018 15:10:16 +0000 (+0000) Subject: Do not stop trying to log into an IMAP server at the first NO X-Git-Tag: neomutt-20180512~18 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=37c4ccd7ae4f81bf56fa79d83b520df368f90324;p=neomutt Do not stop trying to log into an IMAP server at the first NO Issue #1166 --- diff --git a/imap/auth.c b/imap/auth.c index b4ab2fe4e..53f4016e6 100644 --- a/imap/auth.c +++ b/imap/auth.c @@ -53,8 +53,6 @@ static const struct ImapAuth imap_authenticators[] = { { imap_auth_cram_md5, "cram-md5" }, #endif { imap_auth_login, "login" }, - - { NULL, NULL }, }; /** @@ -67,18 +65,17 @@ static const struct ImapAuth imap_authenticators[] = { */ int imap_authenticate(struct ImapData *idata) { - const struct ImapAuth *authenticator = NULL; - char *methods = NULL; - char *method = NULL; - char *delim = NULL; - int r = IMAP_AUTH_UNAVAIL; + int r = IMAP_AUTH_FAILURE; if (ImapAuthenticators && *ImapAuthenticators) { + mutt_debug(2, "Trying user-defined imap_authenticators.\n"); + /* Try user-specified list of authentication methods */ - methods = mutt_str_strdup(ImapAuthenticators); + char *methods = mutt_str_strdup(ImapAuthenticators); + char *delim = NULL; - for (method = methods; method; method = delim) + for (const char *method = methods; method; method = delim) { delim = strchr(method, ':'); if (delim) @@ -87,22 +84,19 @@ int imap_authenticate(struct ImapData *idata) continue; mutt_debug(2, "Trying method %s\n", method); - authenticator = imap_authenticators; - while (authenticator->authenticate) + for (size_t i = 0; i < mutt_array_size(imap_authenticators); ++i) { - if (!authenticator->method || - (mutt_str_strcasecmp(authenticator->method, method) == 0)) + const struct ImapAuth *auth = &imap_authenticators[i]; + if (!auth->method || (mutt_str_strcasecmp(auth->method, method) == 0)) { - r = authenticator->authenticate(idata, method); - if (r != IMAP_AUTH_UNAVAIL) + r = auth->authenticate(idata, method); + if (r == IMAP_AUTH_SUCCESS) { FREE(&methods); return r; } } - - authenticator++; } } @@ -111,22 +105,16 @@ int imap_authenticate(struct ImapData *idata) else { /* Fall back to default: any authenticator */ - mutt_debug(2, "Using any available method.\n"); - authenticator = imap_authenticators; + mutt_debug(2, "Trying pre-defined imap_authenticators.\n"); - while (authenticator->authenticate) + for (size_t i = 0; i < mutt_array_size(imap_authenticators); ++i) { - r = authenticator->authenticate(idata, NULL); - if (r != IMAP_AUTH_UNAVAIL) + r = imap_authenticators[i].authenticate(idata, NULL); + if (r == IMAP_AUTH_SUCCESS) return r; - authenticator++; } } - if (r == IMAP_AUTH_UNAVAIL) - { - mutt_error(_("No authenticators available")); - } - + mutt_error(_("No authenticators available or wrong credentials")); return r; }