From: Nicolas Morey-Chaisemartin Date: Tue, 08 Aug 2017 07:48:19 GMT Subject: [PATCHv2 2/4] imap-send: add wrapper to get server credentials if needed Message-ID: <19196543-f4ac-0584-6916-fd414c377eb1@morey-chaisemartin.com> In-Reply-To: <3637fd31-3120-eca0-b7ee-8e6e324b6b58@morey-chaisemartin.com> Signed-off-by: Nicolas Morey-Chaisemartin --- imap-send.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/imap-send.c b/imap-send.c index 09f29ea95..448a4a0b3 100644 --- a/imap-send.c +++ b/imap-send.c @@ -926,6 +926,25 @@ static int auth_cram_md5(struct imap_store *ctx, struct imap_cmd *cmd, const cha return 0; } +static void server_fill_credential(struct imap_server_conf *srvc, struct credential *cred) +{ + if (srvc->user && srvc->pass) + return; + + cred->protocol = xstrdup(srvc->use_ssl ? "imaps" : "imap"); + cred->host = xstrdup(srvc->host); + + cred->username = xstrdup_or_null(srvc->user); + cred->password = xstrdup_or_null(srvc->pass); + + credential_fill(cred); + + if (!srvc->user) + srvc->user = xstrdup(cred->username); + if (!srvc->pass) + srvc->pass = xstrdup(cred->password); +} + static struct imap_store *imap_open_store(struct imap_server_conf *srvc, char *folder) { struct credential cred = CREDENTIAL_INIT; @@ -1078,20 +1097,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, char *f } #endif imap_info("Logging in...\n"); - if (!srvc->user || !srvc->pass) { - cred.protocol = xstrdup(srvc->use_ssl ? "imaps" : "imap"); - cred.host = xstrdup(srvc->host); - - cred.username = xstrdup_or_null(srvc->user); - cred.password = xstrdup_or_null(srvc->pass); - - credential_fill(&cred); - - if (!srvc->user) - srvc->user = xstrdup(cred.username); - if (!srvc->pass) - srvc->pass = xstrdup(cred.password); - } + server_fill_credential(srvc, &cred); if (srvc->auth_method) { struct imap_cmd_cb cb; -- 2.14.0.rc1.16.gcc208c97c