From 53e5f6904c5d491485edec6d1b4c965aed26054b Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Mon, 10 Jun 2019 20:41:48 +0100 Subject: [PATCH] smtp_authenticators -> slist Convert `$smtp_authenticators` to use the new DT_SLIST type (string list). --- init.h | 2 +- smtp.c | 31 ++++++++++--------------------- smtp.h | 2 +- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/init.h b/init.h index 709796709..95fe1e5ce 100644 --- a/init.h +++ b/init.h @@ -4054,7 +4054,7 @@ struct ConfigDef MuttVars[] = { */ #endif #ifdef USE_SMTP - { "smtp_authenticators", DT_STRING, &C_SmtpAuthenticators, 0 }, + { "smtp_authenticators", DT_SLIST|SLIST_SEP_COLON, &C_SmtpAuthenticators, 0 }, /* ** .pp ** This is a colon-delimited list of authentication methods NeoMutt may diff --git a/smtp.c b/smtp.c index 444e3067f..8dc942a95 100644 --- a/smtp.c +++ b/smtp.c @@ -56,7 +56,7 @@ #endif /* These Config Variables are only used in smtp.c */ -char *C_SmtpAuthenticators; ///< Config: (smtp) List of allowed authentication methods +struct Slist *C_SmtpAuthenticators; ///< Config: (smtp) List of allowed authentication methods #define smtp_success(x) ((x) / 100 == 2) #define SMTP_READY 334 @@ -589,47 +589,36 @@ static int smtp_auth(struct Connection *conn) if (C_SmtpAuthenticators) { - char *methods = mutt_str_strdup(C_SmtpAuthenticators); - char *method = NULL; - char *delim = NULL; - - for (method = methods; method; method = delim) + struct ListNode *np = NULL; + STAILQ_FOREACH(np, &C_SmtpAuthenticators->head, entries) { - delim = strchr(method, ':'); - if (delim) - *delim++ = '\0'; - if (method[0] == '\0') - continue; + mutt_debug(LL_DEBUG2, "Trying method %s\n", np->data); - mutt_debug(LL_DEBUG2, "Trying method %s\n", method); - - if (strcmp(method, "oauthbearer") == 0) + if (strcmp(np->data, "oauthbearer") == 0) { r = smtp_auth_oauth(conn); } - else if (strcmp(method, "plain") == 0) + else if (strcmp(np->data, "plain") == 0) { r = smtp_auth_plain(conn); } else { #ifdef USE_SASL - r = smtp_auth_sasl(conn, method); + r = smtp_auth_sasl(conn, np->data); #else - mutt_error(_("SMTP authentication method %s requires SASL"), method); + mutt_error(_("SMTP authentication method %s requires SASL"), np->data); continue; #endif } - if ((r == SMTP_AUTH_FAIL) && delim) + if ((r == SMTP_AUTH_FAIL) && (C_SmtpAuthenticators->count > 1)) { - mutt_error(_("%s authentication failed, trying next method"), method); + mutt_error(_("%s authentication failed, trying next method"), np->data); } else if (r != SMTP_AUTH_UNAVAIL) break; } - - FREE(&methods); } else { diff --git a/smtp.h b/smtp.h index cf74ed8b3..a6476c2ad 100644 --- a/smtp.h +++ b/smtp.h @@ -27,7 +27,7 @@ struct AddressList; /* These Config Variables are only used in smtp.c */ -extern char *C_SmtpAuthenticators; +extern struct Slist *C_SmtpAuthenticators; #ifdef USE_SMTP int mutt_smtp_send(const struct AddressList *from, const struct AddressList *to, -- 2.40.0