static char *mailbox_header_data_cstring(struct mailbox *mailbox)
{
    struct buf buf = BUF_INITIALIZER;
    struct dlist *dl = dlist_newkvlist(NULL, NULL);
    int nflags = 0;
    int flag;

    dlist_setatom(dl, "T", mboxlist_mbtype_to_string(mailbox->h.mbtype));

    dlist_setatom(dl, "N", mailbox->h.name);

    dlist_setatom(dl, "I", mailbox->h.uniqueid);

    if (mailbox->h.quotaroot)
        dlist_setatom(dl, "Q", mailbox->h.quotaroot);

    if (mailbox->h.acl)
        dlist_stitch(dl, mailbox_acl_to_dlist(mailbox->h.acl));

    for (flag = 0; flag < MAX_USER_FLAGS; flag++) {
        if (mailbox->h.flagname[flag])
             nflags = flag+1;
    }
    if (nflags) {
        struct dlist *fl = dlist_newlist(dl, "U");

        // this could be inserting NIL values for removed flags
        for (flag = 0; flag < nflags; flag++) {
            dlist_setatom(fl, NULL, mailbox->h.flagname[flag]);
        }
    }

    dlist_printbuf(dl, 0, &buf);

    dlist_free(&dl);

    return buf_release(&buf);
}
static char *mailbox_header_data_cstring(struct mailbox *mailbox)
{
    struct buf buf = BUF_INITIALIZER;
    struct dlist *dl = dlist_newkvlist(NULL, NULL);
    int nflags = 0;
    int flag;

    dlist_setatom(dl, "T", mboxlist_mbtype_to_string(mailbox->h.mbtype));

    dlist_setatom(dl, "N", mailbox->h.name);

    dlist_setatom(dl, "I", mailbox->h.uniqueid);

    if (mailbox->h.quotaroot)
        dlist_setatom(dl, "Q", mailbox->h.quotaroot);

    if (mailbox->h.acl)
        dlist_stitch(dl, mailbox_acl_to_dlist(mailbox->h.acl));

    for (flag = 0; flag < MAX_USER_FLAGS; flag++) {
        if (mailbox->h.flagname[flag])
             nflags = flag+1;
    }
    if (nflags) {
        struct dlist *fl = dlist_newlist(dl, "U");

         
        for (flag = 0; flag < nflags; flag++) {
            dlist_setatom(fl, NULL, mailbox->h.flagname[flag]);
        }
    }

    dlist_printbuf(dl, 0, &buf);

    dlist_free(&dl);

    return buf_release(&buf);
}