Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-index/mbox/mbox-rewrite.c @ 953:411006be3c66 HEAD
Naming change for function typedefs.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 11 Jan 2003 21:55:56 +0200 |
parents | fd8888f6f037 |
children | 3aa40f0dde5f |
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 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
19 struct mbox_rewrite_context { |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
20 struct 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; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
36 }; |
160
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 */ |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
39 static void reset_dirty_flags(struct mail_index *index) |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
41 struct mail_index_record *rec; |
160
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 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
53 static int mbox_write(struct mail_index *index, struct istream *input, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
54 struct ostream *output, uoff_t end_offset) |
160
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 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
81 static int mbox_write_ximapbase(struct mbox_rewrite_context *ctx) |
362
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 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
108 static int mbox_write_xkeywords(struct mbox_rewrite_context *ctx, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
109 const char *x_keywords) |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
110 { |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
111 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
|
112 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
|
113 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
118 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
|
119 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
|
120 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
127 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
|
128 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
|
129 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
|
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 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
133 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
|
134 /* 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
|
135 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
|
136 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
|
137 |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
138 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
|
139 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
|
140 } |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
141 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
142 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
|
143 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
|
144 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
145 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
|
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 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
148 static int mbox_write_status(struct mbox_rewrite_context *ctx, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
149 const char *status) |
362
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 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
|
152 |
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 = (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
|
154 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
|
155 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
|
156 |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
157 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
|
158 return FALSE; |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
159 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
|
160 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
|
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 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
|
163 } |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
164 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
165 static int mbox_write_xstatus(struct mbox_rewrite_context *ctx, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
166 const char *x_status) |
362
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
167 { |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
168 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
|
169 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
170 /* 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
|
171 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
|
172 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
|
173 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
|
174 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
175 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
|
176 (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
|
177 (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
|
178 (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
|
179 (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
|
180 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
|
181 |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
182 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
|
183 return FALSE; |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
184 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
|
185 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
|
186 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
187 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
|
188 } |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
189 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
190 static int mbox_write_content_length(struct mbox_rewrite_context *ctx) |
370
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
191 { |
678
1e5c655bad25
Renamed largest_t to uintmax_t which already exists in C99.
Timo Sirainen <tss@iki.fi>
parents:
642
diff
changeset
|
192 char str[MAX_INT_STRLEN+30]; |
370
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
193 |
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
194 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
|
195 ctx->content_length); |
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
196 |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
197 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
|
198 return FALSE; |
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
199 return TRUE; |
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
200 } |
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
201 |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
202 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
|
203 const char *list) |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
204 { |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
205 /* @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
|
206 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
|
207 size_t i; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
208 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
209 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
|
210 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
|
211 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
|
212 *p++ = value[i]; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
213 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
214 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
215 if (ret == p) |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
216 return NULL; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
217 *p = '\0'; |
184 | 218 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
|
219 return ret; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
220 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
221 |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
222 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
|
223 int index, void *context) |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
224 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
225 string_t *str = context; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
226 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
227 if (index < 0) { |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 /* 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
|
229 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
|
230 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
|
231 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
|
232 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
233 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
234 |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
235 static const char *strip_custom_flags(const unsigned char *value, size_t len, |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
236 struct mbox_rewrite_context *ctx) |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
237 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
238 string_t *str; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 |
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 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
|
241 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
|
242 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
|
243 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
|
244 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
245 |
953
411006be3c66
Naming change for function typedefs.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
246 static void header_cb(struct message_part *part __attr_unused__, |
411006be3c66
Naming change for function typedefs.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
247 const unsigned char *name, size_t name_len, |
411006be3c66
Naming change for function typedefs.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
248 const unsigned char *value, size_t value_len, |
411006be3c66
Naming change for function typedefs.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
249 void *context) |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
250 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
251 struct mbox_rewrite_context *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
|
252 const char *str; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
253 char *end; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
254 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 if (ctx->failed) |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
256 return; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
257 |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
258 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
|
259 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
|
260 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
|
261 (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
|
262 } 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
|
263 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
|
264 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
|
265 (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
|
266 } 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
|
267 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
|
268 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
|
269 (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
|
270 } 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
|
271 if (ctx->seq == 1) { |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
272 /* 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
|
273 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
|
274 const char *str; |
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
275 |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
276 t_push(); |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
277 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
|
278 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
|
279 while (*end == ' ') end++; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
280 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
|
281 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
|
282 |
aa449d013563
When updating any of the fields, keep them in the original location in
Timo Sirainen <tss@iki.fi>
parents:
312
diff
changeset
|
283 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
|
284 (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
|
285 } |
370
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
286 } 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
|
287 memcasecmp(name, "Content-Length", 14) == 0) { |
370
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
288 ctx->content_length_found = TRUE; |
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
289 (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
|
290 } 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
|
291 /* 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
|
292 (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
|
293 (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
|
294 (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
|
295 (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
|
296 } |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
297 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
298 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
|
299 ctx->failed = TRUE; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
300 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
301 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
302 static int mbox_write_header(struct mail_index *index, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
303 struct mail_index_record *rec, unsigned int seq, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
304 struct istream *input, struct ostream *output, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
305 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
|
306 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
|
307 { |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
308 /* 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
|
309 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
|
310 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
|
311 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
|
312 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
313 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
|
314 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
315 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
|
316 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
|
317 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
|
318 */ |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
319 struct mbox_rewrite_context ctx; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
320 struct message_size hdr_parsed_size; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
321 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
322 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
|
323 /* 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
|
324 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
|
325 "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
|
326 return FALSE; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
327 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
328 |
180
38341ad6a9db
partial changes to add X-IMAPbase parser update custom flags
Timo Sirainen <tss@iki.fi>
parents:
160
diff
changeset
|
329 t_push(); |
38341ad6a9db
partial changes to add X-IMAPbase parser update custom flags
Timo Sirainen <tss@iki.fi>
parents:
160
diff
changeset
|
330 |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
331 /* 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
|
332 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
|
333 ctx.output = output; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
334 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
|
335 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
|
336 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
|
337 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
|
338 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
|
339 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
340 i_stream_set_read_limit(input, input->v_offset + hdr_size); |
953
411006be3c66
Naming change for function typedefs.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
341 message_parse_header(NULL, input, &hdr_parsed_size, header_cb, &ctx); |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
342 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
|
343 |
525
2cb2e0a3423b
Moved several fields from .imap.index file to .imap.index.data file. Fixed
Timo Sirainen <tss@iki.fi>
parents:
521
diff
changeset
|
344 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
|
345 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
346 /* 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
|
347 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
|
348 /* 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
|
349 (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
|
350 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
351 |
362
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.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
|
353 (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
|
354 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
|
355 (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
|
356 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
|
357 (void)mbox_write_xstatus(&ctx, NULL); |
370
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
358 if (!ctx.content_length_found) |
b0a62e264b22
Write Content-Length header for rewritten messages.
Timo Sirainen <tss@iki.fi>
parents:
369
diff
changeset
|
359 (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
|
360 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
361 t_pop(); |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
362 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
363 /* 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
|
364 (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
|
365 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
366 return TRUE; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
367 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
368 |
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 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
|
370 { |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
371 struct istream *input; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
372 struct 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
|
373 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
|
374 |
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 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
|
376 |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
377 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
|
378 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
|
379 |
404
f25e575bf1ca
Created datastack_mempool which is used by at least a few temporary
Timo Sirainen <tss@iki.fi>
parents:
389
diff
changeset
|
380 t_push(); |
f25e575bf1ca
Created datastack_mempool which is used by at least a few temporary
Timo Sirainen <tss@iki.fi>
parents:
389
diff
changeset
|
381 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
382 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
|
383 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
|
384 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
|
385 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
|
386 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
387 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
|
388 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
|
389 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
|
390 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
|
391 /* 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
|
392 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
|
393 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
|
394 } |
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 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
396 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
|
397 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
|
398 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
|
399 |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
400 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
|
401 } |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
402 |
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
|
403 #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
|
404 (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
|
405 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
406 int mbox_index_rewrite(struct mail_index *index) |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
407 { |
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
|
408 /* 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
|
409 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
|
410 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
|
411 valid header/body sizes which fsck() should have ensured. */ |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
412 struct mail_index_record *rec; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
413 struct istream *input; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
414 struct 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
|
415 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
|
416 const char *path; |
194 | 417 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
|
418 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
|
419 |
559
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
420 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
|
421 |
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
422 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
|
423 return FALSE; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
424 |
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
|
425 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
|
426 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
|
427 |
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
428 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
|
429 return FALSE; |
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
430 |
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
431 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
|
432 /* 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
|
433 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
|
434 } |
19108e7c5af2
Actually, first don't do anything if there's no dirty flags. Then fsck().
Timo Sirainen <tss@iki.fi>
parents:
301
diff
changeset
|
435 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
436 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
|
437 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
|
438 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
|
439 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
|
440 break; |
2626acd3c6f4
And more locking/syncing fixes. Now it's finally beginning to look sane
Timo Sirainen <tss@iki.fi>
parents:
560
diff
changeset
|
441 |
559
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
442 if (!index->sync_and_lock(index, MAIL_LOCK_EXCLUSIVE, NULL)) |
556 | 443 break; |
444 | |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
445 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
|
446 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
|
447 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
|
448 |
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
|
449 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
|
450 /* 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
|
451 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
|
452 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
|
453 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
|
454 } |
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 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
|
457 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
|
458 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
|
459 |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
460 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
|
461 } 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
|
462 |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
463 if (!rewrite) { |
560 | 464 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
|
465 failed = TRUE; |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
466 if (input != NULL) |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
467 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
|
468 return !failed; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
469 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
470 |
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
|
471 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
|
472 /* 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
|
473 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
|
474 } 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
|
475 dirty_found = FALSE; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
476 } |
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
|
477 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
|
478 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
479 /* 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
|
480 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
|
481 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
|
482 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
|
483 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
484 failed = FALSE; seq = 1; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
485 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
|
486 while (rec != NULL) { |
383 | 487 if (dirty_found || (rec->index_flags & INDEX_MAIL_FLAG_DIRTY)) { |
488 /* 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
|
489 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
|
490 &hdr_size, &body_size)) { |
383 | 491 /* fsck should have fixed it */ |
492 failed = TRUE; | |
493 break; | |
494 } | |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
495 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
496 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
|
497 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
|
498 "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
|
499 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
|
500 break; |
2626acd3c6f4
And more locking/syncing fixes. Now it's finally beginning to look sane
Timo Sirainen <tss@iki.fi>
parents:
560
diff
changeset
|
501 } |
2626acd3c6f4
And more locking/syncing fixes. Now it's finally beginning to look sane
Timo Sirainen <tss@iki.fi>
parents:
560
diff
changeset
|
502 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
503 if (offset + hdr_size + body_size > input->v_size) { |
383 | 504 index_set_corrupted(index, |
505 "Invalid message size"); | |
506 failed = TRUE; | |
507 break; | |
508 } | |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
509 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
510 |
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
|
511 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
|
512 (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
|
513 /* 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
|
514 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
|
515 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
|
516 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
517 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
|
518 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
519 |
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
|
520 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
|
521 /* 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
|
522 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
|
523 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
|
524 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
|
525 } |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
526 |
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 /* 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
|
528 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
|
529 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
|
530 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
|
531 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
|
532 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
|
533 } |
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 |
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 /* 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
|
536 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
|
537 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
|
538 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
|
539 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
|
540 } |
160
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 |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
543 seq++; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
544 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
|
545 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
546 |
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
|
547 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
|
548 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
|
549 "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
|
550 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
|
551 } |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
552 |
484
006202bcab99
input buffer limit wasn't reset in error conditions.
Timo Sirainen <tss@iki.fi>
parents:
452
diff
changeset
|
553 if (!failed) { |
006202bcab99
input buffer limit wasn't reset in error conditions.
Timo Sirainen <tss@iki.fi>
parents:
452
diff
changeset
|
554 /* 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
|
555 (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
|
556 } |
006202bcab99
input buffer limit wasn't reset in error conditions.
Timo Sirainen <tss@iki.fi>
parents:
452
diff
changeset
|
557 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
558 if (output->closed) { |
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
559 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
|
560 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
|
561 failed = TRUE; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
562 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
563 |
764
f57c52738f90
Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
564 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
|
565 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
|
566 |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
567 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
|
568 /* 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
|
569 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
|
570 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
|
571 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
|
572 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
|
573 |
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 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
|
575 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
|
576 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
|
577 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
|
578 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
|
579 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
|
580 |
f5e59d65d124
Rewrite only needed parts of mbox. We don't rename() anymore, which means we
Timo Sirainen <tss@iki.fi>
parents:
303
diff
changeset
|
581 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
|
582 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
|
583 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
|
584 /* 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
|
585 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
|
586 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
|
587 reset_dirty_flags(index); |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
588 } 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
|
589 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
|
590 failed = TRUE; |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
591 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
592 } |
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
593 |
559
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
594 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
|
595 failed = TRUE; |
c834e77b624c
Mostly mbox locking/syncing fixes. Still some problems though.
Timo Sirainen <tss@iki.fi>
parents:
556
diff
changeset
|
596 |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
597 (void)unlink(path); |
297
ef6ae9e1b585
some cleanups + fd leaks when recaching mailbox.
Timo Sirainen <tss@iki.fi>
parents:
290
diff
changeset
|
598 |
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
|
599 if (close(tmp_fd) < 0) |
297
ef6ae9e1b585
some cleanups + fd leaks when recaching mailbox.
Timo Sirainen <tss@iki.fi>
parents:
290
diff
changeset
|
600 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
|
601 return !failed; |
160
ff05b320482c
Bigger changes.. full_virtual_size was removed from index record and
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
602 } |