static int mailbox_wipe_index_record(struct mailbox *mailbox,
                                     struct index_record *record)
{
    int n;
    indexbuffer_t ibuf;
    unsigned char *buf = ibuf.buf;
    size_t offset;

    assert(mailbox_index_islocked(mailbox, 1));
    assert(record->recno > 0 &&
           record->recno <= mailbox->i.num_records);

    record->uid = 0;
    record->internal_flags |= FLAG_INTERNAL_EXPUNGED | FLAG_INTERNAL_UNLINKED;

    mailbox->i.options |= OPT_MAILBOX_NEEDS_REPACK;
    mailbox_index_dirty(mailbox);

    mailbox_index_record_to_buf(record, mailbox->i.minor_version, buf);

    offset = mailbox->i.start_offset +
             (record->recno-1) * mailbox->i.record_size;

    off_t p = lseek(mailbox->index_fd, offset, SEEK_SET);
    if (p == -1) {
        xsyslog(LOG_ERR, "IOERROR: seeking index record failed",
                         "mailbox=<%s> record=<%u>",
                         mailbox_name(mailbox), record->recno);
        return IMAP_IOERROR;
    }

    n = retry_write(mailbox->index_fd, buf, mailbox->i.record_size);
    if (n < 0) {
        xsyslog(LOG_ERR, "IOERROR: writing index record failed",
                         "mailbox=<%s> record=<%u>",
                         mailbox_name(mailbox), record->recno);
        return IMAP_IOERROR;
    }

    return 0;
}
static int mailbox_wipe_index_record(struct mailbox *mailbox,
                                     struct index_record *record)
{
    int n;
    indexbuffer_t ibuf;
    unsigned char *buf = ibuf.buf;
    size_t offset;

    assert(mailbox_index_islocked(mailbox, 1));
    assert(record->recno > 0 &&
           record->recno <= mailbox->i.num_records);

    record->uid = 0;
    record->internal_flags |= FLAG_INTERNAL_EXPUNGED | FLAG_INTERNAL_UNLINKED;

    mailbox->i.options |= OPT_MAILBOX_NEEDS_REPACK;
    mailbox_index_dirty(mailbox);

    mailbox_index_record_to_buf(record, mailbox->i.minor_version, buf);

    offset = mailbox->i.start_offset +
             (record->recno-1) * mailbox->i.record_size;

    off_t p = lseek(mailbox->index_fd, offset, SEEK_SET);
    if (p == -1) {
        xsyslog(LOG_ERR, "IOERROR: seeking index record failed",
                         "mailbox=<%s> record=<%u>",
                         mailbox_name(mailbox), record->recno);
        return IMAP_IOERROR;
    }

    n = retry_write(mailbox->index_fd, buf, mailbox->i.record_size);
    if (n < 0) {
        xsyslog(LOG_ERR, "IOERROR: writing index record failed",
                         "mailbox=<%s> record=<%u>",
                         mailbox_name(mailbox), record->recno);
        return IMAP_IOERROR;
    }

    return 0;
}