static void _delayed_cleanup(void *rock)
{
    const char *mboxname = (const char *)rock;
    struct mailbox *mailbox = NULL;

    /* don't do the potentially expensive work of repacking mailboxes
     * if we are in the middle of a shutdown */
    if (in_shutdown) goto done;

    int r = mailbox_open_exclusive(mboxname, &mailbox);
    if (r) goto done;

    if (mailbox->i.options & OPT_MAILBOX_NEEDS_REPACK) {
        mailbox_index_repack(mailbox, mailbox->i.minor_version);
        // clear the flags here too so we don't try to repack again
        mailbox->i.options &= ~(OPT_MAILBOX_NEEDS_REPACK|OPT_MAILBOX_NEEDS_UNLINK);
    }
    else if (mailbox->i.options & OPT_MAILBOX_NEEDS_UNLINK) {
        mailbox_index_unlink(mailbox);
    }
    /* or we missed out - someone else beat us to it, all good */

 done:
    mailbox_close(&mailbox);
}
static void _delayed_cleanup(void *rock)
{
    const char *mboxname = (const char *)rock;
    struct mailbox *mailbox = NULL;

     
    if (in_shutdown) goto done;

    int r = mailbox_open_exclusive(mboxname, &mailbox);
    if (r) goto done;

    if (mailbox->i.options & OPT_MAILBOX_NEEDS_REPACK) {
        mailbox_index_repack(mailbox, mailbox->i.minor_version);
         
        mailbox->i.options &= ~(OPT_MAILBOX_NEEDS_REPACK|OPT_MAILBOX_NEEDS_UNLINK);
    }
    else if (mailbox->i.options & OPT_MAILBOX_NEEDS_UNLINK) {
        mailbox_index_unlink(mailbox);
    }
     

 done:
    mailbox_close(&mailbox);
}