Commit 09105467 091054679e9842c2b96b3ee7e4ff5b59f8e0f9ee by Sergey Poznyakoff

Fix listing names with escapable characters

* imap4d/io.c (io_send_qstring): Fix condition
* imap4d/list.c (list_fun): Use io_send_qstring to print names.
* imap4d/lsub.c (imap4d_lsub): Likewise.
1 parent 50979073
...@@ -234,15 +234,14 @@ io_sendf (const char *format, ...) ...@@ -234,15 +234,14 @@ io_sendf (const char *format, ...)
234 } 234 }
235 235
236 /* Send NIL if empty string, change the quoted string to a literal if the 236 /* Send NIL if empty string, change the quoted string to a literal if the
237 string contains: double quotes, CR, LF, and '/'. CR, LF will be changed 237 string contains: double quotes, CR, LF, and '\\'. CR, LF will be changed
238 to spaces. */ 238 to spaces. */
239 int 239 int
240 io_send_qstring (const char *buffer) 240 io_send_qstring (const char *buffer)
241 { 241 {
242 if (buffer == NULL || *buffer == '\0') 242 if (buffer == NULL || *buffer == '\0')
243 return io_sendf ("NIL"); 243 return io_sendf ("NIL");
244 if (strchr (buffer, '"') || strchr (buffer, '\r') || strchr (buffer, '\n') 244 if (strpbrk (buffer, "\"\r\n\\"))
245 || strchr (buffer, '\\'))
246 { 245 {
247 char *s; 246 char *s;
248 int ret; 247 int ret;
......
...@@ -93,7 +93,10 @@ list_fun (mu_folder_t folder, struct mu_list_response *resp, void *data) ...@@ -93,7 +93,10 @@ list_fun (mu_folder_t folder, struct mu_list_response *resp, void *data)
93 else if (is_atom (name)) 93 else if (is_atom (name))
94 io_sendf ("%s\n", name); 94 io_sendf ("%s\n", name);
95 else 95 else
96 io_sendf ("\"%s\"\n", name); 96 {
97 io_send_qstring (name);
98 io_sendf ("\n", name);
99 }
97 return 0; 100 return 0;
98 } 101 }
99 102
......
...@@ -65,8 +65,12 @@ imap4d_lsub (struct imap4d_session *session, ...@@ -65,8 +65,12 @@ imap4d_lsub (struct imap4d_session *session,
65 mu_iterator_current_kv (itr, (const void **)&name, (void**)&val); 65 mu_iterator_current_kv (itr, (const void **)&name, (void**)&val);
66 66
67 if (mu_imap_wildmatch (pattern, name, MU_HIERARCHY_DELIMITER) == 0) 67 if (mu_imap_wildmatch (pattern, name, MU_HIERARCHY_DELIMITER) == 0)
68 io_untagged_response (RESP_NONE, "LSUB () \"%c\" \"%s\"", 68 {
69 MU_HIERARCHY_DELIMITER, name); 69 mu_stream_printf (iostream, "* LSUB () \"%c\" ",
70 MU_HIERARCHY_DELIMITER);
71 io_send_qstring (name);
72 io_sendf ("\n");
73 }
70 } 74 }
71 } 75 }
72 else 76 else
......