imap-send: use server conf argument in setup_curl()

Our caller passes in an imap_server_conf struct, but we ignore it totally, and instead read the config directly from the global "server" variable. This works OK, since our sole caller will pass in that same global variable. But the intent seems to have been to use the passed-in variable, as otherwise it has no purpose (and many other functions use the same pattern). Let's use the passed-in value, which also silences a -Wunused-parameter warning. It would be nice if "server" was not a global here, as we could avoid making similar mistakes. But changing that would be a larger refactor, as it must be accessed as a global in a few spots (e.g., filling it in with the config callback). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jul 3, 2023 at 02:33 UTC 84d689a810842c44d95ac759d39702dfa170093b
1 file changed +12 -12
imap-send.c
+12 -12
@@ -1415,16 +1415,16 @@ static CURL *setup_curl(struct imap_server_conf *srvc, struct credential *cred)
1415 if (!curl)
1416 die("curl_easy_init failed");
1417
1418 - server_fill_credential(&server, cred);
1419 - curl_easy_setopt(curl, CURLOPT_USERNAME, server.user);
1420 - curl_easy_setopt(curl, CURLOPT_PASSWORD, server.pass);
1418 + server_fill_credential(srvc, cred);
1419 + curl_easy_setopt(curl, CURLOPT_USERNAME, srvc->user);
1420 + curl_easy_setopt(curl, CURLOPT_PASSWORD, srvc->pass);
1421
1422 - strbuf_addstr(&path, server.use_ssl ? "imaps://" : "imap://");
1423 - strbuf_addstr(&path, server.host);
1422 + strbuf_addstr(&path, srvc->use_ssl ? "imaps://" : "imap://");
1423 + strbuf_addstr(&path, srvc->host);
1424 if (!path.len || path.buf[path.len - 1] != '/')
1425 strbuf_addch(&path, '/');
1426
1427 - uri_encoded_folder = curl_easy_escape(curl, server.folder, 0);
1427 + uri_encoded_folder = curl_easy_escape(curl, srvc->folder, 0);
1428 if (!uri_encoded_folder)
1429 die("failed to encode server folder");
1430 strbuf_addstr(&path, uri_encoded_folder);
@@ -1432,25 +1432,25 @@ static CURL *setup_curl(struct imap_server_conf *srvc, struct credential *cred)
1432
1433 curl_easy_setopt(curl, CURLOPT_URL, path.buf);
1434 strbuf_release(&path);
1435 - curl_easy_setopt(curl, CURLOPT_PORT, server.port);
1435 + curl_easy_setopt(curl, CURLOPT_PORT, srvc->port);
1436
1437 - if (server.auth_method) {
1437 + if (srvc->auth_method) {
1438 #ifndef GIT_CURL_HAVE_CURLOPT_LOGIN_OPTIONS
1439 warning("No LOGIN_OPTIONS support in this cURL version");
1440 #else
1441 struct strbuf auth = STRBUF_INIT;
1442 strbuf_addstr(&auth, "AUTH=");
1443 - strbuf_addstr(&auth, server.auth_method);
1443 + strbuf_addstr(&auth, srvc->auth_method);
1444 curl_easy_setopt(curl, CURLOPT_LOGIN_OPTIONS, auth.buf);
1445 strbuf_release(&auth);
1446 #endif
1447 }
1448
1449 - if (!server.use_ssl)
1449 + if (!srvc->use_ssl)
1450 curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_TRY);
1451
1452 - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, server.ssl_verify);
1453 - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, server.ssl_verify);
1452 + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, srvc->ssl_verify);
1453 + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, srvc->ssl_verify);
1454
1455 curl_easy_setopt(curl, CURLOPT_READFUNCTION, fread_buffer);
1456