mbox-append.c revision 99b621cc5076398c5d780d2ea33dd7391341d630
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
#include "ioloop.h"
#include "istream.h"
#include "hex-binary.h"
#include "md5.h"
#include "mbox-index.h"
#include "mail-index-util.h"
{
struct mail_index_record *rec;
struct mail_index_update *update;
struct mbox_header_context ctx;
const unsigned char *data;
unsigned char md5_digest[16];
int ret;
/* get the From-line */
pos = 0;
break;
}
break;
}
/* a) no \n found, or line too long
b) not a From-line */
"From-line not found where expected",
return -1;
}
/* parse the From-line */
/* now, find the end of header. also stops at "\nFrom " if it's
found (broken messages) */
/* add message to index */
return -1;
&internal_date, sizeof(internal_date));
/* location = offset to beginning of headers in message */
&abs_start_offset, sizeof(uoff_t));
/* parse the header and cache wanted fields. get the message flags
from Status and X-Status fields. temporarily limit the stream length
so the message body is parsed properly.
the stream length limit is raised again by mbox_header_cb after
reading the headers. it uses Content-Length if available or finds
the next From-line. */
ret = 1;
/* UID validity is different */
if (ctx.uid_validity == 0) {
/* we have to write it to mbox */
/* try again */
ret = 0;
} else {
}
} else {
/* change it in index */
}
}
/* X-UID header looks ok */
if (ret != 0)
} else if (!index->mailbox_readonly) {
/* Write X-UID for it */
/* try again */
ret = 0;
} else {
}
} else {
/* save MD5 */
md5_digest, sizeof(md5_digest));
}
if (ret <= 0) {
} else {
ret = -1;
} else {
/* save message flags */
ret = 1;
ret = -1;
}
}
return ret;
}
{
int ret;
/* no new data */
return TRUE;
}
return FALSE;
do {
/* we're at the [\r]\n before the From-line,
skip it */
if (!mbox_skip_crlf(input)) {
"Error indexing mbox file %s: "
"LF not found where expected",
return FALSE;
}
}
ret = 1;
break;
}
t_push();
t_pop();
if (ret == 0) {
/* we want to rescan this message with exclusive
locking */
}
} while (ret > 0);
return mbox_index_rewrite(index);
}
return ret >= 0;
}