Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-index/mbox/mbox-rewrite.c @ 898:0d5be52d7131 HEAD
Use unsigned char* when accessing non-NUL terminating strings. Compiler
warnings would then notify about accidentally passing them to functions which
require them NUL-terminated. Changed a few functions to use void* to avoid
unneeded casting.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 04 Jan 2003 19:26:29 +0200 |
parents | 41ec8cadd238 |
children | fd8888f6f037 |
rev | line source |
---|---|
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1 /* Copyright (C) 2002 Timo Sirainen */ |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
818
3d8767d31fe2
Don't fsck index after we've rewritten mbox - that doesn't gain us anything.
Timo Sirainen <tss@iki.fi>
parents:
817
diff
changeset
|
4 #include "ioloop.h" |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
5 #include "istream.h" |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
6 #include "ostream.h" |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
818
diff
changeset
|
7 #include "str.h" |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "write-full.h" |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "mbox-index.h" |
298
5509d87fe68b
mbox locking changes. support read-locking now. there's still problems
Timo Sirainen <tss@iki.fi>
parents:
297
diff
changeset
|
10 #include "mbox-lock.h" |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #include "mail-index-util.h" |
180
38341ad6a9db
partial changes to add X-IMAPbase parser update custom flags
Timo Sirainen <tss@iki.fi>
parents:
160
diff
changeset
|
12 #include "mail-custom-flags.h" |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 #include <stdio.h> |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 #include <stdlib.h> |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 #include <unistd.h> |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 #include <fcntl.h> |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 typedef struct { |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
20 OStream *output; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 int failed; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 |
370
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
23 uoff_t content_length; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 unsigned int seq; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 unsigned int msg_flags; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 const char **custom_flags; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 unsigned int uid_validity; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 unsigned int uid_last; |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
30 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
31 unsigned int ximapbase_found:1; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
32 unsigned int xkeywords_found:1; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
33 unsigned int status_found:1; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
34 unsigned int xstatus_found:1; |
370
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
35 unsigned int content_length_found:1; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 } MboxRewriteContext; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 /* Remove dirty flag from all messages */ |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 static void reset_dirty_flags(MailIndex *index) |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 { |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 MailIndexRecord *rec; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 rec = index->lookup(index, 1); |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 while (rec != NULL) { |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 rec->index_flags &= ~INDEX_MAIL_FLAG_DIRTY; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 rec = index->next(index, rec); |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 } |
209
d85a6898bf39
Don't rewrite mbox if no flags were changed.
Timo Sirainen <tss@iki.fi>
parents:
194
diff
changeset
|
48 |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
49 index->header->flags &= ~(MAIL_INDEX_FLAG_DIRTY_MESSAGES | |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
50 MAIL_INDEX_FLAG_DIRTY_CUSTOMFLAGS); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
53 static int mbox_write(MailIndex *index, IStream *input, OStream *output, |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 uoff_t end_offset) |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 { |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
404
diff
changeset
|
56 uoff_t old_limit; |
484
006202bcab99
input buffer limit wasn't reset in error conditions.
Timo Sirainen <tss@iki.fi>
parents:
452
diff
changeset
|
57 int failed; |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
404
diff
changeset
|
58 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
59 i_assert(input->v_offset <= end_offset); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
61 old_limit = input->v_limit; |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
62 i_stream_set_read_limit(input, end_offset); |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
63 if (o_stream_send_istream(output, input) < 0) { |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
404
diff
changeset
|
64 index_set_error(index, "Error rewriting mbox file %s: %s", |
817
86cf24da85f1
Added :INDEX=<dir> for both Maildir and mbox to specify different location
Timo Sirainen <tss@iki.fi>
parents:
807
diff
changeset
|
65 index->mailbox_path, |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
66 strerror(output->stream_errno)); |
484
006202bcab99
input buffer limit wasn't reset in error conditions.
Timo Sirainen <tss@iki.fi>
parents:
452
diff
changeset
|
67 failed = TRUE; |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
68 } else if (input->v_offset < end_offset) { |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 /* fsck should have noticed it.. */ |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 index_set_error(index, "Error rewriting mbox file %s: " |
817
86cf24da85f1
Added :INDEX=<dir> for both Maildir and mbox to specify different location
Timo Sirainen <tss@iki.fi>
parents:
807
diff
changeset
|
71 "Unexpected end of file", index->mailbox_path); |
484
006202bcab99
input buffer limit wasn't reset in error conditions.
Timo Sirainen <tss@iki.fi>
parents:
452
diff
changeset
|
72 failed = TRUE; |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
404
diff
changeset
|
73 } else { |
484
006202bcab99
input buffer limit wasn't reset in error conditions.
Timo Sirainen <tss@iki.fi>
parents:
452
diff
changeset
|
74 failed = FALSE; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
77 i_stream_set_read_limit(input, old_limit); |
484
006202bcab99
input buffer limit wasn't reset in error conditions.
Timo Sirainen <tss@iki.fi>
parents:
452
diff
changeset
|
78 return !failed; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
81 static int mbox_write_ximapbase(MboxRewriteContext *ctx) |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
82 { |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
83 const char *str; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
84 int i; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
85 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
86 str = t_strdup_printf("X-IMAPbase: %u %u", |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
87 ctx->uid_validity, ctx->uid_last); |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
88 if (o_stream_send_str(ctx->output, str) < 0) |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
89 return FALSE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
90 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
91 for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++) { |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
92 if (ctx->custom_flags[i] != NULL) { |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
93 if (o_stream_send(ctx->output, " ", 1) < 0) |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
94 return FALSE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
95 |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
96 if (o_stream_send_str(ctx->output, |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
97 ctx->custom_flags[i]) < 0) |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
98 return FALSE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
99 } |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
100 } |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
101 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
102 if (o_stream_send(ctx->output, "\n", 1) < 0) |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
103 return FALSE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
104 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
105 return TRUE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
106 } |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
107 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
108 static int mbox_write_xkeywords(MboxRewriteContext *ctx, const char *x_keywords) |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
109 { |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
110 unsigned int field; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
111 int i; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
112 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
113 if ((ctx->msg_flags & MAIL_CUSTOM_FLAGS_MASK) == 0 && |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
114 x_keywords == NULL) |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
115 return TRUE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
116 |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
117 if (o_stream_send_str(ctx->output, "X-Keywords:") < 0) |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
118 return FALSE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
119 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
120 field = 1 << MAIL_CUSTOM_FLAG_1_BIT; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
121 for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++, field <<= 1) { |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
122 if ((ctx->msg_flags & field) && ctx->custom_flags[i] != NULL) { |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
123 if (o_stream_send(ctx->output, " ", 1) < 0) |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
124 return FALSE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
125 |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
126 if (o_stream_send_str(ctx->output, |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
127 ctx->custom_flags[i]) < 0) |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
128 return FALSE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
129 } |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
130 } |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
131 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
132 if (x_keywords != NULL) { |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
133 /* X-Keywords that aren't custom flags */ |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
134 if (o_stream_send(ctx->output, " ", 1) < 0) |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
135 return FALSE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
136 |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
137 if (o_stream_send_str(ctx->output, x_keywords) < 0) |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
138 return FALSE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
139 } |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
140 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
141 if (o_stream_send(ctx->output, "\n", 1) < 0) |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
142 return FALSE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
143 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
144 return TRUE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
145 } |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
146 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
147 static int mbox_write_status(MboxRewriteContext *ctx, const char *status) |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
148 { |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
149 const char *str; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
150 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
151 str = (ctx->msg_flags & MAIL_SEEN) ? "Status: RO" : "Status: O"; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
152 if (status != NULL) |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
153 str = t_strconcat(str, status, NULL); |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
154 |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
155 if (o_stream_send_str(ctx->output, str) < 0) |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
156 return FALSE; |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
157 if (o_stream_send(ctx->output, "\n", 1) < 0) |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
158 return FALSE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
159 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
160 return TRUE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
161 } |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
162 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
163 static int mbox_write_xstatus(MboxRewriteContext *ctx, const char *x_status) |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
164 { |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
165 const char *str; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
166 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
167 /* X-Status field */ |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
168 if ((ctx->msg_flags & (MAIL_SYSTEM_FLAGS_MASK^MAIL_SEEN)) == 0 && |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
169 x_status == NULL) |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
170 return TRUE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
171 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
172 str = t_strconcat("X-Status: ", |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
173 (ctx->msg_flags & MAIL_ANSWERED) ? "A" : "", |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
174 (ctx->msg_flags & MAIL_DRAFT) ? "D" : "", |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
175 (ctx->msg_flags & MAIL_FLAGGED) ? "F" : "", |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
176 (ctx->msg_flags & MAIL_DELETED) ? "T" : "", |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
177 x_status, NULL); |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
178 |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
179 if (o_stream_send_str(ctx->output, str) < 0) |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
180 return FALSE; |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
181 if (o_stream_send(ctx->output, "\n", 1) < 0) |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
182 return FALSE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
183 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
184 return TRUE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
185 } |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
186 |
370
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
187 static int mbox_write_content_length(MboxRewriteContext *ctx) |
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
188 { |
678
1e5c655bad25
Renamed largest_t to uintmax_t which already exists in C99.
Timo Sirainen <tss@iki.fi>
parents:
642
diff
changeset
|
189 char str[MAX_INT_STRLEN+30]; |
370
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
190 |
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
191 i_snprintf(str, sizeof(str), "Content-Length: %"PRIuUOFF_T"\n", |
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
192 ctx->content_length); |
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
193 |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
194 if (o_stream_send_str(ctx->output, str) < 0) |
370
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
195 return FALSE; |
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
196 return TRUE; |
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
197 } |
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
198 |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
199 static const char *strip_chars(const unsigned char *value, size_t value_len, |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 const char *list) |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 { |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
202 /* @UNSAFE: leave only unknown flags, very likely none */ |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 char *ret, *p; |
765
553f050c8313
Added buffer API. Point is to hide all buffer writing behind this API which
Timo Sirainen <tss@iki.fi>
parents:
764
diff
changeset
|
204 size_t i; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
205 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
206 ret = p = t_buffer_get(value_len+1); |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
207 for (i = 0; i < value_len; i++) { |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
208 if (strchr(list, value[i]) == NULL) |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
209 *p++ = value[i]; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
210 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
211 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
212 if (ret == p) |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
213 return NULL; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
214 *p = '\0'; |
184 | 215 t_buffer_alloc((size_t) (p-ret)+1); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
216 return ret; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
217 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
218 |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
219 static void update_stripped_custom_flags(const unsigned char *value, size_t len, |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
220 int index, void *context) |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
221 { |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
818
diff
changeset
|
222 String *str = context; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
223 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
224 if (index < 0) { |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
225 /* not found, keep it */ |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
818
diff
changeset
|
226 if (str_len(str) != 0) |
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
818
diff
changeset
|
227 str_append_c(str, ' '); |
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
818
diff
changeset
|
228 str_append_n(str, value, len); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
229 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
230 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
231 |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
232 static const char *strip_custom_flags(const unsigned char *value, size_t len, |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
233 MboxRewriteContext *ctx) |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
234 { |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
818
diff
changeset
|
235 String *str; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
236 |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
818
diff
changeset
|
237 str = t_str_new(len+1); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
238 mbox_keywords_parse(value, len, ctx->custom_flags, |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 update_stripped_custom_flags, str); |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
818
diff
changeset
|
240 return str_len(str) == 0 ? NULL : str_c(str); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
241 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
242 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
243 static void header_func(MessagePart *part __attr_unused__, |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
244 const unsigned char *name, size_t name_len, |
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
245 const unsigned char *value, size_t value_len, |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
246 void *context) |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
247 { |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
248 MboxRewriteContext *ctx = context; |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
249 const char *str; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
250 char *end; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
251 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
252 if (ctx->failed) |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
253 return; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
254 |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
255 if (name_len == 6 && memcasecmp(name, "Status", 6) == 0) { |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
256 ctx->status_found = TRUE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
257 str = strip_chars(value, value_len, "RO"); |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
258 (void)mbox_write_status(ctx, str); |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
259 } else if (name_len == 8 && memcasecmp(name, "X-Status", 8) == 0) { |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
260 ctx->xstatus_found = TRUE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
261 str = strip_chars(value, value_len, "ADFT"); |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
262 (void)mbox_write_xstatus(ctx, str); |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
263 } else if (name_len == 10 && memcasecmp(name, "X-Keywords", 10) == 0) { |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
264 ctx->ximapbase_found = TRUE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
265 str = strip_custom_flags(value, value_len, ctx); |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
266 (void)mbox_write_xkeywords(ctx, str); |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
267 } else if (name_len == 10 && memcasecmp(name, "X-IMAPbase", 10) == 0) { |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
268 if (ctx->seq == 1) { |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
269 /* temporarily copy the value to make sure we |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
270 don't overflow it */ |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
271 const char *str; |
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
272 |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
273 t_push(); |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
274 str = t_strndup(value, value_len); |
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
275 ctx->uid_validity = strtoul(str, &end, 10); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
276 while (*end == ' ') end++; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
277 ctx->uid_last = strtoul(end, &end, 10); |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
278 t_pop(); |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
279 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
280 ctx->ximapbase_found = TRUE; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
281 (void)mbox_write_ximapbase(ctx); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
282 } |
370
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
283 } else if (name_len == 14 && |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
284 memcasecmp(name, "Content-Length", 14) == 0) { |
370
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
285 ctx->content_length_found = TRUE; |
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
286 (void)mbox_write_content_length(ctx); |
369
d037915978ca
message_parse_header() now calls the function with empty name/value at end
Timo Sirainen <tss@iki.fi>
parents:
365
diff
changeset
|
287 } else if (name_len > 0) { |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
288 /* save this header */ |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
289 (void)o_stream_send(ctx->output, name, name_len); |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
290 (void)o_stream_send(ctx->output, ": ", 2); |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
291 (void)o_stream_send(ctx->output, value, value_len); |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
292 (void)o_stream_send(ctx->output, "\n", 1); |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
293 } |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
294 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
295 if (ctx->output->closed) |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
296 ctx->failed = TRUE; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
297 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
298 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
299 static int mbox_write_header(MailIndex *index, |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
300 MailIndexRecord *rec, unsigned int seq, |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
301 IStream *input, OStream *output, uoff_t end_offset, |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
521
diff
changeset
|
302 uoff_t hdr_size, uoff_t body_size) |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
303 { |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
304 /* We need to update fields that define message flags. Standard fields |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
305 are stored in Status and X-Status. For custom flags we use |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
306 uw-imapd compatible format, by first listing them in first message's |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
307 X-IMAPbase field and actually defining them in X-Keywords field. |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
308 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
309 Format of X-IMAPbase is: <UID validity> <last used UID> <flag names> |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
310 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
311 We don't want to sync our UIDs with the mbox file, so the UID |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
312 validity is always kept different from our internal UID validity. |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
313 Last used UID is also not updated, and set to 0 initially. |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
314 */ |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
315 MboxRewriteContext ctx; |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
521
diff
changeset
|
316 MessageSize hdr_parsed_size; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
317 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
318 if (input->v_offset >= end_offset) { |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
319 /* fsck should have noticed it.. */ |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
320 index_set_error(index, "Error rewriting mbox file %s: " |
817
86cf24da85f1
Added :INDEX=<dir> for both Maildir and mbox to specify different location
Timo Sirainen <tss@iki.fi>
parents:
807
diff
changeset
|
321 "Unexpected end of file", index->mailbox_path); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
322 return FALSE; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
323 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
324 |
180
38341ad6a9db
partial changes to add X-IMAPbase parser update custom flags
Timo Sirainen <tss@iki.fi>
parents:
160
diff
changeset
|
325 t_push(); |
38341ad6a9db
partial changes to add X-IMAPbase parser update custom flags
Timo Sirainen <tss@iki.fi>
parents:
160
diff
changeset
|
326 |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
327 /* parse the header, write the fields we don't want to change */ |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
328 memset(&ctx, 0, sizeof(ctx)); |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
329 ctx.output = output; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
330 ctx.seq = seq; |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
521
diff
changeset
|
331 ctx.content_length = body_size; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
332 ctx.msg_flags = rec->msg_flags; |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
333 ctx.uid_validity = index->header->uid_validity-1; |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
334 ctx.custom_flags = mail_custom_flags_list_get(index->custom_flags); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
335 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
336 i_stream_set_read_limit(input, input->v_offset + hdr_size); |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
337 message_parse_header(NULL, input, &hdr_parsed_size, header_func, &ctx); |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
338 i_stream_set_read_limit(input, 0); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
339 |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
521
diff
changeset
|
340 i_assert(hdr_parsed_size.physical_size == hdr_size); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
341 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
342 /* append the flag fields */ |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
343 if (seq == 1 && !ctx.ximapbase_found) { |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
344 /* write X-IMAPbase header to first message */ |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
345 (void)mbox_write_ximapbase(&ctx); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
346 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
347 |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
348 if (!ctx.xkeywords_found) |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
349 (void)mbox_write_xkeywords(&ctx, NULL); |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
350 if (!ctx.status_found) |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
351 (void)mbox_write_status(&ctx, NULL); |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
352 if (!ctx.xstatus_found) |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
353 (void)mbox_write_xstatus(&ctx, NULL); |
370
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
354 if (!ctx.content_length_found) |
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
355 (void)mbox_write_content_length(&ctx); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
356 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
357 t_pop(); |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
358 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
359 /* empty line ends headers */ |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
360 (void)o_stream_send(output, "\n", 1); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
361 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
362 return TRUE; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
363 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
364 |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
365 static int fd_copy(int in_fd, int out_fd, uoff_t out_offset) |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
366 { |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
367 IStream *input; |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
368 OStream *output; |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
369 int ret; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
370 |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
371 i_assert(out_offset <= OFF_T_MAX); |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
372 |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
373 if (lseek(out_fd, (off_t)out_offset, SEEK_SET) < 0) |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
374 return -1; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
375 |
404
f25e575bf1ca
Created datastack_mempool which is used by at least a few temporary
Timo Sirainen <tss@iki.fi>
parents:
389
diff
changeset
|
376 t_push(); |
f25e575bf1ca
Created datastack_mempool which is used by at least a few temporary
Timo Sirainen <tss@iki.fi>
parents:
389
diff
changeset
|
377 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
378 input = i_stream_create_mmap(in_fd, data_stack_pool, |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
404
diff
changeset
|
379 1024*256, 0, 0, FALSE); |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
380 output = o_stream_create_file(out_fd, data_stack_pool, 1024, 0, FALSE); |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
381 o_stream_set_blocking(output, 60000, NULL, NULL); |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
382 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
383 ret = o_stream_send_istream(output, input); |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
384 if (ret < 0) |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
385 errno = output->stream_errno; |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
386 else { |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
387 /* we may have shrinked the file */ |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
388 i_assert(out_offset + input->v_size <= OFF_T_MAX); |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
389 ret = ftruncate(out_fd, (off_t) (out_offset + input->v_size)); |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
390 } |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
391 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
392 o_stream_unref(output); |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
393 i_stream_unref(input); |
404
f25e575bf1ca
Created datastack_mempool which is used by at least a few temporary
Timo Sirainen <tss@iki.fi>
parents:
389
diff
changeset
|
394 t_pop(); |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
395 |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
396 return ret; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
397 } |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
398 |
629
2f3b2a5d74d7
If first message with our X-IMAPbase is deleted, make sure it's added back.
Timo Sirainen <tss@iki.fi>
parents:
604
diff
changeset
|
399 #define INDEX_DIRTY_FLAGS \ |
2f3b2a5d74d7
If first message with our X-IMAPbase is deleted, make sure it's added back.
Timo Sirainen <tss@iki.fi>
parents:
604
diff
changeset
|
400 (MAIL_INDEX_FLAG_DIRTY_MESSAGES | MAIL_INDEX_FLAG_DIRTY_CUSTOMFLAGS) |
2f3b2a5d74d7
If first message with our X-IMAPbase is deleted, make sure it's added back.
Timo Sirainen <tss@iki.fi>
parents:
604
diff
changeset
|
401 |
180
38341ad6a9db
partial changes to add X-IMAPbase parser update custom flags
Timo Sirainen <tss@iki.fi>
parents:
160
diff
changeset
|
402 int mbox_index_rewrite(MailIndex *index) |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
403 { |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
404 /* Write messages beginning from the first dirty one to temp file, |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
405 then copy it over the mbox file. This may create data loss if |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
406 interrupted (see below). This rewriting relies quite a lot on |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
407 valid header/body sizes which fsck() should have ensured. */ |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
408 MailIndexRecord *rec; |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
409 IStream *input; |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
410 OStream *output; |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
521
diff
changeset
|
411 uoff_t offset, hdr_size, body_size, dirty_offset; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
412 const char *path; |
194 | 413 unsigned int seq; |
521
83da62e0675a
mbox locking fixes / changes. we now read-lock the mbox file before syncing
Timo Sirainen <tss@iki.fi>
parents:
484
diff
changeset
|
414 int tmp_fd, failed, dirty_found, rewrite; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
415 |
559
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
416 i_assert(index->lock_type == MAIL_LOCK_UNLOCK); |
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
417 |
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
418 if (!index->set_lock(index, MAIL_LOCK_SHARED)) |
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
419 return FALSE; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
420 |
642
5f5fdc45c19d
Don't rewrite when there's no messages (ie. don't write the one '\n').
Timo Sirainen <tss@iki.fi>
parents:
629
diff
changeset
|
421 rewrite = (index->header->flags & INDEX_DIRTY_FLAGS) && |
5f5fdc45c19d
Don't rewrite when there's no messages (ie. don't write the one '\n').
Timo Sirainen <tss@iki.fi>
parents:
629
diff
changeset
|
422 index->header->messages_count > 0; |
559
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
423 |
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
424 if (!index->set_lock(index, MAIL_LOCK_UNLOCK)) |
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
425 return FALSE; |
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
426 |
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
427 if (!rewrite) { |
303
19108e7c5af2
Actually, first don't do anything if there's no dirty flags. Then fsck().
Timo Sirainen <tss@iki.fi>
parents:
301
diff
changeset
|
428 /* no need to rewrite */ |
19108e7c5af2
Actually, first don't do anything if there's no dirty flags. Then fsck().
Timo Sirainen <tss@iki.fi>
parents:
301
diff
changeset
|
429 return TRUE; |
19108e7c5af2
Actually, first don't do anything if there's no dirty flags. Then fsck().
Timo Sirainen <tss@iki.fi>
parents:
301
diff
changeset
|
430 } |
19108e7c5af2
Actually, first don't do anything if there's no dirty flags. Then fsck().
Timo Sirainen <tss@iki.fi>
parents:
301
diff
changeset
|
431 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
432 tmp_fd = -1; input = NULL; |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
433 failed = TRUE; rewrite = FALSE; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
434 do { |
570
2626acd3c6f4
And more locking/syncing fixes. Now it's finally beginning to look sane
Timo Sirainen <tss@iki.fi>
parents:
560
diff
changeset
|
435 if (!index->set_lock(index, MAIL_LOCK_EXCLUSIVE)) |
2626acd3c6f4
And more locking/syncing fixes. Now it's finally beginning to look sane
Timo Sirainen <tss@iki.fi>
parents:
560
diff
changeset
|
436 break; |
2626acd3c6f4
And more locking/syncing fixes. Now it's finally beginning to look sane
Timo Sirainen <tss@iki.fi>
parents:
560
diff
changeset
|
437 |
559
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
438 if (!index->sync_and_lock(index, MAIL_LOCK_EXCLUSIVE, NULL)) |
556 | 439 break; |
440 | |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
441 input = mbox_get_stream(index, 0, MAIL_LOCK_EXCLUSIVE); |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
442 if (input == NULL) |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
443 break; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
444 |
629
2f3b2a5d74d7
If first message with our X-IMAPbase is deleted, make sure it's added back.
Timo Sirainen <tss@iki.fi>
parents:
604
diff
changeset
|
445 if ((index->header->flags & INDEX_DIRTY_FLAGS) == 0) { |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
446 /* fsck() figured out there's no dirty messages |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
447 after all */ |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
448 failed = FALSE; rewrite = FALSE; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
449 break; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
450 } |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
451 |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
452 tmp_fd = mail_index_create_temp_file(index, &path); |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
453 if (tmp_fd == -1) |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
454 break; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
455 |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
456 failed = FALSE; rewrite = TRUE; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
457 } while (0); |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
458 |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
459 if (!rewrite) { |
560 | 460 if (!index->set_lock(index, MAIL_LOCK_UNLOCK)) |
559
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
461 failed = TRUE; |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
462 if (input != NULL) |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
463 i_stream_unref(input); |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
464 return !failed; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
465 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
466 |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
467 if (index->header->flags & MAIL_INDEX_FLAG_DIRTY_CUSTOMFLAGS) { |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
468 /* need to update X-IMAPbase in first message */ |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
469 dirty_found = TRUE; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
470 } else { |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
471 dirty_found = FALSE; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
472 } |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
473 dirty_offset = 0; |
298
5509d87fe68b
mbox locking changes. support read-locking now. there's still problems
Timo Sirainen <tss@iki.fi>
parents:
297
diff
changeset
|
474 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
475 /* note: we can't use data_stack_pool with output stream because it's |
559
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
476 being written to inside t_push() .. t_pop() calls */ |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
477 output = o_stream_create_file(tmp_fd, system_pool, 8192, 0, FALSE); |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
478 o_stream_set_blocking(output, 60000, NULL, NULL); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
479 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
480 failed = FALSE; seq = 1; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
481 rec = index->lookup(index, 1); |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
482 while (rec != NULL) { |
383 | 483 if (dirty_found || (rec->index_flags & INDEX_MAIL_FLAG_DIRTY)) { |
484 /* get offset to beginning of mail headers */ | |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
521
diff
changeset
|
485 if (!mbox_mail_get_location(index, rec, &offset, |
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
521
diff
changeset
|
486 &hdr_size, &body_size)) { |
383 | 487 /* fsck should have fixed it */ |
488 failed = TRUE; | |
489 break; | |
490 } | |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
491 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
492 if (offset < input->v_offset) { |
570
2626acd3c6f4
And more locking/syncing fixes. Now it's finally beginning to look sane
Timo Sirainen <tss@iki.fi>
parents:
560
diff
changeset
|
493 index_set_corrupted(index, |
2626acd3c6f4
And more locking/syncing fixes. Now it's finally beginning to look sane
Timo Sirainen <tss@iki.fi>
parents:
560
diff
changeset
|
494 "Invalid message offset"); |
2626acd3c6f4
And more locking/syncing fixes. Now it's finally beginning to look sane
Timo Sirainen <tss@iki.fi>
parents:
560
diff
changeset
|
495 failed = TRUE; |
2626acd3c6f4
And more locking/syncing fixes. Now it's finally beginning to look sane
Timo Sirainen <tss@iki.fi>
parents:
560
diff
changeset
|
496 break; |
2626acd3c6f4
And more locking/syncing fixes. Now it's finally beginning to look sane
Timo Sirainen <tss@iki.fi>
parents:
560
diff
changeset
|
497 } |
2626acd3c6f4
And more locking/syncing fixes. Now it's finally beginning to look sane
Timo Sirainen <tss@iki.fi>
parents:
560
diff
changeset
|
498 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
499 if (offset + hdr_size + body_size > input->v_size) { |
383 | 500 index_set_corrupted(index, |
501 "Invalid message size"); | |
502 failed = TRUE; | |
503 break; | |
504 } | |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
505 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
506 |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
507 if (!dirty_found && |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
508 (rec->index_flags & INDEX_MAIL_FLAG_DIRTY)) { |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
509 /* first dirty message */ |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
510 dirty_found = TRUE; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
511 dirty_offset = offset; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
512 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
513 i_stream_seek(input, dirty_offset); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
514 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
515 |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
516 if (dirty_found) { |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
517 /* write the From-line */ |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
518 if (!mbox_write(index, input, output, offset)) { |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
519 failed = TRUE; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
520 break; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
521 } |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
522 |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
523 /* write header, updating flag fields */ |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
521
diff
changeset
|
524 offset += hdr_size; |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
525 if (!mbox_write_header(index, rec, seq, input, output, |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
521
diff
changeset
|
526 offset, hdr_size, body_size)) { |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
527 failed = TRUE; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
528 break; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
529 } |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
530 |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
531 /* write body */ |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
521
diff
changeset
|
532 offset += body_size; |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
533 if (!mbox_write(index, input, output, offset)) { |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
534 failed = TRUE; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
535 break; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
536 } |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
537 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
538 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
539 seq++; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
540 rec = index->next(index, rec); |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
541 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
542 |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
543 if (!dirty_found) { |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
544 index_set_error(index, "Expected dirty messages not found " |
817
86cf24da85f1
Added :INDEX=<dir> for both Maildir and mbox to specify different location
Timo Sirainen <tss@iki.fi>
parents:
807
diff
changeset
|
545 "from mbox file %s", index->mailbox_path); |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
546 failed = TRUE; |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
547 } |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
548 |
484
006202bcab99
input buffer limit wasn't reset in error conditions.
Timo Sirainen <tss@iki.fi>
parents:
452
diff
changeset
|
549 if (!failed) { |
006202bcab99
input buffer limit wasn't reset in error conditions.
Timo Sirainen <tss@iki.fi>
parents:
452
diff
changeset
|
550 /* always end with a \n */ |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
551 (void)o_stream_send(output, "\n", 1); |
484
006202bcab99
input buffer limit wasn't reset in error conditions.
Timo Sirainen <tss@iki.fi>
parents:
452
diff
changeset
|
552 } |
006202bcab99
input buffer limit wasn't reset in error conditions.
Timo Sirainen <tss@iki.fi>
parents:
452
diff
changeset
|
553 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
554 if (output->closed) { |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
555 errno = output->stream_errno; |
221
ed0d5b17c7a4
Added extra functions for easier printing of error messages. Moved
Timo Sirainen <tss@iki.fi>
parents:
217
diff
changeset
|
556 mbox_set_syscall_error(index, "write()"); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
557 failed = TRUE; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
558 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
559 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
560 i_stream_unref(input); |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
561 o_stream_unref(output); |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
562 |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
563 if (!failed) { |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
564 /* POSSIBLE DATA LOSS HERE. We're writing to the mbox file, |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
565 so if we get killed here before finished, we'll lose some |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
566 bytes. I can't really think of any way to fix this, |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
567 rename() is problematic too especially because of file |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
568 locking issues (new mail could be lost). |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
569 |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
570 Usually we're moving the data by just a few bytes, so |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
571 the data loss should never be more than those few bytes.. |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
572 If we moved more, we could have written the file from end |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
573 to beginning in blocks (it'd be a bit slow to do it in |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
574 blocks of ~1-10 bytes which is the usual case, so we don't |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
575 bother). |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
576 |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
577 Also, we might as well be shrinking the file, in which |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
578 case we can't lose data. */ |
364
ea958a5b9de1
Added io_buffer_set_start_offset() and io_buffer_ref() and replaced
Timo Sirainen <tss@iki.fi>
parents:
363
diff
changeset
|
579 if (fd_copy(tmp_fd, index->mbox_fd, dirty_offset) == 0) { |
818
3d8767d31fe2
Don't fsck index after we've rewritten mbox - that doesn't gain us anything.
Timo Sirainen <tss@iki.fi>
parents:
817
diff
changeset
|
580 /* All ok. Just make sure the timestamps of index and |
3d8767d31fe2
Don't fsck index after we've rewritten mbox - that doesn't gain us anything.
Timo Sirainen <tss@iki.fi>
parents:
817
diff
changeset
|
581 mbox differ, so index will be updated at next sync */ |
3d8767d31fe2
Don't fsck index after we've rewritten mbox - that doesn't gain us anything.
Timo Sirainen <tss@iki.fi>
parents:
817
diff
changeset
|
582 index->file_sync_stamp = ioloop_time-61; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
583 reset_dirty_flags(index); |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
584 } else { |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
585 mbox_set_syscall_error(index, "fd_copy()"); |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
586 failed = TRUE; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
587 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
588 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
589 |
559
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
590 if (!index->set_lock(index, MAIL_LOCK_UNLOCK)) |
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
591 failed = TRUE; |
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
592 |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
593 (void)unlink(path); |
297
ef6ae9e1b585
some cleanups + fd leaks when recaching mailbox.
Timo Sirainen <tss@iki.fi>
parents:
290
diff
changeset
|
594 |
312
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
595 if (close(tmp_fd) < 0) |
297
ef6ae9e1b585
some cleanups + fd leaks when recaching mailbox.
Timo Sirainen <tss@iki.fi>
parents:
290
diff
changeset
|
596 index_file_set_syscall_error(index, path, "close()"); |
559
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
597 return !failed; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
598 } |