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

[PATCH v2] imap-send: URI encode server folder

From
Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Date
Dec 18, 2017, 18:25 UTC
Message-ID
<20171218182546.9962-1-kaartic.sivaraam@gmail.com>
In-Reply-To
<CAPig+cSEYHfupRt+-0sZK6H3_WcT_=wdNB2FfdYuB6geGQYZ3A@mail.gmail.com>
From: Nicolas Morey-Chaisemartin <nmoreychaisemartin@suse.com>

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
resulted in the following error,
    curl_easy_perform() failed: URL using bad/illegal format or missing URL

That was a consequence of the not URI encoding the folder portion of the URL which contained characters such as '[' which are not allowed in a URI. According to RFC3986, these characters should be "URI encoded".

So, URI encode the folder portion of the URL to ensure it doesn't contain characters that aren't allowed in a URI.

Reported-by: Doron Behar <doron.behar@gmail.com>
Signed-off-by: Nicolas Morey-Chaisemartin <NMoreyChaisemartin@suse.com>
---

I came across the same issue that lead to this patch recently and found that this patch didn't make it in. So, I thought I could help out and hence this v2.

Eric Sunshine <sunshine@sunshineco.com> writes:
Show 7 quoted lines
> For someone reading this commit message in the future -- someone who
> didn't follow the email thread which led to this patch -- "this fixes"
> doesn't say much about the actual problem being addressed. Can you
> expand the commit message a bit to make it more self-contained? At
> minimum, perhaps show the error message you were experiencing, and
> cite (as Daniel pointed out) RFC 3986 and the bit about a "legal" URL
> not containing brackets.
I guess I covered this part.
Show 8 quoted lines
> Also, a natural question which pops into the head of someone reading
> this patch is whether other parts of the URL (host, user, etc.) also
> need to be handled similarly. It's possible that you audited the code
> and determined that they are handled fine already, but the reader of
> the commit message is unable to infer that. Consequently, it might be
> nice to have a sentence about that, as well ("other parts of the URL
> are already encoded, thus are fine" or "other parts of the URL are not
> subject to this problem because ...").

I'm not sure about this one. I guess the host and user don't need encoding as I suspect they wouldn't contain characters that aren't allowed. I might be wrong, though. Let me know if I'm missing something.

Thanks, Kaartic

 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);
-- 
2.15.1.620.gb9897f467
Previous: Junio C HamanoNext: Eric Sunshine
Message 13 of 17 in “imap-send with gmail: curl_easy_perform() failed: URL using bad/illegal format or missing URL”
  1. Doron BeharNov 29, 2017
  2. Jonathan NiederNov 30, 2017
  3. Jeff KingNov 30, 2017
  4. Jeff KingNov 30, 2017
  5. Nicolas Morey-ChaisemartinNov 30, 2017
  6. Nicolas Morey-ChaisemartinNov 30, 2017
  7. Daniel StenbergNov 30, 2017
  8. Nicolas Morey-ChaisemartinNov 30, 2017
  9. Daniel StenbergNov 30, 2017
  10. imap-send: URI encode server folderNicolas Morey-Chaisemartin, Nov 30, 2017
  11. Eric SunshineNov 30, 2017
  12. Junio C HamanoDec 5, 2017
  13. imap-send: URI encode server folderKaartic Sivaraam, Dec 18, 2017
  14. Eric SunshineDec 18, 2017
  15. imap-send: URI encode server folderKaartic Sivaraam, Dec 18, 2017
  16. Jonathan NiederDec 18, 2017
  17. Junio C HamanoDec 18, 2017

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.