mbox-sync-rewrite.c revision f16c114c20bbd7d292d93415d1e56c8dd6abd3e7
#include "lib.h"
#include "buffer.h"
#include "istream.h"
#include "ostream.h"
#include "str.h"
#include "write-full.h"
#include "message-parser.h"
#include "mbox-storage.h"
#include "mbox-sync-private.h"
#include "istream-raw-mbox.h"
{
return 0;
} else {
}
if (ret < 0) {
"o_stream_send_istream()");
}
return (int)ret;
}
{
unsigned char space[1024];
return -1;
}
}
return -1;
}
return 0;
}
{
const unsigned char *data;
void *p;
else {
/* Append at the end of X-Keywords header,
or X-UID if it doesn't exist */
}
/* possibly continues in next line */
break;
}
}
/* pos points to end of header now, and start_pos to beginning
of whitespace. */
/* we're rewriting messages and moving space towards beginning
of file. it's useless to write lots of spaces because we're
overwriting it soon anyway. */
} else {
if (skip_space_pos_r != NULL)
}
}
{
const unsigned char *data;
/* find the end of the LWSP */
/* possibly continues in next line */
break;
}
}
}
return;
/* and remove what we can */
/* remove it all */
return;
}
/* we have more space than needed. since we're removing from
the beginning of header instead of end, we don't have to
worry about multiline-headers. */
else
last_line_pos -= *size;
*size = 0;
}
}
{
static enum header_position space_positions[] = {
};
enum header_position pos;
int i;
for (i = 0; i < 3 && size > 0; i++) {
pos = space_positions[i];
&size);
}
}
/* FIXME: see if we could remove X-Keywords header completely */
}
int leave_space_hole)
{
if (new_hdr_size <= old_hdr_size) {
/* add space. note that we must call add_space() even if we're
not adding anything so mail.offset gets fixed. */
} else if (new_hdr_size > old_hdr_size) {
/* try removing the space where we can */
if (new_hdr_size <= old_hdr_size) {
/* good, we removed enough. */
} else if (move_diff < 0 &&
/* moving backwards - we can use the extra space from
it, just update expunged_space accordingly */
} else {
/* couldn't get enough space */
return 0;
}
}
/* no changes actually. we get here if index sync record told
us to do something that was already there */
return 1;
}
/* forget about partial write optimizations */
ctx->header_first_change = 0;
ctx->header_last_change = 0;
}
ctx->header_last_change != 0)
move_diff) < 0) {
return -1;
}
move_diff) < 0) {
"pwrite_full()");
return -1;
}
}
}
return 1;
}
struct mbox_sync_mail *mails,
{
struct mbox_sync_mail_context mail_ctx;
return -1;
/* mbox_sync_parse_next_mail() checks that UIDs are growing,
so we have to fool it. */
else {
/* updating might just try to add headers and mess up our
calculations completely. so only add the EOH here. */
}
(space_diff - need_space));
} else {
}
/* move the body of this message and headers of next message forward,
then write the headers */
end_offset - dest_offset) < 0)
return -1;
hdr_size, hdr_offset) < 0) {
return -1;
}
/* skip over the space in header, it's written later. */
return -1;
}
}
sync_ctx->update_base_uid_last = 0;
}
return 0;
}
/* extra_space specifies how many bytes from last_seq's space will be left
over after all the rewrites. */
{
struct mbox_sync_mail *mails;
int ret = 0;
/* if there's expunges in mails[], we would get more correct balancing
by counting only them here. however, that might make us overwrite
data which hasn't yet been copied backwards. to avoid too much
complexity, we just leave all the rest of the extra space to first
mail */
/* after expunge the next mail must have been missing space, or we
would have moved it backwards already */
/* start moving backwards. */
do {
/* this message's body is always moved space_diff bytes
forward along with next message's headers, so current
message gets temporarily space_diff amount of padding.
the moving stops at next message's beginning of padding.
each message gets left padding_per_mail bytes of space.
what gets left over is given to first message */
}
idx--;
/* offset points to beginning of headers. read the
header again, update it and give enough space to
fill space_diff */
end_offset) < 0) {
ret = -1;
break;
}
} else {
/* X-Keywords: xx [offset]\n
...
X-Keywords: xx [end_offset] \n
move data forward so mails before us gets the extra
space (ie. we temporarily get more space to us) */
end_offset - dest_offset) < 0) {
ret = -1;
break;
}
}
ret = -1;
break;
}
}
} while (idx > 0);
ret = -1;
}
return ret;
}