]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap: notify - Properly encode mailbox names in mUTF7
authorStephan Bosch <stephan.bosch@open-xchange.com>
Fri, 21 Nov 2025 04:10:41 +0000 (05:10 +0100)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Sun, 7 Dec 2025 07:12:57 +0000 (09:12 +0200)
src/imap/cmd-notify.c
src/imap/imap-notify.c

index 84741ccb506fef7d908eaaf5abaf4120ef20b3fc..9d3a62370d43702cce83d06114c3a40735733b6d 100644 (file)
@@ -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);
 }
index 714644c793187d164f61f3d516ffb4d3a75d03b3..3ada855281ed1eb589f6ce9d76e317ad93b47168 100644 (file)
@@ -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;