Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/index/mbox/mbox-sync-rewrite.c @ 2379:9a6d22b5bb7a HEAD
mbox corruption fix
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 30 Jul 2004 04:03:59 +0300 |
parents | c48822c8713f |
children | 8ef002a26f1c |
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 | 21 if (size == 0 || source == dest) |
22 return 0; | |
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 | 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 | 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 | 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 | 48 o_stream_unref(output); |
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 |
2164 | 52 static int mbox_fill_space(struct mbox_sync_context *sync_ctx, |
53 uoff_t offset, uoff_t size) | |
54 { | |
55 unsigned char space[1024]; | |
56 | |
57 memset(space, ' ', sizeof(space)); | |
58 while (size > sizeof(space)) { | |
59 if (pwrite_full(sync_ctx->fd, space, | |
60 sizeof(space), offset) < 0) { | |
61 mbox_set_syscall_error(sync_ctx->ibox, "pwrite_full()"); | |
62 return -1; | |
63 } | |
64 size -= sizeof(space); | |
65 } | |
66 | |
67 if (pwrite_full(sync_ctx->fd, space, size, offset) < 0) { | |
68 mbox_set_syscall_error(sync_ctx->ibox, "pwrite_full()"); | |
69 return -1; | |
70 } | |
71 return 0; | |
72 } | |
73 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 static void mbox_sync_headers_add_space(struct mbox_sync_mail_context *ctx, |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
75 size_t size, size_t *skip_space_pos_r) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 { |
2151
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
77 size_t data_size, pos, start_pos; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 const unsigned char *data; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 void *p; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 |
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
|
81 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
|
82 |
2250
7b70a60c0f9d
some fixes for handling pseudo headers.
Timo Sirainen <tss@iki.fi>
parents:
2249
diff
changeset
|
83 if (ctx->pseudo) |
7b70a60c0f9d
some fixes for handling pseudo headers.
Timo Sirainen <tss@iki.fi>
parents:
2249
diff
changeset
|
84 start_pos = ctx->hdr_pos[MBOX_HDR_X_IMAPBASE]; |
7b70a60c0f9d
some fixes for handling pseudo headers.
Timo Sirainen <tss@iki.fi>
parents:
2249
diff
changeset
|
85 else { |
7b70a60c0f9d
some fixes for handling pseudo headers.
Timo Sirainen <tss@iki.fi>
parents:
2249
diff
changeset
|
86 /* Append at the end of X-Keywords header, |
7b70a60c0f9d
some fixes for handling pseudo headers.
Timo Sirainen <tss@iki.fi>
parents:
2249
diff
changeset
|
87 or X-UID if it doesn't exist */ |
7b70a60c0f9d
some fixes for handling pseudo headers.
Timo Sirainen <tss@iki.fi>
parents:
2249
diff
changeset
|
88 start_pos = ctx->hdr_pos[MBOX_HDR_X_KEYWORDS] != (size_t)-1 ? |
7b70a60c0f9d
some fixes for handling pseudo headers.
Timo Sirainen <tss@iki.fi>
parents:
2249
diff
changeset
|
89 ctx->hdr_pos[MBOX_HDR_X_KEYWORDS] : |
7b70a60c0f9d
some fixes for handling pseudo headers.
Timo Sirainen <tss@iki.fi>
parents:
2249
diff
changeset
|
90 ctx->hdr_pos[MBOX_HDR_X_UID]; |
7b70a60c0f9d
some fixes for handling pseudo headers.
Timo Sirainen <tss@iki.fi>
parents:
2249
diff
changeset
|
91 } |
7b70a60c0f9d
some fixes for handling pseudo headers.
Timo Sirainen <tss@iki.fi>
parents:
2249
diff
changeset
|
92 i_assert(start_pos != (size_t)-1); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
93 |
2151
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
94 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
|
95 data_size = str_len(ctx->header); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
96 |
2151
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
97 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
|
98 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
|
99 /* 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
|
100 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
|
101 break; |
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
102 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
|
103 } 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
|
104 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
|
105 } |
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
106 } |
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
107 |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
108 /* pos points to end of header now, and start_pos to beginning |
2164 | 109 of whitespace. */ |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
110 |
2379 | 111 if (size > 1024 && skip_space_pos_r != NULL) { |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
112 /* we're rewriting messages and moving space towards beginning |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
113 of file. it's useless to write lots of spaces because we're |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
114 overwriting it soon anyway. */ |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
115 *skip_space_pos_r = start_pos; |
2379 | 116 |
117 /* we'll have to delete the existing space */ | |
118 buffer_delete(ctx->header, start_pos, pos - start_pos); | |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
119 } else { |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
120 if (skip_space_pos_r != NULL) |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
121 *skip_space_pos_r = (size_t)-1; |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
122 |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
123 buffer_copy(ctx->header, pos + size, |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
124 ctx->header, pos, (size_t)-1); |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
125 p = buffer_get_space_unsafe(ctx->header, pos, size); |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
126 memset(p, ' ', size); |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
127 } |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
128 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
129 if (ctx->header_first_change > pos) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
130 ctx->header_first_change = pos; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
131 ctx->header_last_change = (size_t)-1; |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
132 |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
133 ctx->mail.offset = ctx->hdr_offset + start_pos; |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
134 ctx->mail.space = (pos - start_pos) + size; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
135 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
136 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
137 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
|
138 size_t start_pos, size_t *size) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
139 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
140 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
|
141 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
|
142 |
2151
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
143 /* find the end of the LWSP */ |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
144 data = str_data(ctx->header); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
145 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
|
146 |
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
147 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
|
148 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
|
149 /* 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
|
150 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
|
151 data_size = pos; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
152 break; |
2151
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
153 } |
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
154 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
|
155 } 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
|
156 start_pos = last_line_pos = pos+1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
157 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
158 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
159 |
2151
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
160 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
|
161 return; |
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
162 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
163 /* 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
|
164 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
|
165 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
|
166 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
|
167 |
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
168 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
|
169 /* remove it all */ |
2249
cb4dad60f6cd
Several fixes for updating mbox. Recent changes also made it corrupt
Timo Sirainen <tss@iki.fi>
parents:
2214
diff
changeset
|
170 mbox_sync_move_buffer(ctx, start_pos, 0, data_size - start_pos); |
2151
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
171 *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
|
172 return; |
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
173 } |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
174 |
2151
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
175 /* 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
|
176 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
|
177 worry about multiline-headers. */ |
2249
cb4dad60f6cd
Several fixes for updating mbox. Recent changes also made it corrupt
Timo Sirainen <tss@iki.fi>
parents:
2214
diff
changeset
|
178 mbox_sync_move_buffer(ctx, start_pos, 0, *size); |
2176 | 179 if (last_line_pos <= start_pos + *size) |
180 last_line_pos = start_pos; | |
181 else | |
182 last_line_pos -= *size; | |
183 data_size -= *size; | |
2151
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
184 |
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
185 *size = 0; |
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
186 |
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
187 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
|
188 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
|
189 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
|
190 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
192 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
193 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
|
194 size_t size) |
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 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
|
197 MBOX_HDR_X_UID, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 MBOX_HDR_X_KEYWORDS, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
199 MBOX_HDR_X_IMAPBASE |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 }; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 enum header_position pos; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
202 int i; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
204 ctx->mail.space = 0; |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
205 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
|
206 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
207 for (i = 0; i < 3 && size > 0; i++) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
208 pos = space_positions[i]; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
209 if (ctx->hdr_pos[pos] != (size_t)-1) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
210 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
|
211 &size); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
212 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
213 } |
2153
53288223de6c
Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents:
2151
diff
changeset
|
214 |
53288223de6c
Create X-Keywords header if possible.
Timo Sirainen <tss@iki.fi>
parents:
2151
diff
changeset
|
215 /* 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
|
216 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
217 |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
218 int mbox_sync_try_rewrite(struct mbox_sync_mail_context *ctx, off_t move_diff, |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
219 int leave_space_hole) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
220 { |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
221 size_t old_hdr_size, new_hdr_size, space_pos, hdr_size; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
222 |
1983
933cab442392
mbox growing and locking works now
Timo Sirainen <tss@iki.fi>
parents:
1981
diff
changeset
|
223 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
|
224 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
225 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
|
226 new_hdr_size = str_len(ctx->header); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
227 |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
228 space_pos = (size_t)-1; |
2164 | 229 if (new_hdr_size <= old_hdr_size) { |
230 /* add space. note that we must call add_space() even if we're | |
231 not adding anything so mail.offset gets fixed. */ | |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
232 mbox_sync_headers_add_space(ctx, old_hdr_size - new_hdr_size, |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
233 leave_space_hole ? |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
234 &space_pos : NULL); |
1983
933cab442392
mbox growing and locking works now
Timo Sirainen <tss@iki.fi>
parents:
1981
diff
changeset
|
235 } 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
|
236 /* 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
|
237 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
|
238 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
|
239 new_hdr_size = str_len(ctx->header); |
2107 | 240 |
2151
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
241 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
|
242 /* 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
|
243 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
|
244 } 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
|
245 new_hdr_size - old_hdr_size <= -move_diff) { |
2107 | 246 /* moving backwards - we can use the extra space from |
247 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 new_hdr_size - old_hdr_size; |
2107 | 253 } else { |
2151
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
254 /* 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
|
255 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
|
256 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
|
257 -(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
|
258 return 0; |
2107 | 259 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
260 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
261 |
2151
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
262 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
|
263 |
2126 | 264 if (ctx->header_first_change == (size_t)-1 && move_diff == 0) { |
265 /* no changes actually. we get here if index sync record told | |
266 us to do something that was already there */ | |
267 return 1; | |
268 } | |
2107 | 269 |
2151
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
270 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
|
271 /* forget about partial write optimizations */ |
2107 | 272 ctx->header_first_change = 0; |
273 ctx->header_last_change = 0; | |
274 } | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 |
1983
933cab442392
mbox growing and locking works now
Timo Sirainen <tss@iki.fi>
parents:
1981
diff
changeset
|
276 if (ctx->header_last_change != (size_t)-1 && |
933cab442392
mbox growing and locking works now
Timo Sirainen <tss@iki.fi>
parents:
1981
diff
changeset
|
277 ctx->header_last_change != 0) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
278 str_truncate(ctx->header, ctx->header_last_change); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
279 |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
280 i_assert(space_pos >= ctx->header_first_change); |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
281 |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
282 hdr_size = space_pos == (size_t)-1 ? str_len(ctx->header) : space_pos; |
2151
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
283 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
|
284 str_data(ctx->header) + ctx->header_first_change, |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
285 hdr_size - ctx->header_first_change, |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
286 ctx->hdr_offset + ctx->header_first_change + |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
287 move_diff) < 0) { |
2124
24651c3ac7f3
major syncing code cleanups. the code finally looks almost readable. logic
Timo Sirainen <tss@iki.fi>
parents:
2119
diff
changeset
|
288 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
|
289 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
290 } |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
291 if (space_pos != (size_t)-1) { |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
292 ctx->mail.flags |= MBOX_DIRTY_SPACE; |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
293 if (pwrite_full(ctx->sync_ctx->fd, |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
294 str_data(ctx->header) + space_pos, |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
295 str_len(ctx->header) - space_pos, |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
296 ctx->mail.offset + ctx->mail.space + |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
297 move_diff) < 0) { |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
298 mbox_set_syscall_error(ctx->sync_ctx->ibox, |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
299 "pwrite_full()"); |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
300 return -1; |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
301 } |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
302 } |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2176
diff
changeset
|
303 |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2176
diff
changeset
|
304 if (ctx->sync_ctx->dest_first_mail) { |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2176
diff
changeset
|
305 ctx->sync_ctx->base_uid_last = |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2176
diff
changeset
|
306 ctx->sync_ctx->update_base_uid_last; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2176
diff
changeset
|
307 ctx->sync_ctx->update_base_uid_last = 0; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2176
diff
changeset
|
308 } |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2176
diff
changeset
|
309 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
310 istream_raw_mbox_flush(ctx->sync_ctx->input); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
311 return 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
312 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
313 |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
314 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
|
315 struct mbox_sync_mail *mails, |
8c0168d19148
expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
316 uint32_t seq, uint32_t idx, |
2164 | 317 uoff_t space_diff, uoff_t end_offset) |
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 struct mbox_sync_mail_context mail_ctx; |
2109
8c0168d19148
expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
320 uint32_t old_prev_msg_uid; |
2164 | 321 uoff_t hdr_offset, offset, dest_offset; |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
322 size_t old_hdr_size, need_space, space_pos, hdr_size; |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
323 |
2155 | 324 if (mbox_sync_seek(sync_ctx, mails[idx].from_offset) < 0) |
325 return -1; | |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
326 |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
327 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
|
328 mail_ctx.sync_ctx = sync_ctx; |
2109
8c0168d19148
expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
329 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
|
330 mail_ctx.header = sync_ctx->header; |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
331 mail_ctx.uidl = sync_ctx->uidl; |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
332 str_truncate(mail_ctx.uidl, 0); |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
333 |
2164 | 334 hdr_offset = mails[idx].offset; |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
335 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
|
336 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
|
337 |
2109
8c0168d19148
expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
338 /* 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
|
339 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
|
340 old_prev_msg_uid = sync_ctx->prev_msg_uid; |
2250
7b70a60c0f9d
some fixes for handling pseudo headers.
Timo Sirainen <tss@iki.fi>
parents:
2249
diff
changeset
|
341 sync_ctx->prev_msg_uid = mails[idx].uid == 0 ? 0 : mails[idx].uid-1; |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2176
diff
changeset
|
342 sync_ctx->dest_first_mail = mails[idx].from_offset == 0; |
2109
8c0168d19148
expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
343 |
2214
c0b5573d76e3
fixes for From-line offset updating
Timo Sirainen <tss@iki.fi>
parents:
2190
diff
changeset
|
344 mbox_sync_parse_next_mail(sync_ctx->input, &mail_ctx); |
2109
8c0168d19148
expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
345 if (mails[idx].space != 0) |
8c0168d19148
expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
346 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
|
347 else { |
8c0168d19148
expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
348 /* 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
|
349 calculations completely. so only add the EOH here. */ |
8c0168d19148
expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
350 if (mail_ctx.have_eoh) |
8c0168d19148
expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
351 str_append_c(mail_ctx.header, '\n'); |
8c0168d19148
expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
352 } |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
353 |
2151
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
354 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
|
355 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
|
356 |
2164 | 357 old_hdr_size = mail_ctx.body_offset - mail_ctx.hdr_offset; |
358 need_space = str_len(mail_ctx.header) - mail_ctx.mail.space - | |
359 old_hdr_size; | |
360 i_assert(need_space == -mails[idx].space); | |
361 i_assert(space_diff >= need_space); | |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
362 |
2164 | 363 if (space_diff - need_space < (uoff_t)mail_ctx.mail.space) { |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
364 mbox_sync_headers_remove_space(&mail_ctx, mail_ctx.mail.space - |
2164 | 365 (space_diff - need_space)); |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
366 space_pos = (size_t)-1; |
2164 | 367 } else { |
368 mbox_sync_headers_add_space(&mail_ctx, space_diff - need_space - | |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
369 mail_ctx.mail.space, &space_pos); |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
370 } |
2164 | 371 mails[idx].offset = mail_ctx.mail.offset; |
372 mails[idx].space = mail_ctx.mail.space; | |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
373 |
2164 | 374 /* move the body of this message and headers of next message forward, |
375 then write the 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
|
376 offset = sync_ctx->input->v_offset; |
2164 | 377 dest_offset = offset + space_diff; |
378 if (mbox_move(sync_ctx, dest_offset, offset, | |
379 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
|
380 return -1; |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
381 |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
382 hdr_size = space_pos == (size_t)-1 ? |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
383 str_len(mail_ctx.header) : space_pos; |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
384 if (pwrite_full(sync_ctx->fd, str_data(mail_ctx.header), |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
385 hdr_size, hdr_offset) < 0) { |
2124
24651c3ac7f3
major syncing code cleanups. the code finally looks almost readable. logic
Timo Sirainen <tss@iki.fi>
parents:
2119
diff
changeset
|
386 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
|
387 return -1; |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
388 } |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
389 if (space_pos != (size_t)-1) { |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
390 /* skip over the space in header, it's written later. */ |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
391 mails[idx].flags |= MBOX_DIRTY_SPACE; |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
392 if (pwrite_full(sync_ctx->fd, |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
393 str_data(mail_ctx.header) + space_pos, |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
394 str_len(mail_ctx.header) - space_pos, |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
395 mails[idx].offset + mails[idx].space) < 0) { |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
396 mbox_set_syscall_error(sync_ctx->ibox, "pwrite_full()"); |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
397 return -1; |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
398 } |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
399 } |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
400 |
2190
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2176
diff
changeset
|
401 if (mails[idx].from_offset == 0) { |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2176
diff
changeset
|
402 sync_ctx->base_uid_last = |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2176
diff
changeset
|
403 sync_ctx->update_base_uid_last; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2176
diff
changeset
|
404 sync_ctx->update_base_uid_last = 0; |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2176
diff
changeset
|
405 } |
755ec9442a58
mailbox_save() and mailbox_copy() functions can now return the saved mail so
Timo Sirainen <tss@iki.fi>
parents:
2176
diff
changeset
|
406 |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
407 return 0; |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
408 } |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
409 |
2164 | 410 /* extra_space specifies how many bytes from last_seq's space will be left |
411 over after all the rewrites. */ | |
412 int mbox_sync_rewrite(struct mbox_sync_context *sync_ctx, uoff_t extra_space, | |
413 uint32_t first_seq, uint32_t last_seq) | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
414 { |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
415 struct mbox_sync_mail *mails; |
2164 | 416 uoff_t offset, end_offset, dest_offset, space_diff; |
2273
c48822c8713f
Updated comment about how syncing is done, and s/extra space/padding/
Timo Sirainen <tss@iki.fi>
parents:
2266
diff
changeset
|
417 uint32_t idx, padding_per_mail; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
418 size_t size; |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
419 int ret = 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
420 |
2107 | 421 i_assert(first_seq != last_seq); |
1983
933cab442392
mbox growing and locking works now
Timo Sirainen <tss@iki.fi>
parents:
1981
diff
changeset
|
422 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
|
423 |
2124
24651c3ac7f3
major syncing code cleanups. the code finally looks almost readable. logic
Timo Sirainen <tss@iki.fi>
parents:
2119
diff
changeset
|
424 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
|
425 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
|
426 |
2109
8c0168d19148
expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
427 /* 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
|
428 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
|
429 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
|
430 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
|
431 mail */ |
8c0168d19148
expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
432 idx = last_seq - first_seq; |
2273
c48822c8713f
Updated comment about how syncing is done, and s/extra space/padding/
Timo Sirainen <tss@iki.fi>
parents:
2266
diff
changeset
|
433 padding_per_mail = extra_space / (idx + 1); |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
434 |
2151
16287320d080
Several fixes in space/offset logic. Should be much more robust now.
Timo Sirainen <tss@iki.fi>
parents:
2146
diff
changeset
|
435 /* 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
|
436 would have moved it backwards already */ |
2250
7b70a60c0f9d
some fixes for handling pseudo headers.
Timo Sirainen <tss@iki.fi>
parents:
2249
diff
changeset
|
437 i_assert(mails[0].space < 0 || (mails[0].flags & MBOX_EXPUNGED) != 0); |
2164 | 438 |
439 /* start moving backwards. */ | |
440 do { | |
441 /* this message's body is always moved space_diff bytes | |
442 forward along with next message's headers, so current | |
2273
c48822c8713f
Updated comment about how syncing is done, and s/extra space/padding/
Timo Sirainen <tss@iki.fi>
parents:
2266
diff
changeset
|
443 message gets temporarily space_diff amount of padding. |
2109
8c0168d19148
expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
444 |
2273
c48822c8713f
Updated comment about how syncing is done, and s/extra space/padding/
Timo Sirainen <tss@iki.fi>
parents:
2266
diff
changeset
|
445 the moving stops at next message's beginning of padding. |
c48822c8713f
Updated comment about how syncing is done, and s/extra space/padding/
Timo Sirainen <tss@iki.fi>
parents:
2266
diff
changeset
|
446 each message gets left padding_per_mail bytes of space. |
c48822c8713f
Updated comment about how syncing is done, and s/extra space/padding/
Timo Sirainen <tss@iki.fi>
parents:
2266
diff
changeset
|
447 what gets left over is given to first message */ |
2164 | 448 i_assert(mails[idx].space > 0); |
449 space_diff = mails[idx].space; | |
450 end_offset = mails[idx].offset + mails[idx].space; | |
451 | |
2250
7b70a60c0f9d
some fixes for handling pseudo headers.
Timo Sirainen <tss@iki.fi>
parents:
2249
diff
changeset
|
452 if ((mails[idx].flags & MBOX_EXPUNGED) == 0) { |
2273
c48822c8713f
Updated comment about how syncing is done, and s/extra space/padding/
Timo Sirainen <tss@iki.fi>
parents:
2266
diff
changeset
|
453 space_diff -= padding_per_mail; |
c48822c8713f
Updated comment about how syncing is done, and s/extra space/padding/
Timo Sirainen <tss@iki.fi>
parents:
2266
diff
changeset
|
454 end_offset -= padding_per_mail; |
c48822c8713f
Updated comment about how syncing is done, and s/extra space/padding/
Timo Sirainen <tss@iki.fi>
parents:
2266
diff
changeset
|
455 mails[idx].space = padding_per_mail; |
2164 | 456 } |
457 | |
2107 | 458 idx--; |
2250
7b70a60c0f9d
some fixes for handling pseudo headers.
Timo Sirainen <tss@iki.fi>
parents:
2249
diff
changeset
|
459 if (mails[idx].space <= 0 && |
7b70a60c0f9d
some fixes for handling pseudo headers.
Timo Sirainen <tss@iki.fi>
parents:
2249
diff
changeset
|
460 (mails[idx].flags & MBOX_EXPUNGED) == 0) { |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
461 /* 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
|
462 header again, update it and give enough space to |
2164 | 463 fill space_diff */ |
2109
8c0168d19148
expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
464 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
|
465 first_seq + idx, idx, |
2164 | 466 space_diff, |
467 end_offset) < 0) { | |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
468 ret = -1; |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
469 break; |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
470 } |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
471 } else { |
2164 | 472 /* X-Keywords: xx [offset]\n |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
473 ... |
2164 | 474 X-Keywords: xx [end_offset] \n |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
475 |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
476 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
|
477 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
|
478 offset = mails[idx].offset + mails[idx].space; |
2164 | 479 dest_offset = offset + space_diff; |
2041 | 480 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
|
481 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
|
482 ret = -1; |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
483 break; |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
484 } |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
485 |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
486 mails[idx].space += space_diff; |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
487 mails[idx].flags |= MBOX_DIRTY_SPACE; |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
488 } |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
489 |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
490 mails[idx+1].from_offset += space_diff; |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
491 mails[idx+1].offset += space_diff; |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
492 |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
493 if ((mails[idx+1].flags & MBOX_DIRTY_SPACE) != 0) { |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
494 mails[idx+1].flags &= ~MBOX_DIRTY_SPACE; |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
495 if (mbox_fill_space(sync_ctx, mails[idx+1].offset, |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
496 mails[idx+1].space) < 0) { |
2164 | 497 ret = -1; |
498 break; | |
499 } | |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
500 } |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
501 } while (idx > 0); |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
502 |
2266
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
503 if ((mails[0].flags & MBOX_DIRTY_SPACE) != 0) { |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
504 mails[0].flags &= ~MBOX_DIRTY_SPACE; |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
505 if (mbox_fill_space(sync_ctx, mails[0].offset, |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
506 mails[0].space) < 0) |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
507 ret = -1; |
d6001ee7815d
Don't keep filling empty spaces which will be overwritten soon anyway. Major
Timo Sirainen <tss@iki.fi>
parents:
2250
diff
changeset
|
508 } |
2109
8c0168d19148
expunges should pretty much work now.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
509 |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
510 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
|
511 return ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
512 } |