1
From: Jaldhar H. Vyas <jaldhar@debian.org>
2
Date: Sun, 30 Sep 2012 11:31:43 -0400
3
Subject: backport of 2.1.8 fixes for UTF-8 namespaces
5
Description: Fixes handling of UTF-8 namespace prefixes
7
# User Timo Sirainen <tss@iki.fi>
8
# Date 1345751816 -10800
9
# Node ID ade94fde249e1379af55df62c47ad98e19ddb935
10
# Parent 565605200989dd5a81b8358a13420a4d7b30b33c
11
imap: Fixes to handling UTF-8 namespace prefixes
12
Origin: http://hg.dovecot.org/dovecot-2.1
14
diff -r 565605200989 -r ade94fde249e src/imap/cmd-list.c
15
--- a/src/imap/cmd-list.c Thu Aug 23 22:33:23 2012 +0300
16
+++ b/src/imap/cmd-list.c Thu Aug 23 22:56:56 2012 +0300
21
+static const char *ns_prefix_mutf7(struct mail_namespace *ns)
25
+ if (*ns->prefix == '\0')
28
+ str = t_str_new(64);
29
+ if (imap_utf8_to_utf7(ns->prefix, str) < 0)
30
+ i_panic("Namespace prefix not UTF-8: %s", ns->prefix);
34
static const char *ns_get_listed_prefix(struct cmd_list_context *ctx)
36
struct imap_match_glob *glob;
39
enum mailbox_info_flags flags;
42
+ string_t *str, *mutf7_name;
43
bool same_ns, ends_with_sep;
44
char ns_sep = mail_namespace_get_sep(ctx->ns);
47
str_append(str, ") ");
48
list_reply_append_ns_sep_param(str, ns_sep);
49
str_append_c(str, ' ');
50
- imap_quote_append_string(str, name, FALSE);
52
+ mutf7_name = t_str_new(64);
53
+ if (imap_utf8_to_utf7(name, mutf7_name) < 0)
54
+ i_panic("Namespace prefix not UTF-8: %s", name);
55
+ imap_quote_append_string(str, str_c(mutf7_name), FALSE);
56
mailbox_childinfo2str(ctx, str, flags);
58
client_send_line(ctx->cmd->client, str_c(str));
60
Otherwise we'll emulate UW-IMAP behavior. */
61
ns = mail_namespace_find_visible(client->user->namespaces, ref);
63
- ns_prefix = ns->prefix;
64
+ ns_prefix = ns_prefix_mutf7(ns);
65
ns_sep = mail_namespace_get_sep(ns);
72
+ if (imap_utf7_to_utf8(ctx->ref, str) == 0)
73
+ ctx->ref = p_strdup(cmd->pool, str_c(str));
74
+ str_truncate(str, 0);
76
if (imap_arg_get_list_full(&args[1], &list_args, &arg_count)) {
77
ctx->used_listext = TRUE;
78
/* convert pattern list to string array */
79
diff -r 565605200989 -r ade94fde249e src/imap/cmd-namespace.c
80
--- a/src/imap/cmd-namespace.c Thu Aug 23 22:33:23 2012 +0300
81
+++ b/src/imap/cmd-namespace.c Thu Aug 23 22:56:56 2012 +0300
84
#include "imap-common.h"
86
+#include "imap-utf7.h"
87
#include "imap-quote.h"
88
#include "imap-commands.h"
89
#include "mail-namespace.h"
91
static void list_namespaces(struct mail_namespace *ns,
92
enum namespace_type type, string_t *str)
94
+ string_t *mutf7_prefix = t_str_new(64);
100
ns_sep = mail_namespace_get_sep(ns);
101
str_append_c(str, '(');
102
- imap_quote_append_string(str, ns->prefix, FALSE);
104
+ str_truncate(mutf7_prefix, 0);
105
+ if (imap_utf8_to_utf7(ns->prefix, mutf7_prefix) < 0) {
106
+ i_panic("LIST: Namespace prefix not UTF-8: %s",
110
+ imap_quote_append_string(str, str_c(mutf7_prefix), FALSE);
111
str_append(str, " \"");
113
str_append_c(str, '\\');
114
diff -r 565605200989 -r ade94fde249e src/imap/imap-commands-util.c
115
--- a/src/imap/imap-commands-util.c Thu Aug 23 22:33:23 2012 +0300
116
+++ b/src/imap/imap-commands-util.c Thu Aug 23 22:56:56 2012 +0300
119
struct mail_namespace *namespaces = cmd->client->user->namespaces;
120
struct mail_namespace *ns;
121
- unsigned int name_len;
124
- ns = mail_namespace_find(namespaces, *mailbox);
125
+ utf8_name = t_str_new(64);
126
+ if (imap_utf7_to_utf8(*mailbox, utf8_name) < 0) {
127
+ client_send_tagline(cmd, "NO Mailbox name is not valid mUTF-7");
131
+ ns = mail_namespace_find(namespaces, str_c(utf8_name));
133
client_send_tagline(cmd, t_strdup_printf(
134
"NO Client tried to access nonexistent namespace. "
139
- name_len = strlen(*mailbox);
140
if ((cmd->client->set->parsed_workarounds &
141
WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 &&
143
- (*mailbox)[name_len-1] == mail_namespace_get_sep(ns)) {
144
+ str_len(utf8_name) > 0 &&
145
+ str_c(utf8_name)[str_len(utf8_name)-1] == mail_namespace_get_sep(ns)) {
146
/* drop the extra trailing hierarchy separator */
147
- *mailbox = t_strndup(*mailbox, name_len-1);
148
+ str_truncate(utf8_name, str_len(utf8_name)-1);
151
- utf8_name = t_str_new(64);
152
- if (imap_utf7_to_utf8(*mailbox, utf8_name) < 0) {
153
- client_send_tagline(cmd, "NO Mailbox name is not valid mUTF-7");
156
*mailbox = str_c(utf8_name);