예제 #1
0
void mdbox_update_header(struct mdbox_mailbox *mbox,
                         struct mail_index_transaction *trans,
                         const struct mailbox_update *update)
{
    struct mdbox_index_header hdr, new_hdr;
    bool need_resize;

    if (mdbox_read_header(mbox, &hdr, &need_resize) < 0) {
        memset(&hdr, 0, sizeof(hdr));
        need_resize = TRUE;
    }

    new_hdr = hdr;

    if (update != NULL && !guid_128_is_empty(update->mailbox_guid)) {
        memcpy(new_hdr.mailbox_guid, update->mailbox_guid,
               sizeof(new_hdr.mailbox_guid));
    } else if (guid_128_is_empty(new_hdr.mailbox_guid)) {
        guid_128_generate(new_hdr.mailbox_guid);
    }

    new_hdr.map_uid_validity =
        mdbox_map_get_uid_validity(mbox->storage->map);
    if (need_resize) {
        mail_index_ext_resize_hdr(trans, mbox->hdr_ext_id,
                                  sizeof(new_hdr));
    }
    if (memcmp(&hdr, &new_hdr, sizeof(hdr)) != 0) {
        mail_index_update_header_ext(trans, mbox->hdr_ext_id, 0,
                                     &new_hdr, sizeof(new_hdr));
    }
}
예제 #2
0
int mdbox_mail_lookup(struct mdbox_mailbox *mbox, struct mail_index_view *view,
		      uint32_t seq, uint32_t *map_uid_r)
{
	const struct mdbox_mail_index_record *dbox_rec;
	struct mdbox_index_header hdr;
	const void *data;
	uint32_t uid, cur_map_uid_validity;
	bool expunged;

	mail_index_lookup_ext(view, seq, mbox->ext_id, &data, &expunged);
	dbox_rec = data;
	if (dbox_rec == NULL || dbox_rec->map_uid == 0) {
		mail_index_lookup_uid(view, seq, &uid);
		mail_storage_set_critical(&mbox->storage->storage.storage,
			"mdbox %s: map uid lost for uid %u",
			mbox->box.path, uid);
		mdbox_storage_set_corrupted(mbox->storage);
		return -1;
	}

	if (mbox->map_uid_validity == 0) {
		if (mdbox_read_header(mbox, &hdr) < 0) {
			mdbox_storage_set_corrupted(mbox->storage);
			return -1;
		}
		mbox->map_uid_validity = hdr.map_uid_validity;
	}
	if (mdbox_map_open_or_create(mbox->storage->map) < 0)
		return -1;

	cur_map_uid_validity = mdbox_map_get_uid_validity(mbox->storage->map);
	if (cur_map_uid_validity != mbox->map_uid_validity) {
		mail_storage_set_critical(&mbox->storage->storage.storage,
			"mdbox %s: map uidvalidity mismatch (%u vs %u)",
			mbox->box.path, mbox->map_uid_validity,
			cur_map_uid_validity);
		mdbox_storage_set_corrupted(mbox->storage);
		return -1;
	}
	*map_uid_r = dbox_rec->map_uid;
	return 0;
}