mbox-sync-full.c revision 6449bd276af37b3e0b81a9c47ecd01f39a2cba53
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
#include "istream.h"
#include "hex-binary.h"
#include "message-parser.h"
#include "message-part-serialize.h"
#include "mbox-index.h"
#include "mbox-lock.h"
#include "mail-index-util.h"
#include "mail-cache.h"
#include <unistd.h>
#include <fcntl.h>
{
const unsigned char *msg;
int ret;
for (i = 0; i < size; i++) {
if (msg[i] == '\n') {
return;
}
}
i_stream_skip(input, i);
}
}
struct mail_index_record *rec,
{
const void *old_digest;
if (uid != 0) {
/* X-UID header - no need to check more */
}
/* check if MD5 sums match */
&old_digest, &size))
return FALSE;
}
unsigned int uid_validity)
{
return TRUE;
if (uid_validity == 0) {
/* X-IMAPbase header isn't written yet */
} else {
/* UID validity has changed - rebuild whole index */
return FALSE;
}
return TRUE;
}
struct mail_index_record *rec,
{
struct message_size hdr_parsed_size;
struct mbox_header_context ctx;
unsigned char current_digest[16];
int ret, hdr_size_fixed;
/* skip the From-line */
return -1;
do {
return -1;
if (body_size == 0 && !hdr_size_fixed) {
/* possibly broken message, find the next From-line
and make sure header parser won't pass it. */
hdr_size = 0;
}
if (hdr_size == 0) {
/* get the MD5 sum of fixed headers and the current
message flags in Status and X-Status fields */
mbox_header_cb, &ctx);
if (*seq == 1) {
if (!mbox_check_uidvalidity(index,
ctx.uid_validity)) {
/* uidvalidity changed, abort */
return -1;
}
/* last_uid larger than ours */
}
}
}
/* valid message */
/* update flags, unless we've changed them */
if ((index_flags & MAIL_INDEX_FLAG_DIRTY) == 0) {
return -1;
/* flags are same, it's not dirty anymore */
rec, index_flags);
} else {
}
/* update location */
if (offset != header_offset) {
return -1;
}
ret = 1;
break;
}
/* try next message */
}
*seq += 1;
} else {
return -1;
}
return ret;
}
{
struct mail_index_record *rec;
const unsigned char *data;
unsigned int seq;
return FALSE;
/* first make sure we start with a "From " line. If file is too
small, we'll just treat it as empty mbox file. */
return FALSE;
}
/* we'll go through the mailbox and index in order matching the
messages by their size and Message-ID. old mails aren't remembered,
so we handle well only the cases when mail has been deleted. if
mails have been reordered (eg. sorted by someone) most of the mails
will show up as being new. if we really wanted to support that well,
we could save the message-ids into hash but I don't know if it's
worth the trouble. */
seq = 1;
/* we're at the [\r]\n before the From-line,
skip it */
if (!mbox_skip_crlf(input)) {
/* they just went and broke it, even while
we had it locked. */
"Error syncing mbox file %s: "
"LF not found where expected",
return FALSE;
}
}
if (ret < 0) {
break;
return FALSE;
}
if (ret == 0) {
/* Get back to line before From */
}
}
/* delete the rest of the records */
return FALSE;
}
if (!dirty &&
/* no flags are dirty anymore, no need to rewrite */
}
return TRUE;
else
}
{
int failed;
return FALSE;
} else {
}
/* mbox_index_append() stopped, which means that it wants
write access to mbox. if mbox hasn't changed after
unlock+lock, we should be able to safely continue where we
were left off last time. otherwise do full resync. */
if (!mbox_unlock(index))
return FALSE;
return FALSE;
} else {
}
if (index->mbox_rewritten) {
/* rewritten, sync again */
i_stream_seek(input, 0);
}
}
return !failed;
}