EXPORTED struct mboxlist_entry *mailbox_mbentry_from_path(const char *header_path)
{
    struct mboxlist_entry *mbentry = mboxlist_entry_create();
    struct mailbox mailbox;
    int r;

    zeromailbox(mailbox);
    mailbox.mbentry = mbentry;

    r = mailbox_read_header(&mailbox, header_path);
    if (!r) {
        mbentry->mbtype = mailbox.h.mbtype;

        /* Steal strings from mailbox_header */
        mbentry->name = mailbox.h.name;
        mbentry->uniqueid = mailbox.h.uniqueid;
        mbentry->acl = mailbox.h.acl;

        /* Cleanup remaining mailbox_header */
        for (int flag = 0; flag < MAX_USER_FLAGS; flag++) {
            xzfree(mailbox.h.flagname[flag]);
        }
        xzfree(mailbox.h.quotaroot);
        xclose(mailbox.header_fd);

        /* Get partition name */
        struct part_rock prock = {
            header_path,
            config_metapartition_files & IMAP_ENUM_METAPARTITION_FILES_HEADER,
            &mbentry->partition
        };

        config_foreachoverflowstring(&get_partition, &prock);
    }
    else {
        mboxlist_entry_free(&mbentry);
    }

    return mbentry;
}
EXPORTED struct mboxlist_entry *mailbox_mbentry_from_path(const char *header_path)
{
    struct mboxlist_entry *mbentry = mboxlist_entry_create();
    struct mailbox mailbox;
    int r;

    zeromailbox(mailbox);
    mailbox.mbentry = mbentry;

    r = mailbox_read_header(&mailbox, header_path);
    if (!r) {
        mbentry->mbtype = mailbox.h.mbtype;

         
        mbentry->name = mailbox.h.name;
        mbentry->uniqueid = mailbox.h.uniqueid;
        mbentry->acl = mailbox.h.acl;

         
        for (int flag = 0; flag < MAX_USER_FLAGS; flag++) {
            xzfree(mailbox.h.flagname[flag]);
        }
        xzfree(mailbox.h.quotaroot);
        xclose(mailbox.header_fd);

         
        struct part_rock prock = {
            header_path,
            config_metapartition_files & IMAP_ENUM_METAPARTITION_FILES_HEADER,
            &mbentry->partition
        };

        config_foreachoverflowstring(&get_partition, &prock);
    }
    else {
        mboxlist_entry_free(&mbentry);
    }

    return mbentry;
}