EXPORTED struct conversations_state *mailbox_get_cstate_full(struct mailbox *mailbox, int allow_deleted)
{
    if (!mailbox_has_conversations_full(mailbox, allow_deleted))
        return NULL;

    /* we already own it? */
    if (mailbox->local_cstate)
        return mailbox->local_cstate;

    /* already exists, use that one */
    struct conversations_state *cstate = conversations_get_mbox(mailbox_name(mailbox));
    if (cstate) {
        /* but make sure it's not read-only unless we are */
        if (!mailbox->is_readonly) assert (!cstate->is_shared);
        return cstate;
    }

    /* open the conversations DB - don't bother checking return code since it'll
     * only be set if it opens successfully, and we can only return NULL or an
     * object */
    conversations_open_mbox(mailbox_name(mailbox), mailbox->is_readonly, &mailbox->local_cstate);

    return mailbox->local_cstate;
}
EXPORTED struct conversations_state *mailbox_get_cstate_full(struct mailbox *mailbox, int allow_deleted)
{
    if (!mailbox_has_conversations_full(mailbox, allow_deleted))
        return NULL;

     
    if (mailbox->local_cstate)
        return mailbox->local_cstate;

     
    struct conversations_state *cstate = conversations_get_mbox(mailbox_name(mailbox));
    if (cstate) {
         
        if (!mailbox->is_readonly) assert (!cstate->is_shared);
        return cstate;
    }

     
    conversations_open_mbox(mailbox_name(mailbox), mailbox->is_readonly, &mailbox->local_cstate);

    return mailbox->local_cstate;
}