mail-index-sync-keywords.c revision 2a6af811ea3de3cf9e2f15e446674dd21b0705f3
/* Copyright (C) 2004 Timo Sirainen */
#include "lib.h"
#include "array.h"
#include "buffer.h"
#include "mail-index-view-private.h"
#include "mail-index-sync-private.h"
#include "mail-transaction-log.h"
static int
const char *keyword_name, unsigned int *idx_r)
{
const unsigned int *idx_map;
unsigned int i, count, keyword_idx;
if (!map->keywords_read) {
return -1;
}
FALSE, &keyword_idx)) {
/* FIXME: slow. maybe create index -> file mapping as well */
for (i = 0; i < count; i++) {
if (idx_map[i] == keyword_idx) {
*idx_r = i;
return 1;
}
}
}
*idx_r = (unsigned int)-1;
return 0;
}
static buffer_t *
const struct mail_index_ext *ext,
unsigned int new_count, unsigned int *keywords_count_r,
{
const struct mail_index_keyword_header *kw_hdr;
const struct mail_index_keyword_header_rec *kw_rec;
const char *name;
struct mail_index_keyword_header new_kw_hdr;
if (kw_hdr->keywords_count == 0)
return NULL;
new_kw_hdr = *kw_hdr;
*name_offset_r = offset;
return buf;
}
{
struct mail_transaction_ext_intro *u;
sizeof(*u) + sizeof("keywords")-1);
u = buffer_append_space_unsafe(ext_intro_buf, sizeof(*u));
if ((u->record_size % 4) != 0) {
/* since we aren't properly aligned anyway,
reserve one extra byte for future */
u->record_size++;
}
u->record_align = 1;
}
return mail_index_sync_ext_intro(ctx, u);
}
static int
const char *keyword_name, unsigned int *keyword_idx_r)
{
struct mail_index_keyword_header *kw_hdr;
struct mail_index_keyword_header_rec kw_rec;
unsigned int keywords_count;
int ret;
/* if we crash in the middle of writing the header, the
keywords are more or less corrupted. avoid that by
making sure the header is updated atomically. */
/* update existing header */
&name_offset);
}
/* create new / replace broken header */
name_offset = 0;
}
/* add the keyword */
rec_offset += sizeof(kw_rec);
/* if we need to grow the buffer, add some padding */
if (ret <= 0)
return ret;
/* map may have changed */
}
}
return 1;
}
static int
const struct mail_index_ext *ext,
{
struct mail_index_record *rec;
unsigned int data_offset;
return -1;
if (seq1 == 0)
return 1;
switch (type) {
case MODIFY_ADD:
}
break;
case MODIFY_REMOVE:
}
break;
default:
i_unreached();
}
return 1;
}
const struct mail_transaction_header *hdr,
const struct mail_transaction_keyword_update *rec)
{
const char *keyword_name;
const struct mail_index_ext *ext;
unsigned int keyword_idx;
int ret;
if ((seqset_offset % 4) != 0)
"Keyword header ended unexpectedly");
return -1;
}
"Keyword sequence list empty");
return -1;
}
return -1;
if (keyword_idx == (unsigned int)-1) {
if (ret <= 0)
return ret;
}
/* nothing to do */
return 1;
}
if (ext->record_size == 0) {
/* nothing to do */
return 1;
}
return -1;
}
"Keyword record UIDs are broken");
return -1;
}
if (ret <= 0)
return ret;
uid += 2;
}
return 1;
}
int
const struct mail_transaction_header *hdr,
const struct mail_transaction_keyword_reset *r)
{
struct mail_index_record *rec;
const struct mail_index_ext *ext;
const struct mail_transaction_keyword_reset *end;
/* nothing to do */
return 1;
}
for (; r != end; r++) {
return -1;
if (seq1 == 0)
continue;
0, ext->record_size);
}
}
return 1;
}