mbox-sync.c revision 77af8c68c416179e717fc2d551f72ec50b499c13
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (C) 2004 Timo Sirainen */
332e3fd09754ad85800a736292a0ef8dfdca4c9eAki Tuomi Modifying mbox can be slow, so we try to do it all at once minimizing the
332e3fd09754ad85800a736292a0ef8dfdca4c9eAki Tuomi required disk I/O. We may need to:
332e3fd09754ad85800a736292a0ef8dfdca4c9eAki Tuomi - Update message flags in Status, X-Status and X-Keywords headers
332e3fd09754ad85800a736292a0ef8dfdca4c9eAki Tuomi - Write missing X-UID and X-IMAPbase headers
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi - Write missing or broken Content-Length header if there's space
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi - Expunge specified messages
332e3fd09754ad85800a736292a0ef8dfdca4c9eAki Tuomi Here's how we do it:
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi - Start reading the mails from the beginning
9698cd24356147d8a5471260062ea7e10e692fdfAki Tuomi - X-Keywords, X-UID and X-IMAPbase headers may contain padding at the end
332e3fd09754ad85800a736292a0ef8dfdca4c9eAki Tuomi of them, remember how much each message has and offset to beginning of the
332e3fd09754ad85800a736292a0ef8dfdca4c9eAki Tuomi - If header needs to be rewritten and there's enough space, do it
#include "lib.h"
#include "ioloop.h"
#include "buffer.h"
#include "istream.h"
#include "file-set-size.h"
#include "str.h"
#include "write-full.h"
#include "istream-raw-mbox.h"
#include "mbox-storage.h"
#include "mbox-file.h"
#include "mbox-lock.h"
#include "mbox-sync-private.h"
#include <stddef.h>
#include <stdlib.h>
dest++;
for (i = 0; i < size; i++) {
return TRUE;
return FALSE;
int ret;
if (uid == 0) {
sizeof(*sync_rec));
if (ret < 0) {
if (ret == 0) {
if (!*sync_expunge_r)
for (i = 0; i < size; i++) {
int ret = 0;
if (ret < 0) {
ret = 0;
return ret;
unsigned char hdr_md5_sum[],
const void *data;
int ret;
if (ret < 0) {
&data) < 0) {
int nocheck)
const void *data;
if (!nocheck) {
&data) < 0) {
INDEX_KEYWORDS_BYTE_COUNT) == 0) {
MAIL_INDEX_MAIL_FLAG_DIRTY) != 0;
INDEX_KEYWORDS_BYTE_COUNT) != 0) {
const unsigned char *data;
if (from_line_size == 0)
int ret;
if (ret < 0)
if (ret > 0) {
move_diff = 0;
if (seq == 0) {
seq++;
if (ret < 0) {
if (ret == 0) {
old_offset) < 0) {
uid = 0;
if (seq1 == 0) {
file_size) < 0) {
messages_count : 0);
&expunged) < 0)
if (size == 0)
if (ret <= 0)
return ret;
uid = 0;
if (uid != 0) {
if (ret < 0)
if (ret == 0)
uid = 0;
&rec) < 0)
&expunged) < 0)
if (!expunged) {
if (!expunged) {
rec) < 0)
if (!expunged) {
if (!partial)
trailer_size) < 0)
min_msg_count = 0;
if (ret <= 0) {
if (ret < 0)
FALSE);
if (ret <= 0) {
unsigned int lock_id = 0;
if (!changed)
lock_id = 0;
if (changed) {
if (ret <= 0) {
if (ret < 0)
if (lock_id != 0)
return ret;
if (lock_id != 0)
if (lock_id == 0) {
goto __again;
if (ret < 0)
if (ret < 0)
if (ret < 0)
&seq,
&offset) < 0) {
index_sync_ctx) < 0) {
unsigned int read_lock_id = 0;
return ret;
struct mailbox_sync_context *
int ret = 0;