mail-cache-compress.c revision 275b5e9ddb9679c5667493834d4579821994089b
/* Copyright (C) 2003-2004 Timo Sirainen */
#include "lib.h"
#include "buffer.h"
#include "byteorder.h"
#include "ostream.h"
#include "mail-cache-private.h"
static unsigned char null4[4] = { 0, 0, 0, 0 };
static const struct mail_cache_record *
{
struct mail_cache_record cache_rec;
const void *data;
int i;
if ((cached_fields & field) == 0)
continue;
cached_fields &= ~field;
continue;
}
if ((field & MAIL_CACHE_FIXED_MASK) == 0)
if ((size & 3) != 0)
}
/* now merge all the headers if we have them all */
nb_size = 0;
for (i = 0; i <= header_idx; i++) {
size--; /* terminating \0 */
}
}
nb_size++;
if ((nb_size & 3) != 0)
}
return data;
}
static int
{
struct mail_cache_view *cache_view;
struct mail_index_transaction *t;
const struct mail_index_header *idx_hdr;
const struct mail_cache_record *cache_rec;
struct mail_cache_header hdr;
const char *str;
int i, header_idx, ret;
/* get sequence of first message which doesn't need it's temp fields
removed. */
return -1;
&message_count) < 0)
return -1;
if (first_new_seq == 0)
sizeof(hdr.field_usage_decision_type));
sizeof(hdr.field_usage_last_used));
keep_fields = temp_fields = 0;
for (i = 0; i < 32; i++) {
keep_fields |= 1 << i;
temp_fields |= 1 << i;
}
/* merge all the header pieces into one. if some message doesn't have
all the required pieces, we'll just have to drop them all. */
for (i = MAIL_CACHE_HEADERS_COUNT-1; i >= 0; i--) {
break;
}
header_idx = -1;
else {
header_idx = i;
if ((size & 3) != 0)
}
ret = 0;
continue;
if ((cached_fields & temp_fields) != 0 &&
seq >= first_new_seq) {
/* new message, keep temp fields */
}
if (keep_fields == cached_fields &&
/* just one unmodified block, save it */
if ((size & 3) != 0)
} else {
/* a) dropping fields
b) multiple blocks, sort them into buffer */
t_push();
&size);
t_pop();
}
}
(void)mail_index_transaction_rollback(t);
return -1;
}
}
{
return ret;
#ifdef DEBUG
#endif
if (fd == -1) {
return -1;
}
ret = -1;
} else {
-1, FALSE) < 0) {
"file_dotlock_replace()");
ret = -1;
} else {
if (mail_cache_mmap_update(cache, 0, 0) < 0)
ret = -1;
}
}
/* headers could have changed, reread them */
if (mail_cache_unlock(cache) < 0)
return -1;
if (ret == 0)
return ret;
}
{
return FALSE; //FIXME:cache->need_compress;
}