mail-index-update.c revision 7c424aa51c956c628e3512055841aa2f9eef4833
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
#include "buffer.h"
#include "istream.h"
#include "ioloop.h"
#include "message-date.h"
#include "message-parser.h"
#include "message-part-serialize.h"
#include "message-size.h"
#include "imap-envelope.h"
#include "imap-bodystructure.h"
#include "mail-index.h"
#include "mail-index-data.h"
#include "mail-index-util.h"
struct mail_index_update {
struct mail_index *index;
struct mail_index_record *rec;
unsigned int updated_fields;
void *fields[DATA_FIELD_MAX_BITS];
};
struct mail_index_update *
{
struct mail_index_update *update;
struct mail_index_data_record_header *data_hdr;
return update;
}
{
unsigned int i, mask;
return i;
}
return -1;
}
int *no_grown_fields)
{
struct mail_index_data_record *rec;
enum mail_data_field field;
unsigned int field_min_size;
int i, field_exists;
*no_grown_fields = TRUE;
/* value was modified - use it */
update->field_extra_sizes[i]);
if (!field_exists ||
*no_grown_fields = FALSE;
} else if (field_exists) {
/* use the old value */
}
if (field_exists) {
}
}
}
{
return size; /* no extra / extra went into alignment */
/* partial */
}
}
/* extra_size is the amount of data in data_size which can be used for
field_extra_sizes */
{
struct mail_index_data_record_header *dest_hdr;
enum mail_data_field field;
const void *src;
int i;
/* set header */
/* set fields */
/* value was modified - use it */
update->field_extra_sizes[i],
&extra_size);
/* use the old value */
} else {
/* the field doesn't exist, jump to next */
continue;
}
}
}
return buffer_free_without_data(buf);
}
/* Append all the data at the end of the data file and update
the index's data position */
{
void *mem;
/* append the data at the end of the data file */
if (fpos == 0)
return FALSE;
/* the old data is discarded */
/* update index file position - it's mmap()ed so it'll be written
into disk when index is unlocked. */
return TRUE;
}
/* Replace the whole block - assumes there's enough space to do it */
{
struct mail_index_data_record_header *data_hdr;
void *mem;
/* clear the extra space. not really needed. */
}
/* Replace the modified fields in the file - assumes there's enough
space to do it */
{
struct mail_index_data_record_header *data_hdr;
struct mail_index_data_record *rec;
int index;
/* update header */
/* field was changed */
/* clear the extra space. not really needed. */
}
}
}
{
struct mail_index_data_record_header *data_hdr;
if (update->updated_fields != 0) {
/* if fields don't fit to allocated data block, we have
to move it to end of file */
if (no_grown_fields)
else {
}
if (!failed) {
/* update cached fields mask */
}
}
return !failed;
}
enum mail_data_field field,
{
int index;
}
enum mail_data_field field,
{
switch (field) {
case DATA_HDR_INTERNAL_DATE:
break;
case DATA_HDR_VIRTUAL_SIZE:
break;
case DATA_HDR_HEADER_SIZE:
break;
case DATA_HDR_BODY_SIZE:
break;
default:
i_unreached();
}
}
enum mail_data_field field,
{
}
enum mail_data_field field,
{
if (field >= DATA_FIELD_LAST)
else
}
struct header_update_context {
struct mail_index_update *update;
struct message_part_envelope_data *envelope;
void *context;
};
void *context)
{
return;
/* see if we can do anything with this field */
ctx->envelope_pool =
}
}
}
}
enum mail_data_field cache_fields,
void *context)
{
struct header_update_context ctx;
struct message_part *part;
if (cache_fields == 0)
if (IS_BODYSTRUCTURE_FIELD(cache_fields)) {
/* for body / bodystructure, we need need to
fully parse the message. unless it's already parsed
and cached. */
&size);
else {
&error);
/* corrupted, rebuild it */
"Corrupted cached MessagePart data "
"(%s)", error);
}
}
update_header_cb, &ctx);
} else {
/* cached, construct the bodystructure using it.
also we need to parse the header.. */
update_header_cb, &ctx);
}
/* save sizes */
/* don't save both BODY + BODYSTRUCTURE since BODY can be
generated from BODYSTRUCTURE. FIXME: However that takes
CPU, maybe this should be configurable (I/O vs. CPU)? */
if ((cache_fields & DATA_FIELD_BODY) &&
DATA_FIELD_BODYSTRUCTURE) == 0) {
t_push();
value, 0);
t_pop();
}
if (cache_fields & DATA_FIELD_BODYSTRUCTURE) {
t_push();
value, 0);
t_pop();
}
if (cache_fields & DATA_FIELD_MESSAGEPART) {
t_push();
(size_t)-1);
t_pop();
}
} else {
update_header_cb, &ctx);
if (body_size.physical_size == 0)
body_size.virtual_size = 0;
else {
}
}
t_push();
value, 0);
t_pop();
}
/* update physical sizes */
sizeof(hdr_size.physical_size));
sizeof(body_size.physical_size));
/* update virtual size if we know it */
sizeof(virtual_size));
}
/* update binary flags. */
}