Subject: Re: [PATCH] git-imap-send: use libcurl for implementation

From: Junio C Hamano <[email-masked]>
Date: Mon, 10 Nov 2014 09:19:00 -0800

Bernhard Reiter <[email-masked]> writes:

> Am 2014-11-09 um 14:00 schrieb Torsten Bögershausen:
>> On 2014-08-27 00.40, Bernhard Reiter wrote:
>>> Use libcurl's high-level API functions to implement git-imap-send
>>> instead of the previous low-level OpenSSL-based functions.
>>>
>> This doesn't seem to fully work under Debian 7:
>> /home/tb/projects/git/git.pu/imap-send.c:1546: undefined reference
>> to `curl_append_msgs_to_imap'
>
> Thx for the notice. I forgot to guard that with an #ifdef.
>
> The new patch below includes that, and the fix sent by Ramsay;
> hopefully the squashed/edited commit message is fine.

Queued with a small fix-ups, including

 - line-fold a couple of overlong lines;

 - avoid decl-after-stmt of "int prev_len";

 - reduce the scope of "struct struct auth" down to only the block
   it is used;

 - the footer of the log message now reads "helped-by ramsay", your
   sign-off and then mine.

Thanks.

diff --git a/imap-send.c b/imap-send.c
index 08271d9..4dfe4c2 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1349,7 +1349,8 @@ static void git_imap_config(void)
 	git_config_get_string("imap.authmethod", &server.auth_method);
 }
 
-static int append_msgs_to_imap(struct imap_server_conf *server, struct strbuf* all_msgs, int total)
+static int append_msgs_to_imap(struct imap_server_conf *server,
+			       struct strbuf* all_msgs, int total)
 {
 	struct strbuf msg = STRBUF_INIT;
 	struct imap_store *ctx = NULL;
@@ -1391,7 +1392,6 @@ static CURL *setup_curl(struct imap_server_conf *srvc)
 {
 	CURL *curl;
 	struct strbuf path = STRBUF_INIT;
-	struct strbuf auth = STRBUF_INIT;
 
 	if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK)
 		die("curl_global_init failed");
@@ -1414,11 +1414,12 @@ static CURL *setup_curl(struct imap_server_conf *srvc)
 	curl_easy_setopt(curl, CURLOPT_PORT, server.port);
 
 	if (server.auth_method) {
+		struct strbuf auth = STRBUF_INIT;
 		strbuf_addstr(&auth, "AUTH=");
 		strbuf_addstr(&auth, server.auth_method);
 		curl_easy_setopt(curl, CURLOPT_LOGIN_OPTIONS, auth.buf);
+		strbuf_release(&auth);
 	}
-	strbuf_release(&auth);
 
 	if (server.use_ssl)
 		curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
@@ -1436,7 +1437,8 @@ static CURL *setup_curl(struct imap_server_conf *srvc)
 	return curl;
 }
 
-static int curl_append_msgs_to_imap(struct imap_server_conf *server, struct strbuf* all_msgs, int total) {
+static int curl_append_msgs_to_imap(struct imap_server_conf *server,
+				    struct strbuf* all_msgs, int total) {
 	int ofs = 0;
 	int n = 0;
 	struct buffer msgbuf = { STRBUF_INIT, 0 };
@@ -1449,17 +1451,19 @@ static int curl_append_msgs_to_imap(struct imap_server_conf *server, struct strb
 	fprintf(stderr, "sending %d message%s\n", total, (total != 1) ? "s" : "");
 	while (1) {
 		unsigned percent = n * 100 / total;
+		int prev_len;
 
 		fprintf(stderr, "%4u%% (%d/%d) done\r", percent, n, total);
 
-		int prev_len = msgbuf.buf.len;
+		prev_len = msgbuf.buf.len;
 		if (!split_msg(all_msgs, &msgbuf.buf, &ofs))
 			break;
 		if (server->use_html)
 			wrap_in_html(&msgbuf.buf);
 		lf_to_crlf(&msgbuf.buf);
 
-		curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)(msgbuf.buf.len-prev_len));
+		curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
+				 (curl_off_t)(msgbuf.buf.len-prev_len));
 
 		res = curl_easy_perform(curl);