annotate src/lib-storage/index/mbox/mbox-sync-rewrite.c @ 2153:53288223de6c HEAD

Create X-Keywords header if possible.
author Timo Sirainen <tss@iki.fi>
date Fri, 18 Jun 2004 00:55:02 +0300
parents 16287320d080
children 282e993b92c4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 #include "lib.h"
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2 #include "buffer.h"
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "istream.h"
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "ostream.h"
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "str.h"
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "write-full.h"
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "message-parser.h"
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
8 #include "mbox-storage.h"
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "mbox-sync-private.h"
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "istream-raw-mbox.h"
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 int mbox_move(struct mbox_sync_context *sync_ctx,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 uoff_t dest, uoff_t source, uoff_t size)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 struct istream *input;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 struct ostream *output;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 off_t ret;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
19 i_assert(size < OFF_T_MAX);
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
20
2107
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
21 if (size == 0 || source == dest)
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
22 return 0;
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
23
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
24 istream_raw_mbox_flush(sync_ctx->input);
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
25
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 output = o_stream_create_file(sync_ctx->fd, default_pool, 4096, FALSE);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 i_stream_seek(sync_ctx->file_input, source);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 o_stream_seek(output, dest);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 if (size == (uoff_t)-1) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31 input = sync_ctx->file_input;
2107
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
32 ret = o_stream_send_istream(output, input) < 0 ? -1 : 0;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 } else {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 input = i_stream_create_limit(default_pool,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 sync_ctx->file_input,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 source, size);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 ret = o_stream_send_istream(output, input);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 i_stream_unref(input);
2107
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
39 ret = ret == (off_t)size ? 0 : -1;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 }
2107
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
41
2124
24651c3ac7f3 major syncing code cleanups. the code finally looks almost readable. logic
Timo Sirainen <tss@iki.fi>
parents: 2119
diff changeset
42 if (ret < 0) {
24651c3ac7f3 major syncing code cleanups. the code finally looks almost readable. logic
Timo Sirainen <tss@iki.fi>
parents: 2119
diff changeset
43 errno = output->stream_errno;
24651c3ac7f3 major syncing code cleanups. the code finally looks almost readable. logic
Timo Sirainen <tss@iki.fi>
parents: 2119
diff changeset
44 mbox_set_syscall_error(sync_ctx->ibox,
24651c3ac7f3 major syncing code cleanups. the code finally looks almost readable. logic
Timo Sirainen <tss@iki.fi>
parents: 2119
diff changeset
45 "o_stream_send_istream()");
24651c3ac7f3 major syncing code cleanups. the code finally looks almost readable. logic
Timo Sirainen <tss@iki.fi>
parents: 2119
diff changeset
46 }
24651c3ac7f3 major syncing code cleanups. the code finally looks almost readable. logic
Timo Sirainen <tss@iki.fi>
parents: 2119
diff changeset
47
2107
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
48 o_stream_unref(output);
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
49 return (int)ret;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 static void mbox_sync_headers_add_space(struct mbox_sync_mail_context *ctx,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53 size_t size)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54 {
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
55 size_t data_size, pos, start_pos;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 const unsigned char *data;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 void *p;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58
2146
3a33250e6a2d Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents: 2126
diff changeset
59 i_assert(size < SSIZE_T_MAX);
3a33250e6a2d Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents: 2126
diff changeset
60
2153
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
61 if (ctx->hdr_pos[MBOX_HDR_X_KEYWORDS] == (size_t)-1 &&
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
62 size >= sizeof("X-Keywords: \n")-1) {
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
63 /* Add X-Keywords */
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
64 start_pos = str_len(ctx->header);
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
65 if (ctx->have_eoh)
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
66 start_pos--;
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
67 ctx->hdr_pos[MBOX_HDR_X_KEYWORDS] = start_pos;
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
68
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
69 str_insert(ctx->header, start_pos, "X-Keywords: \n");
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
70 size -= sizeof("X-Keywords: \n")-1;
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
71 } else {
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
72 /* Append at the end of X-Keywords header,
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
73 or X-UID if it doesn't exist */
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
74 start_pos = ctx->hdr_pos[MBOX_HDR_X_KEYWORDS] != (size_t)-1 ?
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
75 ctx->hdr_pos[MBOX_HDR_X_KEYWORDS] :
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
76 ctx->hdr_pos[MBOX_HDR_X_UID];
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
77 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
79 data = str_data(ctx->header);
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
80 data_size = str_len(ctx->header);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
82 for (pos = start_pos; pos < data_size; pos++) {
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
83 if (data[pos] == '\n') {
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
84 /* possibly continues in next line */
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
85 if (pos+1 == data_size || !IS_LWSP(data[pos+1]))
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
86 break;
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
87 start_pos = pos+1;
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
88 } else if (!IS_LWSP(data[pos])) {
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
89 start_pos = pos+1;
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
90 }
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
91 }
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
92
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
93 /* pos points to end of headers now, and start_pos to beginning of
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
94 whitespace. */
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 buffer_copy(ctx->header, pos + size,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96 ctx->header, pos, (size_t)-1);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 p = buffer_get_space_unsafe(ctx->header, pos, size);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98 memset(p, ' ', size);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
100 ctx->mail.offset = ctx->hdr_offset + start_pos;
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
101 ctx->mail.space = (pos - start_pos) + size;
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
102
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 if (ctx->header_first_change > pos)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104 ctx->header_first_change = pos;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105 ctx->header_last_change = (size_t)-1;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108 static void mbox_sync_header_remove_space(struct mbox_sync_mail_context *ctx,
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
109 size_t start_pos, size_t *size)
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
110 {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 const unsigned char *data;
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
112 size_t data_size, pos, last_line_pos;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
114 /* find the end of the LWSP */
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
115 data = str_data(ctx->header);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
116 data_size = str_len(ctx->header);
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
117
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
118 for (pos = last_line_pos = start_pos; pos < data_size; pos++) {
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
119 if (data[pos] == '\n') {
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
120 /* possibly continues in next line */
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
121 if (pos+1 == data_size || !IS_LWSP(data[pos+1])) {
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
122 data_size = pos;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
123 break;
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
124 }
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
125 last_line_pos = pos+1;
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
126 } else if (!IS_LWSP(data[pos])) {
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
127 start_pos = last_line_pos = pos+1;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
128 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
129 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
130
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
131 if (start_pos == data_size)
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
132 return;
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
133
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
134 /* and remove what we can */
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
135 if (ctx->header_first_change > start_pos)
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
136 ctx->header_first_change = start_pos;
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
137 ctx->header_last_change = (size_t)-1;
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
138
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
139 if (data_size - start_pos <= *size) {
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
140 /* remove it all */
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
141 str_delete(ctx->header, start_pos, data_size - start_pos);
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
142 *size -= data_size - start_pos;
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
143 return;
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
144 }
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
145
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
146 /* we have more space than needed. since we're removing from
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
147 the beginning of header instead of end, we don't have to
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
148 worry about multiline-headers. */
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
149 str_delete(ctx->header, start_pos, *size);
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
150 last_line_pos = last_line_pos <= *size ?
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
151 start_pos : last_line_pos - *size;
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
152
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
153 data_size -= *size;
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
154 *size = 0;
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
155
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
156 if (ctx->mail.space < data_size - last_line_pos) {
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
157 ctx->mail.space = data_size - last_line_pos;
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
158 ctx->mail.offset = ctx->hdr_offset + last_line_pos;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
159 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162 static void mbox_sync_headers_remove_space(struct mbox_sync_mail_context *ctx,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
163 size_t size)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164 {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
165 static enum header_position space_positions[] = {
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
166 MBOX_HDR_X_UID,
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
167 MBOX_HDR_X_KEYWORDS,
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
168 MBOX_HDR_X_IMAPBASE
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169 };
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
170 enum header_position pos;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
171 int i;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
172
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
173 ctx->mail.space = 0;
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
174 ctx->mail.offset = ctx->hdr_offset;
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
175
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
176 for (i = 0; i < 3 && size > 0; i++) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
177 pos = space_positions[i];
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
178 if (ctx->hdr_pos[pos] != (size_t)-1) {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
179 mbox_sync_header_remove_space(ctx, ctx->hdr_pos[pos],
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180 &size);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
181 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
182 }
2153
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
183
53288223de6c Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents: 2151
diff changeset
184 /* FIXME: see if we could remove X-Keywords header completely */
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
185 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
186
2107
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
187 int mbox_sync_try_rewrite(struct mbox_sync_mail_context *ctx, off_t move_diff)
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
188 {
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189 size_t old_hdr_size, new_hdr_size;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
190
1983
933cab442392 mbox growing and locking works now
Timo Sirainen <tss@iki.fi>
parents: 1981
diff changeset
191 i_assert(ctx->sync_ctx->ibox->mbox_lock_type == F_WRLCK);
933cab442392 mbox growing and locking works now
Timo Sirainen <tss@iki.fi>
parents: 1981
diff changeset
192
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
193 old_hdr_size = ctx->body_offset - ctx->hdr_offset;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
194 new_hdr_size = str_len(ctx->header);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
195
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
196 /* do we have enough space? */
1983
933cab442392 mbox growing and locking works now
Timo Sirainen <tss@iki.fi>
parents: 1981
diff changeset
197 if (new_hdr_size < old_hdr_size) {
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
198 mbox_sync_headers_add_space(ctx, old_hdr_size - new_hdr_size);
1983
933cab442392 mbox growing and locking works now
Timo Sirainen <tss@iki.fi>
parents: 1981
diff changeset
199 } else if (new_hdr_size > old_hdr_size) {
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
200 /* try removing the space where we can */
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
201 mbox_sync_headers_remove_space(ctx,
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
202 new_hdr_size - old_hdr_size);
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
203 new_hdr_size = str_len(ctx->header);
2107
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
204
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
205 if (new_hdr_size <= old_hdr_size) {
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
206 /* good, we removed enough. */
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
207 i_assert(new_hdr_size == old_hdr_size);
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
208 } else if (move_diff < 0 &&
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
209 new_hdr_size - old_hdr_size <= -move_diff) {
2107
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
210 /* moving backwards - we can use the extra space from
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
211 it, just update expunged_space accordingly */
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
212 i_assert(ctx->mail.space == 0);
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
213 i_assert(ctx->sync_ctx->expunged_space >=
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
214 new_hdr_size - old_hdr_size);
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
215 ctx->sync_ctx->expunged_space -=
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
216 new_hdr_size - old_hdr_size;
2107
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
217 } else {
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
218 /* couldn't get enough space */
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
219 i_assert(ctx->mail.space == 0);
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
220 ctx->mail.space =
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
221 -(ssize_t)(new_hdr_size - old_hdr_size);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
222 return 0;
2107
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
223 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
224 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
225
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
226 i_assert(ctx->mail.space >= 0);
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
227
2126
57078e1f2bfc more syncing fixes
Timo Sirainen <tss@iki.fi>
parents: 2124
diff changeset
228 if (ctx->header_first_change == (size_t)-1 && move_diff == 0) {
57078e1f2bfc more syncing fixes
Timo Sirainen <tss@iki.fi>
parents: 2124
diff changeset
229 /* no changes actually. we get here if index sync record told
57078e1f2bfc more syncing fixes
Timo Sirainen <tss@iki.fi>
parents: 2124
diff changeset
230 us to do something that was already there */
57078e1f2bfc more syncing fixes
Timo Sirainen <tss@iki.fi>
parents: 2124
diff changeset
231 return 1;
57078e1f2bfc more syncing fixes
Timo Sirainen <tss@iki.fi>
parents: 2124
diff changeset
232 }
2107
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
233
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
234 if (move_diff != 0 || ctx->no_partial_rewrite) {
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
235 /* forget about partial write optimizations */
2107
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
236 ctx->header_first_change = 0;
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
237 ctx->header_last_change = 0;
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
238 }
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
239
1983
933cab442392 mbox growing and locking works now
Timo Sirainen <tss@iki.fi>
parents: 1981
diff changeset
240 if (ctx->header_last_change != (size_t)-1 &&
933cab442392 mbox growing and locking works now
Timo Sirainen <tss@iki.fi>
parents: 1981
diff changeset
241 ctx->header_last_change != 0)
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
242 str_truncate(ctx->header, ctx->header_last_change);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
243
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
244 if (pwrite_full(ctx->sync_ctx->fd,
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
245 str_data(ctx->header) + ctx->header_first_change,
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
246 str_len(ctx->header) - ctx->header_first_change,
2107
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
247 ctx->hdr_offset + move_diff +
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
248 ctx->header_first_change) < 0) {
2124
24651c3ac7f3 major syncing code cleanups. the code finally looks almost readable. logic
Timo Sirainen <tss@iki.fi>
parents: 2119
diff changeset
249 mbox_set_syscall_error(ctx->sync_ctx->ibox, "pwrite_full()");
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
250 return -1;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
251 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
252 istream_raw_mbox_flush(ctx->sync_ctx->input);
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
253 return 1;
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
254 }
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
255
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
256 static int mbox_sync_read_and_move(struct mbox_sync_context *sync_ctx,
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
257 struct mbox_sync_mail *mails,
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
258 uint32_t seq, uint32_t idx,
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
259 uint32_t extra_per_mail,
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
260 uoff_t *end_offset)
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
261 {
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
262 struct mbox_sync_mail_context mail_ctx;
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
263 uint32_t old_prev_msg_uid;
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
264 uoff_t offset;
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
265
2146
3a33250e6a2d Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents: 2126
diff changeset
266 i_stream_seek(sync_ctx->input, mails[idx].offset);
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
267
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
268 memset(&mail_ctx, 0, sizeof(mail_ctx));
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
269 mail_ctx.sync_ctx = sync_ctx;
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
270 mail_ctx.seq = seq;
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
271 mail_ctx.header = sync_ctx->header;
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
272
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
273 mail_ctx.mail.offset = mails[idx].offset;
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
274 mail_ctx.mail.body_size = mails[idx].body_size;
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
275
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
276 /* mbox_sync_parse_next_mail() checks that UIDs are growing,
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
277 so we have to fool it. */
2146
3a33250e6a2d Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents: 2126
diff changeset
278 old_prev_msg_uid = sync_ctx->prev_msg_uid;
3a33250e6a2d Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents: 2126
diff changeset
279 sync_ctx->prev_msg_uid = mails[idx].uid-1;
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
280 sync_ctx->dest_first_mail = seq == 1;
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
281
2146
3a33250e6a2d Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents: 2126
diff changeset
282 mbox_sync_parse_next_mail(sync_ctx->input, &mail_ctx, TRUE);
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
283 if (mails[idx].space != 0)
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
284 mbox_sync_update_header_from(&mail_ctx, &mails[idx]);
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
285 else {
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
286 /* updating might just try to add headers and mess up our
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
287 calculations completely. so only add the EOH here. */
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
288 if (mail_ctx.have_eoh)
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
289 str_append_c(mail_ctx.header, '\n');
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
290 }
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
291
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
292 sync_ctx->prev_msg_uid = old_prev_msg_uid;
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
293 sync_ctx->dest_first_mail = FALSE;
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
294
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
295 mail_ctx.mail.space =
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
296 -(ssize_t)(str_len(mail_ctx.header) -
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
297 (mail_ctx.body_offset - mail_ctx.hdr_offset));
2111
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
298 i_assert(mail_ctx.mail.space == mails[idx].space);
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
299
1983
933cab442392 mbox growing and locking works now
Timo Sirainen <tss@iki.fi>
parents: 1981
diff changeset
300 if (mail_ctx.mail.space <= 0)
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
301 mbox_sync_headers_add_space(&mail_ctx, extra_per_mail);
1983
933cab442392 mbox growing and locking works now
Timo Sirainen <tss@iki.fi>
parents: 1981
diff changeset
302 else if (mail_ctx.mail.space <= extra_per_mail) {
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
303 mbox_sync_headers_add_space(&mail_ctx, extra_per_mail -
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
304 mail_ctx.mail.space);
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
305 } else {
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
306 mbox_sync_headers_remove_space(&mail_ctx, mail_ctx.mail.space -
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
307 extra_per_mail);
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
308 }
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
309
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
310 /* now we have to move it. first move the body of the message,
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
311 then write the header and leave the extra space to beginning of
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
312 headers. */
2146
3a33250e6a2d Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents: 2126
diff changeset
313 offset = sync_ctx->input->v_offset;
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
314 if (mbox_move(sync_ctx, offset + mails[idx+1].space, offset,
2124
24651c3ac7f3 major syncing code cleanups. the code finally looks almost readable. logic
Timo Sirainen <tss@iki.fi>
parents: 2119
diff changeset
315 *end_offset - offset - mails[idx+1].space) < 0)
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
316 return -1;
2118
11febaee5e9b Save mbox offsets to index file using extra_records. Some other fixes.
Timo Sirainen <tss@iki.fi>
parents: 2111
diff changeset
317 mails[idx+1].from_offset += mails[idx+1].space;
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
318
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
319 *end_offset = offset + mails[idx+1].space - str_len(mail_ctx.header);
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
320
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
321 if (pwrite_full(sync_ctx->fd, str_data(mail_ctx.header),
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
322 str_len(mail_ctx.header), *end_offset) < 0) {
2124
24651c3ac7f3 major syncing code cleanups. the code finally looks almost readable. logic
Timo Sirainen <tss@iki.fi>
parents: 2119
diff changeset
323 mbox_set_syscall_error(sync_ctx->ibox, "pwrite_full()");
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
324 return -1;
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
325 }
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
326
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
327 mails[idx].offset = *end_offset;
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
328 mails[idx].space += mails[idx+1].space - extra_per_mail;
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
329 return 0;
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
330 }
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
331
2111
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
332 static int mbox_sync_fill_leftover(struct mbox_sync_context *sync_ctx,
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
333 struct mbox_sync_mail *mails,
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
334 uint32_t seq, uint32_t idx,
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
335 uoff_t start_offset, uoff_t end_offset)
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
336 {
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
337 struct mbox_sync_mail_context mail_ctx;
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
338 uint32_t old_prev_msg_uid;
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
339
2146
3a33250e6a2d Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents: 2126
diff changeset
340 i_assert(start_offset < end_offset);
3a33250e6a2d Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents: 2126
diff changeset
341 i_stream_seek(sync_ctx->input, mails[idx].offset);
2111
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
342
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
343 memset(&mail_ctx, 0, sizeof(mail_ctx));
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
344 mail_ctx.sync_ctx = sync_ctx;
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
345 mail_ctx.seq = seq;
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
346 mail_ctx.header = sync_ctx->header;
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
347
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
348 mail_ctx.mail.offset = mails[idx].offset;
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
349 mail_ctx.mail.body_size = mails[idx].body_size;
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
350
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
351 /* mbox_sync_parse_next_mail() checks that UIDs are growing,
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
352 so we have to fool it. */
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
353 old_prev_msg_uid = sync_ctx->prev_msg_uid;
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
354 sync_ctx->prev_msg_uid = mails[idx].uid-1;
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
355 sync_ctx->dest_first_mail = seq == 1;
2111
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
356
2146
3a33250e6a2d Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents: 2126
diff changeset
357 mbox_sync_parse_next_mail(sync_ctx->input, &mail_ctx, TRUE);
2111
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
358 mbox_sync_update_header_from(&mail_ctx, &mails[idx]);
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
359
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
360 sync_ctx->prev_msg_uid = old_prev_msg_uid;
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
361 sync_ctx->dest_first_mail = FALSE;
2111
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
362
2146
3a33250e6a2d Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents: 2126
diff changeset
363 mbox_sync_headers_add_space(&mail_ctx,end_offset - start_offset);
2111
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
364
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
365 if (pwrite_full(sync_ctx->fd, str_data(mail_ctx.header),
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
366 str_len(mail_ctx.header), start_offset) < 0) {
2124
24651c3ac7f3 major syncing code cleanups. the code finally looks almost readable. logic
Timo Sirainen <tss@iki.fi>
parents: 2119
diff changeset
367 mbox_set_syscall_error(sync_ctx->ibox, "pwrite_full()");
2111
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
368 return -1;
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
369 }
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
370
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
371 mails[idx].offset = start_offset;
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
372 return 0;
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
373 }
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
374
2124
24651c3ac7f3 major syncing code cleanups. the code finally looks almost readable. logic
Timo Sirainen <tss@iki.fi>
parents: 2119
diff changeset
375 int mbox_sync_rewrite(struct mbox_sync_context *sync_ctx,
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
376 uint32_t first_seq, uint32_t last_seq, off_t extra_space)
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
377 {
1978
6303ef092c5b mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents: 1915
diff changeset
378 struct mbox_sync_mail *mails;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
379 size_t size;
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
380 uoff_t offset, start_offset, end_offset, dest_offset;
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
381 uint32_t idx, extra_per_mail;
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
382 int ret = 0;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
383
2107
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
384 i_assert(first_seq != last_seq);
1983
933cab442392 mbox growing and locking works now
Timo Sirainen <tss@iki.fi>
parents: 1981
diff changeset
385 i_assert(sync_ctx->ibox->mbox_lock_type == F_WRLCK);
933cab442392 mbox growing and locking works now
Timo Sirainen <tss@iki.fi>
parents: 1981
diff changeset
386
2124
24651c3ac7f3 major syncing code cleanups. the code finally looks almost readable. logic
Timo Sirainen <tss@iki.fi>
parents: 2119
diff changeset
387 mails = buffer_get_modifyable_data(sync_ctx->mails, &size);
2118
11febaee5e9b Save mbox offsets to index file using extra_records. Some other fixes.
Timo Sirainen <tss@iki.fi>
parents: 2111
diff changeset
388 i_assert(size / sizeof(*mails) == last_seq - first_seq + 1);
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
389
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
390 /* if there's expunges in mails[], we would get more correct balancing
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
391 by counting only them here. however, that might make us overwrite
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
392 data which hasn't yet been copied backwards. to avoid too much
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
393 complexity, we just leave all the rest of the extra space to first
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
394 mail */
2110
18d29a565168 some more fixes
Timo Sirainen <tss@iki.fi>
parents: 2109
diff changeset
395 extra_per_mail = extra_space / (last_seq - first_seq + 1);
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
396 idx = last_seq - first_seq;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
397
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
398 if (mails[idx].uid != 0)
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
399 mails[idx].space -= extra_per_mail;
2107
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
400 i_assert(mails[idx].space >= 0);
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
401 end_offset = mails[idx].offset + mails[idx].space;
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
402
2151
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
403 /* after expunge the next mail must have been missing space, or we
16287320d080 Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents: 2146
diff changeset
404 would have moved it backwards already */
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
405 i_assert(mails[0].space < 0 || mails[0].uid == 0);
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
406 start_offset = mails[0].offset;
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
407
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
408 /* start moving backwards */
2107
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
409 do {
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
410 idx--;
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
411 if (mails[idx].space <= 0 && mails[idx].uid != 0) {
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
412 /* offset points to beginning of headers. read the
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
413 header again, update it and give enough space to
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
414 it */
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
415 if (mbox_sync_read_and_move(sync_ctx, mails,
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
416 first_seq + idx, idx,
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
417 extra_per_mail,
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
418 &end_offset) < 0) {
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
419 ret = -1;
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
420 break;
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
421 }
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
422 } else {
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
423 /* X-Keywords: xx [offset] \n
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
424 ...
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
425 X-Keywords: xx [end_offset] \n
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
426
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
427 move data forward so mails before us gets the extra
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
428 space (ie. we temporarily get more space to us) */
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
429 offset = mails[idx].offset + mails[idx].space;
2041
2240a38138db mbox syncing fixes
Timo Sirainen <tss@iki.fi>
parents: 1983
diff changeset
430 dest_offset = offset + mails[idx+1].space;
2240a38138db mbox syncing fixes
Timo Sirainen <tss@iki.fi>
parents: 1983
diff changeset
431 if (mbox_move(sync_ctx, dest_offset, offset,
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
432 end_offset - dest_offset) < 0) {
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
433 ret = -1;
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
434 break;
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
435 }
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
436
2118
11febaee5e9b Save mbox offsets to index file using extra_records. Some other fixes.
Timo Sirainen <tss@iki.fi>
parents: 2111
diff changeset
437 mails[idx+1].from_offset += mails[idx+1].space;
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
438
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
439 mails[idx].space += mails[idx+1].space;
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
440 if (mails[idx].uid != 0)
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
441 mails[idx].space -= extra_per_mail;
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
442 i_assert(mails[idx].space > 0);
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
443 end_offset = mails[idx].offset + mails[idx].space;
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
444 }
2107
8266299b92f5 expunging is somewhat working
Timo Sirainen <tss@iki.fi>
parents: 2041
diff changeset
445 } while (idx > 0);
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
446
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
447 if (end_offset != start_offset) {
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
448 /* some space was left over - give it to first message. */
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
449 if (mails[0].uid == 0) {
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
450 /* "body" start_offset .. end_offset "\nFrom .."
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
451 we need to move From-line to start_offset */
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
452 offset = mails[1].offset;
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
453 if (mbox_move(sync_ctx, start_offset, end_offset,
2124
24651c3ac7f3 major syncing code cleanups. the code finally looks almost readable. logic
Timo Sirainen <tss@iki.fi>
parents: 2119
diff changeset
454 offset - end_offset) < 0)
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
455 ret = -1;
2119
Timo Sirainen <tss@iki.fi>
parents: 2118
diff changeset
456 mails[1].from_offset -= end_offset - start_offset;
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
457 idx++;
2111
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
458
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
459 start_offset += offset - end_offset;
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
460 end_offset = offset;
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
461 } else {
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
462 /* "\nFrom ..\n" start_offset .. end_offset "hdr.." */
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
463 }
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
464
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
465 /* now parse it again and give it more space */
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
466 mails[idx].space = extra_per_mail;
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
467 mails[idx+1].space = 0; /* from_offset doesn't move.. */
2111
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
468 if (mbox_sync_fill_leftover(sync_ctx, mails,
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
469 first_seq + idx, idx,
2111
eb26aa46686d Fixes for expunging first message
Timo Sirainen <tss@iki.fi>
parents: 2110
diff changeset
470 start_offset, end_offset) < 0)
2109
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
471 ret = -1;
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
472 }
8c0168d19148 expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents: 2107
diff changeset
473
1981
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
474 istream_raw_mbox_flush(sync_ctx->input);
eb282832fc75 mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents: 1978
diff changeset
475 return ret;
1915
79790750c349 importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
476 }