Thread (1 message) 1 message, 1 author, 2017-12-18

Re: [PATCH v3] imap-send: URI encode server folder

From: Junio C Hamano <hidden>
Date: 2017-12-18 22:32:30

Kaartic Sivaraam [off-list ref] writes:
From: Nicolas Morey-Chaisemartin <redacted>

When trying to send a patch using 'imap-send' with 'curl' and the
following configuration:

[imap]
	folder = "[Gmail]/Drafts"
	host = imaps://imap.gmail.com
	port = 993
	sslverify = false

results in the following error,

    curl_easy_perform() failed: URL using bad/illegal format or missing URL

This is a consequence of not URI-encoding the folder portion of
the URL which contains characters such as '[' which are not
allowed in a URI. According to RFC3986, these characters should be
URI-encoded.

So, URI-encode the folder before adding it to the URI to ensure it doesn't
contain characters that aren't allowed in a URI.

Reported-by: Doron Behar <redacted>
Signed-off-by: Nicolas Morey-Chaisemartin <redacted>
Signed-off-by: Kaartic Sivaraam <redacted>
---
Changes in v3:
    - updated commit message as suggested by Eric (convert past tense
      to present tense) and added a few tweaks to it that striked me

Eric Sunshine [off-list ref] writes:
quoted
Thanks for taking up the slack.
You're welcome. It was easier than waiting for this patch to be
updated so it could get into 'pu' ;-)
Looks good.  Thanks.

quoted hunk
 imap-send.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/imap-send.c b/imap-send.c
index 54e6a80fd..36c7c1b4f 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1412,6 +1412,7 @@ static CURL *setup_curl(struct imap_server_conf *srvc, struct credential *cred)
 {
 	CURL *curl;
 	struct strbuf path = STRBUF_INIT;
+	char *uri_encoded_folder;
 
 	if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK)
 		die("curl_global_init failed");
@@ -1429,7 +1430,12 @@ static CURL *setup_curl(struct imap_server_conf *srvc, struct credential *cred)
 	strbuf_addstr(&path, server.host);
 	if (!path.len || path.buf[path.len - 1] != '/')
 		strbuf_addch(&path, '/');
-	strbuf_addstr(&path, server.folder);
+
+	uri_encoded_folder = curl_easy_escape(curl, server.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);
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help