From: Stephan Bosch Date: Fri, 21 Nov 2025 04:10:41 +0000 (+0100) Subject: imap: notify - Properly encode mailbox names in mUTF7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd8f2da828b1d948b347db6f8b3d714cd4146b02;p=thirdparty%2Fdovecot%2Fcore.git imap: notify - Properly encode mailbox names in mUTF7 --- diff --git a/src/imap/cmd-notify.c b/src/imap/cmd-notify.c index 84741ccb50..9d3a62370d 100644 --- a/src/imap/cmd-notify.c +++ b/src/imap/cmd-notify.c @@ -4,6 +4,7 @@ #include "str.h" #include "mailbox-list-iter.h" #include "imap-quote.h" +#include "imap-utf7.h" #include "imap-commands.h" #include "imap-fetch.h" #include "imap-list.h" @@ -404,11 +405,18 @@ imap_notify_box_list_noperm(struct client *client, struct mailbox *box) string_t *str = t_str_new(128); char ns_sep = mail_namespace_get_sep(mailbox_get_namespace(box)); enum mailbox_info_flags mailbox_flags; + const char *vname; if (mailbox_list_mailbox(mailbox_get_namespace(box)->list, mailbox_get_name(box), &mailbox_flags) < 0) mailbox_flags = 0; + vname = mailbox_get_vname(box); + string_t *mutf7_name = t_str_new(128); + if (imap_utf8_to_utf7(vname, mutf7_name) < 0) + i_panic("LIST: Mailbox name not UTF-8: %s", vname); + vname = str_c(mutf7_name); + str_append(str, "* LIST ("); if (imap_mailbox_flags2str(str, mailbox_flags)) str_append_c(str, ' '); @@ -418,7 +426,7 @@ imap_notify_box_list_noperm(struct client *client, struct mailbox *box) str_append_c(str, ns_sep); str_append(str, "\" "); - imap_append_astring(str, mailbox_get_vname(box)); + imap_append_astring(str, vname); client_send_line(client, str_c(str)); } @@ -460,7 +468,13 @@ imap_notify_box_send_status(struct client_command_context *cmd, t_strconcat("* ", result.errstr, NULL)); } } else { - imap_status_send(client, info->vname, &items, &result); + const char *vname = info->vname; + + string_t *mutf7_vname = t_str_new(128); + if (imap_utf8_to_utf7(vname, mutf7_vname) < 0) + i_panic("Mailbox name not UTF-8: %s", vname); + vname = str_c(mutf7_vname); + imap_status_send(client, vname, &items, &result); } mailbox_free(&box); } diff --git a/src/imap/imap-notify.c b/src/imap/imap-notify.c index 714644c793..3ada855281 100644 --- a/src/imap/imap-notify.c +++ b/src/imap/imap-notify.c @@ -8,6 +8,7 @@ #include "mailbox-list-notify.h" #include "mail-search.h" #include "mail-search-build.h" +#include "imap-utf7.h" #include "imap-commands.h" #include "imap-fetch.h" #include "imap-list.h" @@ -21,8 +22,9 @@ static int imap_notify_list(struct imap_notify_namespace *notify_ns, enum mailbox_info_flags flags) { struct client *client = notify_ns->ctx->client; - string_t *str = t_str_new(128); + string_t *str = t_str_new(128), *mutf7_vname; char ns_sep = mail_namespace_get_sep(notify_ns->ns); + const char *vname, *old_vname; str_append(str, "* LIST ("); imap_mailbox_flags2str(str, flags); @@ -32,10 +34,22 @@ static int imap_notify_list(struct imap_notify_namespace *notify_ns, str_append_c(str, ns_sep); str_append(str, "\" "); - imap_append_astring(str, rec->vname); + vname = rec->vname; + mutf7_vname = t_str_new(128); + if (imap_utf8_to_utf7(vname, mutf7_vname) < 0) + i_panic("Mailbox name not UTF-8: %s", vname); + vname = str_c(mutf7_vname); + imap_append_astring(str, vname); if (rec->old_vname != NULL) { + old_vname = rec->old_vname; + str_truncate(mutf7_vname, 0); + if (imap_utf8_to_utf7(old_vname, mutf7_vname) < 0) { + i_panic("Mailbox name not UTF-8: %s", + old_vname); + } + old_vname = str_c(mutf7_vname); str_append(str, " (\"OLDNAME\" ("); - imap_append_astring(str, rec->old_vname); + imap_append_astring(str, old_vname); str_append(str, "))"); } return client_send_line_next(client, str_c(str)); @@ -80,7 +94,13 @@ static int imap_notify_status(struct imap_notify_namespace *notify_ns, if (error != MAIL_ERROR_PERM) ret = -1; } else { - ret = imap_status_send(client, rec->vname, &items, &result); + const char *vname = rec->vname; + + string_t *mutf7_vname = t_str_new(128); + if (imap_utf8_to_utf7(vname, mutf7_vname) < 0) + i_panic("Mailbox name not UTF-8: %s", vname); + vname = str_c(mutf7_vname); + ret = imap_status_send(client, vname, &items, &result); } mailbox_free(&box); return ret;