Skip to content

Commit 77eac3f

Browse files
nmoreygitster
authored andcommitted
imap-send: URI encode server folder
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 <[email protected]> Signed-off-by: Nicolas Morey-Chaisemartin <[email protected]> Signed-off-by: Kaartic Sivaraam <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 52015aa commit 77eac3f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

imap-send.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,7 @@ static CURL *setup_curl(struct imap_server_conf *srvc, struct credential *cred)
14121412
{
14131413
CURL *curl;
14141414
struct strbuf path = STRBUF_INIT;
1415+
char *uri_encoded_folder;
14151416

14161417
if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK)
14171418
die("curl_global_init failed");
@@ -1429,7 +1430,12 @@ static CURL *setup_curl(struct imap_server_conf *srvc, struct credential *cred)
14291430
strbuf_addstr(&path, server.host);
14301431
if (!path.len || path.buf[path.len - 1] != '/')
14311432
strbuf_addch(&path, '/');
1432-
strbuf_addstr(&path, server.folder);
1433+
1434+
uri_encoded_folder = curl_easy_escape(curl, server.folder, 0);
1435+
if (!uri_encoded_folder)
1436+
die("failed to encode server folder");
1437+
strbuf_addstr(&path, uri_encoded_folder);
1438+
curl_free(uri_encoded_folder);
14331439

14341440
curl_easy_setopt(curl, CURLOPT_URL, path.buf);
14351441
strbuf_release(&path);

0 commit comments

Comments
 (0)