git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] imap-send: use server conf argument in setup_curl()

From
Jeff King <peff@peff.net>
Date
Jul 3, 2023, 06:33 UTC
Message-ID
<20230703063330.GA3524421@coredump.intra.peff.net>
In-Reply-To
<20230703063247.GA3524302@coredump.intra.peff.net>

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>
---
 imap-send.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/imap-send.c b/imap-send.c
index 7f5426177a..0afd88de44 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1415,42 +1415,42 @@ static CURL *setup_curl(struct imap_server_conf *srvc, struct credential *cred)
 	if (!curl)
 		die("curl_easy_init failed");
 
-	server_fill_credential(&server, cred);
-	curl_easy_setopt(curl, CURLOPT_USERNAME, server.user);
-	curl_easy_setopt(curl, CURLOPT_PASSWORD, server.pass);
+	server_fill_credential(srvc, cred);
+	curl_easy_setopt(curl, CURLOPT_USERNAME, srvc->user);
+	curl_easy_setopt(curl, CURLOPT_PASSWORD, srvc->pass);
 
-	strbuf_addstr(&path, server.use_ssl ? "imaps://" : "imap://");
-	strbuf_addstr(&path, server.host);
+	strbuf_addstr(&path, srvc->use_ssl ? "imaps://" : "imap://");
+	strbuf_addstr(&path, srvc->host);
 	if (!path.len || path.buf[path.len - 1] != '/')
 		strbuf_addch(&path, '/');
 
-	uri_encoded_folder = curl_easy_escape(curl, server.folder, 0);
+	uri_encoded_folder = curl_easy_escape(curl, srvc->folder, 0);
 	if (!uri_encoded_folder)
 		die("failed to encode server folder");
 	strbuf_addstr(&path, uri_encoded_folder);
 	curl_free(uri_encoded_folder);
 
 	curl_easy_setopt(curl, CURLOPT_URL, path.buf);
 	strbuf_release(&path);
-	curl_easy_setopt(curl, CURLOPT_PORT, server.port);
+	curl_easy_setopt(curl, CURLOPT_PORT, srvc->port);
 
-	if (server.auth_method) {
+	if (srvc->auth_method) {
 #ifndef GIT_CURL_HAVE_CURLOPT_LOGIN_OPTIONS
 		warning("No LOGIN_OPTIONS support in this cURL version");
 #else
 		struct strbuf auth = STRBUF_INIT;
 		strbuf_addstr(&auth, "AUTH=");
-		strbuf_addstr(&auth, server.auth_method);
+		strbuf_addstr(&auth, srvc->auth_method);
 		curl_easy_setopt(curl, CURLOPT_LOGIN_OPTIONS, auth.buf);
 		strbuf_release(&auth);
 #endif
 	}
 
-	if (!server.use_ssl)
+	if (!srvc->use_ssl)
 		curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_TRY);
 
-	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, server.ssl_verify);
-	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, server.ssl_verify);
+	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, srvc->ssl_verify);
+	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, srvc->ssl_verify);
 
 	curl_easy_setopt(curl, CURLOPT_READFUNCTION, fread_buffer);
 
-- 
2.41.0.586.g3c0cc15bc7
Previous: Jeff KingNext: Junio C Hamano
Message 2 of 7 in “imap-send: some -Wunused-parameter cleanups”
  1. 0/3 imap-send: some -Wunused-parameter cleanupsJeff King, Jul 3, 2023
  2. 1/3 imap-send: use server conf argument in setup_curl()Jeff King, Jul 3, 2023
  3. Junio C HamanoJul 5, 2023
  4. 2/3 imap-send: drop unused parameter from imap_cmd_cb callbackJeff King, Jul 3, 2023
  5. Junio C HamanoJul 5, 2023
  6. 3/3 imap-send: drop unused fields from imap_cmd_cbJeff King, Jul 3, 2023
  7. Junio C HamanoJul 5, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.