static struct sieve_db *mailbox_open_sieve(struct mailbox *mailbox)
{
    if (!mailbox->sievedir) {
        char *userid = mboxname_to_userid(mailbox_name(mailbox));
        mailbox->sievedir = xstrdup(user_sieve_path(userid));
        free(userid);
    }
    if (!mailbox->local_sieve) {
        mailbox->local_sieve = sievedb_open_mailbox(mailbox);
        int r = sievedb_begin(mailbox->local_sieve);
        if (r) {
            sievedb_abort(mailbox->local_sieve);
            sievedb_close(mailbox->local_sieve);
            mailbox->local_sieve = NULL;
        }
    }
    return mailbox->local_sieve;
}
static struct sieve_db *mailbox_open_sieve(struct mailbox *mailbox)
{
    if (!mailbox->sievedir) {
        char *userid = mboxname_to_userid(mailbox_name(mailbox));
        mailbox->sievedir = xstrdup(user_sieve_path(userid));
        free(userid);
    }
    if (!mailbox->local_sieve) {
        mailbox->local_sieve = sievedb_open_mailbox(mailbox);
        int r = sievedb_begin(mailbox->local_sieve);
        if (r) {
            sievedb_abort(mailbox->local_sieve);
            sievedb_close(mailbox->local_sieve);
            mailbox->local_sieve = NULL;
        }
    }
    return mailbox->local_sieve;
}