mbox-sync-rewrite.c revision dda2c506c8fc8ac2f88272de4523ded42baa0aa0
#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;
}
{
const unsigned char *data;
void *p;
/* Append at the end of X-Keywords header,
or X-UID if it doesn't exist */
pos++;
else
}
{
const unsigned char *data;
/* find the end of the lwsp */
break;
} else {
}
}
/* and remove what we can */
nonspace++;
} else {
*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);
}
}
}
{
const unsigned char *data;
/* do we have enough space? */
if (new_hdr_size < old_hdr_size) {
} else if (new_hdr_size > old_hdr_size) {
/* moving backwards - we can use the extra space from
it, just update expunged_space accordingly */
} else {
return 0;
}
}
if (move_diff != 0) {
/* we're moving the header, forget about partial write
optimizations */
ctx->header_first_change = 0;
ctx->header_last_change = 0;
}
/* FIXME: last_change should rather just tell if we want to truncate
to beginning of extra whitespace */
ctx->header_last_change != 0)
ctx->header_first_change) < 0) {
return -1;
}
return 1;
}
struct mbox_sync_mail *mails,
{
struct mbox_sync_mail_context mail_ctx;
/* 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. */
}
} else {
}
/* now we have to move it. first move the body of the message,
then write the header and leave the extra space to beginning of
headers. */
return -1;
return -1;
}
return 0;
}
struct mbox_sync_mail *mails,
{
struct mbox_sync_mail_context mail_ctx;
/* mbox_sync_parse_next_mail() checks that UIDs are growing,
so we have to fool it. */
return -1;
}
return 0;
}
{
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 {
idx--;
/* offset points to beginning of headers. read the
header again, update it and give enough space to
it */
&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;
}
}
} while (idx > 0);
if (end_offset != start_offset) {
/* some space was left over - give it to first message. */
/* "body" start_offset .. end_offset "\nFrom .."
we need to move From-line to start_offset */
offset - end_offset) < 0)
ret = -1;
idx++;
end_offset = offset;
} else {
/* "\nFrom ..\n" start_offset .. end_offset "hdr.." */
}
/* now parse it again and give it more space */
start_offset, end_offset) < 0)
ret = -1;
}
return ret;
}