EXPORTED int mailbox_add_email_alarms(struct mailbox *mailbox)
{
    const message_t *msg;
    int r = 0;

    if (!(mailbox->i.options & OPT_IMAP_HAS_ALARMS))
        return 0;

    if (mboxname_isdeletedmailbox(mailbox_name(mailbox), NULL))
        return 0;

    struct mailbox_iter *iter = mailbox_iter_init(mailbox, 0, ITER_SKIP_UNLINKED);
    while ((msg = mailbox_iter_step(iter))) {
        const struct index_record *record = msg_record(msg);
        r = mailbox_update_email_alarms(mailbox, NULL, record);
        if (r) break;
    }
    mailbox_iter_done(&iter);

    return r;
}
EXPORTED int mailbox_add_email_alarms(struct mailbox *mailbox)
{
    const message_t *msg;
    int r = 0;

    if (!(mailbox->i.options & OPT_IMAP_HAS_ALARMS))
        return 0;

    if (mboxname_isdeletedmailbox(mailbox_name(mailbox), NULL))
        return 0;

    struct mailbox_iter *iter = mailbox_iter_init(mailbox, 0, ITER_SKIP_UNLINKED);
    while ((msg = mailbox_iter_step(iter))) {
        const struct index_record *record = msg_record(msg);
        r = mailbox_update_email_alarms(mailbox, NULL, record);
        if (r) break;
    }
    mailbox_iter_done(&iter);

    return r;
}