# HG changeset patch # User Timo Sirainen # Date 1049249138 -10800 # Node ID ae229b7acb4c759e93c288757131638f70c57efd # Parent 0a524d229f501d3d817311e69a32e3031da72e32 Mailbox names are now sent through imap-quoter instead of just escaping it. This means that mailbox names that would require escapes are instead sent as literals now. diff -r 0a524d229f50 -r ae229b7acb4c src/imap/cmd-list.c --- a/src/imap/cmd-list.c Wed Apr 02 04:00:02 2003 +0300 +++ b/src/imap/cmd-list.c Wed Apr 02 05:05:38 2003 +0300 @@ -1,7 +1,9 @@ /* Copyright (C) 2002 Timo Sirainen */ #include "common.h" +#include "str.h" #include "strescape.h" +#include "imap-quote.h" #include "imap-match.h" #include "commands.h" @@ -23,6 +25,7 @@ struct client *client; const char *response_name; const char *sep; + char sep_chr; struct imap_match_glob *glob; int listext, no_placeholder; }; @@ -72,9 +75,7 @@ t_push(); - /* escaping is done here to make sure we don't try to escape - the separator char */ - name = str_escape(t_strdup_until(name, path)); + name = t_strdup_until(name, path); /* find the node */ while (*node != NULL) { @@ -116,16 +117,18 @@ static void list_send(struct list_send_context *ctx, struct list_node *node, const char *path) { - const char *name, *send_name, *str, *flagstr; + const char *name, *send_name, *flagstr; enum imap_match_result match; + string_t *str; for (; node != NULL; node = node->next) { t_push(); /* Send INBOX always uppercased */ - if (path != NULL) - name = t_strconcat(path, ctx->sep, node->name, NULL); - else if (strcasecmp(node->name, "INBOX") == 0) + if (path != NULL) { + name = t_strdup_printf("%s%c%s", path, ctx->sep_chr, + node->name); + } else if (strcasecmp(node->name, "INBOX") == 0) name = "INBOX"; else name = node->name; @@ -147,8 +150,9 @@ this is sent c) cyrus and courier doesn't do this either.. - if (match == IMAP_MATCH_CHILDREN) { - send_name = t_strconcat(name, ctx->sep, NULL); + if (match == IMAP_MATCH_CHILDREN) { + send_name = t_strdup_printf("%s%c", name, + ctx->sep); buf = str_unescape(t_strdup_noconst(send_name)); match = imap_match(ctx->glob, buf); }*/ @@ -158,10 +162,13 @@ /* node->name should already be escaped */ flagstr = mailbox_flags2str(node->flags, ctx->listext, ctx->no_placeholder); - str = t_strdup_printf("* %s (%s) \"%s\" \"%s\"", - ctx->response_name, flagstr, - ctx->sep, send_name); - client_send_line(ctx->client, str); + t_push(); + str = t_str_new(256); + str_printfa(str, "* %s (%s) \"%s\" ", + ctx->response_name, flagstr, ctx->sep); + imap_quote_append_string(str, send_name); + client_send_line(ctx->client, str_c(str)); + t_pop(); } if (node->children != NULL) @@ -173,8 +180,8 @@ static void list_and_sort(struct client *client, struct mailbox_list_context *ctx, - const char *response_name, - const char *sep, const char *mask, + const char *response_name, const char *mask, + const char *sep, char sep_chr, enum mailbox_list_flags list_flags, int listext) { struct mailbox_list *list; @@ -194,6 +201,7 @@ send_ctx.client = client; send_ctx.response_name = response_name; send_ctx.sep = sep; + send_ctx.sep_chr = sep_chr; send_ctx.glob = imap_match_init(data_stack_pool, mask, TRUE, client->storage->hierarchy_sep); send_ctx.listext = listext; @@ -209,19 +217,19 @@ const char *reply, const char *sep, int listext) { struct mailbox_list *list; - const char *name, *str; + string_t *str; while ((list = client->storage->list_mailbox_next(ctx)) != NULL) { t_push(); + str = t_str_new(256); + str_printfa(str, "* %s (%s) \"%s\" ", reply, + mailbox_flags2str(list->flags, listext, FALSE), + sep); if (strcasecmp(list->name, "INBOX") == 0) - name = "INBOX"; + str_append(str, "INBOX"); else - name = str_escape(list->name); - str = t_strdup_printf("* %s (%s) \"%s\" \"%s\"", reply, - mailbox_flags2str(list->flags, listext, - FALSE), - sep, name); - client_send_line(client, str); + imap_quote_append_string(str, list->name); + client_send_line(client, str_c(str)); t_pop(); } } @@ -333,8 +341,9 @@ list_unsorted(client, ctx, response_name, sep, listext); } else { - list_and_sort(client, ctx, response_name, sep, - mask, list_flags, listext); + list_and_sort(client, ctx, response_name, mask, + sep, sep_chr, list_flags, + listext); } failed = !client->storage->list_mailbox_deinit(ctx); diff -r 0a524d229f50 -r ae229b7acb4c src/imap/cmd-status.c --- a/src/imap/cmd-status.c Wed Apr 02 04:00:02 2003 +0300 +++ b/src/imap/cmd-status.c Wed Apr 02 05:05:38 2003 +0300 @@ -2,7 +2,7 @@ #include "common.h" #include "str.h" -#include "strescape.h" +#include "imap-quote.h" #include "commands.h" /* Returns status items, or -1 if error */ @@ -110,7 +110,10 @@ } str = t_str_new(128); - str_printfa(str, "* STATUS \"%s\" (", str_escape(mailbox)); + str_append(str, "* STATUS "); + imap_quote_append_string(str, mailbox); + str_append(str, " ("); + if (items & STATUS_MESSAGES) str_printfa(str, "MESSAGES %u ", status.messages); if (items & STATUS_RECENT) diff -r 0a524d229f50 -r ae229b7acb4c src/lib/strescape.c --- a/src/lib/strescape.c Wed Apr 02 04:00:02 2003 +0300 +++ b/src/lib/strescape.c Wed Apr 02 05:05:38 2003 +0300 @@ -27,28 +27,28 @@ const char *str_escape(const char *str) { - char *ret, *p; - size_t i, esc; + const char *p; + string_t *ret; - /* get length of string and number of chars to escape */ - esc = 0; - for (i = 0; str[i] != '\0'; i++) { - if (IS_ESCAPED_CHAR(str[i])) - esc++; + /* see if we need to quote it */ + for (p = str; *p != '\0'; p++) { + if (IS_ESCAPED_CHAR(*p)) + break; } - if (esc == 0) + if (*p == '\0') return str; - /* @UNSAFE: escape them */ - p = ret = t_malloc(i + esc + 1); - for (; *str != '\0'; str++) { - if (IS_ESCAPED_CHAR(*str)) - *p++ = '\\'; - *p++ = *str; + /* quote */ + ret = t_str_new((size_t) (p - str) + 128); + str_append_n(ret, str, (size_t) (p - str)); + + for (; *p != '\0'; p++) { + if (IS_ESCAPED_CHAR(*p)) + str_append_c(ret, '\\'); + str_append_c(ret, *p); } - *p = '\0'; - return ret; + return str_c(ret); } void str_append_unescaped(string_t *dest, const void *src, size_t src_size) diff -r 0a524d229f50 -r ae229b7acb4c src/lib/strescape.h --- a/src/lib/strescape.h Wed Apr 02 04:00:02 2003 +0300 +++ b/src/lib/strescape.h Wed Apr 02 05:05:38 2003 +0300 @@ -1,9 +1,9 @@ #ifndef __STRESCAPE_H #define __STRESCAPE_H -#define IS_ESCAPED_CHAR(c) ((c) == '"' || (c) == '\\') +#define IS_ESCAPED_CHAR(c) ((c) == '"' || (c) == '\\' || (c) == '\'') -/* escape all '\' and '"' characters */ +/* escape all '\', '"' and "'" characters */ const char *str_escape(const char *str); /* remove all '\' characters, append to given string */