Mercurial > dovecot > core-2.2
annotate src/lib-storage/index/mbox/istream-raw-mbox.c @ 4327:dbae2347dcdb HEAD
Handle i_stream_stat() better.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 08 Jun 2006 22:26:53 +0300 |
parents | 08a302d3e525 |
children | ccd102aef7ad |
rev | line source |
---|---|
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1 /* Copyright (C) 2003 Timo Sirainen */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "buffer.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "istream-internal.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "istream-raw-mbox.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "mbox-from.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 struct raw_mbox_istream { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 struct _istream istream; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 time_t received_time, next_received_time; |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
13 char *sender, *next_sender; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
14 |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
15 uoff_t from_offset, hdr_offset, body_offset, mail_size; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 struct istream *input; |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
17 uoff_t input_peak_offset; |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
18 |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
19 unsigned int corrupted:1; |
2464
db61972ffeb3
istream-raw-mbox now sets stream->eof when it's at the end of message to fix
Timo Sirainen <tss@iki.fi>
parents:
2457
diff
changeset
|
20 unsigned int eof:1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 }; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 static void _close(struct _iostream *stream __attr_unused__) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 static void _destroy(struct _iostream *stream) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 struct raw_mbox_istream *rstream = (struct raw_mbox_istream *)stream; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 |
2641 | 31 i_free(rstream->sender); |
32 i_free(rstream->next_sender); | |
33 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 i_stream_seek(rstream->input, rstream->istream.istream.v_offset); |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
35 i_stream_unref(&rstream->input); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 static void _set_max_buffer_size(struct _iostream *stream, size_t max_size) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 struct raw_mbox_istream *rstream = (struct raw_mbox_istream *)stream; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 i_stream_set_max_buffer_size(rstream->input, max_size); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
45 static int mbox_read_from_line(struct raw_mbox_istream *rstream) |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
46 { |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
47 const unsigned char *buf, *p; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
48 char *sender; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
49 time_t received_time; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
50 size_t pos, line_pos; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
51 int skip; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
52 |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
53 buf = i_stream_get_data(rstream->input, &pos); |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
54 i_assert(pos > 0); |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
55 |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
56 /* from_offset points to "\nFrom ", so unless we're at the beginning |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
57 of the file, skip the initial \n */ |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
58 skip = rstream->from_offset != 0; |
3430 | 59 if (skip && *buf == '\r') |
60 skip++; | |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
61 |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
62 while ((p = memchr(buf+skip, '\n', pos-skip)) == NULL) { |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
63 if (i_stream_read(rstream->input) < 0) { |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
64 /* EOF - shouldn't happen */ |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
65 return -1; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
66 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
67 buf = i_stream_get_data(rstream->input, &pos); |
3413 | 68 i_assert(pos > 0); |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
69 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
70 line_pos = (size_t)(p - buf); |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
71 |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
72 if (rstream->from_offset != 0) { |
3430 | 73 buf += skip; |
74 pos -= skip; | |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
75 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
76 |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
77 /* beginning of mbox */ |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
78 if (memcmp(buf, "From ", 5) != 0 || |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
79 mbox_from_parse(buf+5, pos-5, &received_time, &sender) < 0) { |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
80 /* broken From - should happen only at beginning of |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
81 file if this isn't a mbox.. */ |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
82 return -1; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
83 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
84 |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
85 if (rstream->istream.istream.v_offset == rstream->from_offset) { |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
86 rstream->received_time = received_time; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
87 i_free(rstream->sender); |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
88 rstream->sender = sender; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
89 } else { |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
90 rstream->next_received_time = received_time; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
91 i_free(rstream->next_sender); |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
92 rstream->next_sender = sender; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
93 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
94 |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
95 /* we'll skip over From-line */ |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
96 rstream->istream.istream.v_offset += line_pos+1; |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
97 i_stream_skip(rstream->input, line_pos+1); |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
98 rstream->hdr_offset = rstream->istream.istream.v_offset; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
99 return 0; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
100 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
101 |
2155 | 102 static void handle_end_of_mail(struct raw_mbox_istream *rstream, size_t pos) |
103 { | |
104 rstream->mail_size = rstream->istream.istream.v_offset + pos - | |
105 rstream->hdr_offset; | |
106 | |
2997
c64674a0a92a
In some cases we may have crashed if header didn't end with LF+LF.
Timo Sirainen <tss@iki.fi>
parents:
2641
diff
changeset
|
107 if (rstream->hdr_offset + rstream->mail_size < rstream->body_offset) { |
c64674a0a92a
In some cases we may have crashed if header didn't end with LF+LF.
Timo Sirainen <tss@iki.fi>
parents:
2641
diff
changeset
|
108 /* a) Header didn't have ending \n |
c64674a0a92a
In some cases we may have crashed if header didn't end with LF+LF.
Timo Sirainen <tss@iki.fi>
parents:
2641
diff
changeset
|
109 b) "headers\n\nFrom ..", the second \n belongs to next |
2155 | 110 message which we didn't know at the time yet. */ |
2997
c64674a0a92a
In some cases we may have crashed if header didn't end with LF+LF.
Timo Sirainen <tss@iki.fi>
parents:
2641
diff
changeset
|
111 i_assert(rstream->body_offset == (uoff_t)-1 || |
c64674a0a92a
In some cases we may have crashed if header didn't end with LF+LF.
Timo Sirainen <tss@iki.fi>
parents:
2641
diff
changeset
|
112 rstream->body_offset == |
2155 | 113 rstream->hdr_offset + rstream->mail_size + 1); |
114 rstream->body_offset = | |
115 rstream->hdr_offset + rstream->mail_size; | |
116 } | |
117 } | |
118 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
119 static ssize_t _read(struct _istream *stream) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
120 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
121 static const char *mbox_from = "\nFrom "; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
122 struct raw_mbox_istream *rstream = (struct raw_mbox_istream *)stream; |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
123 const unsigned char *buf; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
124 const char *fromp; |
3035
6f1ea1c7212f
Don't break if line begins with NUL. Don't return -2 as long as underlying
Timo Sirainen <tss@iki.fi>
parents:
2997
diff
changeset
|
125 char *sender; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
126 time_t received_time; |
3430 | 127 size_t i, pos, new_pos, from_start_pos, from_after_pos; |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
128 ssize_t ret = 0; |
3035
6f1ea1c7212f
Don't break if line begins with NUL. Don't return -2 as long as underlying
Timo Sirainen <tss@iki.fi>
parents:
2997
diff
changeset
|
129 int eoh_char; |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
130 |
2155 | 131 i_assert(stream->istream.v_offset >= rstream->from_offset); |
132 | |
2997
c64674a0a92a
In some cases we may have crashed if header didn't end with LF+LF.
Timo Sirainen <tss@iki.fi>
parents:
2641
diff
changeset
|
133 if (stream->istream.eof) |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
134 return -1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
135 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
136 i_stream_seek(rstream->input, stream->istream.v_offset); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
137 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
138 stream->pos -= stream->skip; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
139 stream->skip = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
140 stream->buffer = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
141 |
2187 | 142 ret = 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
143 do { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
144 buf = i_stream_get_data(rstream->input, &pos); |
3438
22d4fd7fd436
Fixed breakage caused by CRLF-support.
Timo Sirainen <tss@iki.fi>
parents:
3430
diff
changeset
|
145 if (pos > 1 && stream->istream.v_offset + pos > |
22d4fd7fd436
Fixed breakage caused by CRLF-support.
Timo Sirainen <tss@iki.fi>
parents:
3430
diff
changeset
|
146 rstream->input_peak_offset) { |
22d4fd7fd436
Fixed breakage caused by CRLF-support.
Timo Sirainen <tss@iki.fi>
parents:
3430
diff
changeset
|
147 /* fake our read count. needed because if in the end |
22d4fd7fd436
Fixed breakage caused by CRLF-support.
Timo Sirainen <tss@iki.fi>
parents:
3430
diff
changeset
|
148 we have only one character in buffer and we skip it |
22d4fd7fd436
Fixed breakage caused by CRLF-support.
Timo Sirainen <tss@iki.fi>
parents:
3430
diff
changeset
|
149 (as potential CR), we want to get back to this |
22d4fd7fd436
Fixed breakage caused by CRLF-support.
Timo Sirainen <tss@iki.fi>
parents:
3430
diff
changeset
|
150 _read() to read more data. */ |
22d4fd7fd436
Fixed breakage caused by CRLF-support.
Timo Sirainen <tss@iki.fi>
parents:
3430
diff
changeset
|
151 ret = pos; |
2187 | 152 break; |
3438
22d4fd7fd436
Fixed breakage caused by CRLF-support.
Timo Sirainen <tss@iki.fi>
parents:
3430
diff
changeset
|
153 } |
2187 | 154 ret = i_stream_read(rstream->input); |
155 } while (ret > 0); | |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
156 |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
157 if (ret < 0) { |
2187 | 158 if (ret == -2) { |
159 if (stream->istream.v_offset + pos == | |
2457
5506d4cd4973
Buffer wasn't set if _read() returned -2.
Timo Sirainen <tss@iki.fi>
parents:
2431
diff
changeset
|
160 rstream->input_peak_offset) { |
5506d4cd4973
Buffer wasn't set if _read() returned -2.
Timo Sirainen <tss@iki.fi>
parents:
2431
diff
changeset
|
161 stream->buffer = buf; |
2187 | 162 return -2; |
2457
5506d4cd4973
Buffer wasn't set if _read() returned -2.
Timo Sirainen <tss@iki.fi>
parents:
2431
diff
changeset
|
163 } |
3693 | 164 } else if (stream->istream.v_offset != 0 || pos == 0) { |
2187 | 165 /* we've read the whole file, final byte should be |
166 the \n trailer */ | |
3430 | 167 if (pos > 0 && buf[pos-1] == '\n') { |
2187 | 168 pos--; |
3430 | 169 if (pos > 0 && buf[pos-1] == '\r') |
170 pos--; | |
171 } | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 |
2187 | 173 i_assert(pos >= stream->pos); |
174 ret = pos == stream->pos ? -1 : | |
175 (ssize_t)(pos - stream->pos); | |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
176 |
2187 | 177 stream->buffer = buf; |
178 stream->pos = pos; | |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
179 |
3678
bae46114f240
if message was only 0-1 bytes, we skipped the whole message which caused
Timo Sirainen <tss@iki.fi>
parents:
3675
diff
changeset
|
180 if (stream->istream.v_offset == rstream->from_offset) { |
bae46114f240
if message was only 0-1 bytes, we skipped the whole message which caused
Timo Sirainen <tss@iki.fi>
parents:
3675
diff
changeset
|
181 /* haven't seen From-line yet, so this mbox |
bae46114f240
if message was only 0-1 bytes, we skipped the whole message which caused
Timo Sirainen <tss@iki.fi>
parents:
3675
diff
changeset
|
182 stream is now at EOF */ |
bae46114f240
if message was only 0-1 bytes, we skipped the whole message which caused
Timo Sirainen <tss@iki.fi>
parents:
3675
diff
changeset
|
183 rstream->eof = TRUE; |
bae46114f240
if message was only 0-1 bytes, we skipped the whole message which caused
Timo Sirainen <tss@iki.fi>
parents:
3675
diff
changeset
|
184 } |
2431
8e9d8cb1e674
Removed istream.disconnected, it's too much of a special case and the only
Timo Sirainen <tss@iki.fi>
parents:
2421
diff
changeset
|
185 stream->istream.eof = TRUE; |
2187 | 186 handle_end_of_mail(rstream, pos); |
187 return ret < 0 ? _read(stream) : ret; | |
188 } | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 if (stream->istream.v_offset == rstream->from_offset) { |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
192 /* beginning of message, we haven't yet read our From-line */ |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
193 if (mbox_read_from_line(rstream) < 0) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
194 stream->pos = 0; |
2464
db61972ffeb3
istream-raw-mbox now sets stream->eof when it's at the end of message to fix
Timo Sirainen <tss@iki.fi>
parents:
2457
diff
changeset
|
195 rstream->eof = TRUE; |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
196 rstream->corrupted = TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
197 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
199 |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
200 /* got it. we don't want to return it however, |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
201 so start again from headers */ |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
202 buf = i_stream_get_data(rstream->input, &pos); |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
203 if (pos == 0) |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
204 return _read(stream); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
205 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
206 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
207 /* See if we have From-line here - note that it works right only |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
208 because all characters are different in mbox_from. */ |
3430 | 209 fromp = mbox_from; from_start_pos = from_after_pos = (size_t)-1; |
3035
6f1ea1c7212f
Don't break if line begins with NUL. Don't return -2 as long as underlying
Timo Sirainen <tss@iki.fi>
parents:
2997
diff
changeset
|
210 eoh_char = rstream->body_offset == (uoff_t)-1 ? '\n' : -1; |
2167 | 211 for (i = stream->pos; i < pos; i++) { |
2264
a0ffc18d3185
body_offset wasn't set if mail had no header.
Timo Sirainen <tss@iki.fi>
parents:
2254
diff
changeset
|
212 if (buf[i] == eoh_char && |
a0ffc18d3185
body_offset wasn't set if mail had no header.
Timo Sirainen <tss@iki.fi>
parents:
2254
diff
changeset
|
213 ((i > 0 && buf[i-1] == '\n') || |
3430 | 214 (i > 1 && buf[i-1] == '\r' && buf[i-2] == '\n') || |
2264
a0ffc18d3185
body_offset wasn't set if mail had no header.
Timo Sirainen <tss@iki.fi>
parents:
2254
diff
changeset
|
215 stream->istream.v_offset + i == rstream->hdr_offset)) { |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
216 rstream->body_offset = stream->istream.v_offset + i + 1; |
3035
6f1ea1c7212f
Don't break if line begins with NUL. Don't return -2 as long as underlying
Timo Sirainen <tss@iki.fi>
parents:
2997
diff
changeset
|
217 eoh_char = -1; |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
218 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
219 if (buf[i] == *fromp) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
220 if (*++fromp == '\0') { |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
221 /* potential From-line, see if we have the |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
222 rest of the line buffered. |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
223 FIXME: if From-line is longer than input |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
224 buffer, we break. probably irrelevant.. */ |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
225 i++; |
3430 | 226 from_after_pos = i; |
2167 | 227 from_start_pos = i - 6; |
3430 | 228 if (from_start_pos > 0 && |
229 buf[from_start_pos-1] == '\r') { | |
230 /* CR also belongs to it. */ | |
231 from_start_pos--; | |
232 } | |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
233 fromp = mbox_from; |
2363 | 234 } else if (from_start_pos != (size_t)-1) { |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
235 /* we have the whole From-line here now. |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
236 See if it's a valid one. */ |
3430 | 237 if (mbox_from_parse(buf + from_after_pos, |
238 pos - from_after_pos, | |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
239 &received_time, |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
240 &sender) == 0) { |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
241 /* yep, we stop here. */ |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
242 rstream->next_received_time = |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
243 received_time; |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
244 i_free(rstream->next_sender); |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
245 rstream->next_sender = sender; |
2464
db61972ffeb3
istream-raw-mbox now sets stream->eof when it's at the end of message to fix
Timo Sirainen <tss@iki.fi>
parents:
2457
diff
changeset
|
246 stream->istream.eof = TRUE; |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
247 |
2155 | 248 handle_end_of_mail(rstream, |
249 from_start_pos); | |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
250 break; |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
251 } |
2363 | 252 from_start_pos = (size_t)-1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
253 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
254 } else { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 fromp = mbox_from; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
256 if (buf[i] == *fromp) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
257 fromp++; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
258 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
259 } |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
260 |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
261 /* we want to go at least one byte further next time */ |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
262 rstream->input_peak_offset = stream->istream.v_offset + i; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
263 |
2363 | 264 if (from_start_pos != (size_t)-1) { |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
265 /* we're waiting for the \n at the end of From-line */ |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
266 new_pos = from_start_pos; |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
267 } else { |
3430 | 268 /* leave out the beginnings of potential From-line + CR */ |
269 new_pos = i - (fromp - mbox_from) - 1; | |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
270 } |
2167 | 271 |
2473 | 272 stream->buffer = buf; |
273 if (new_pos == stream->pos) { | |
3035
6f1ea1c7212f
Don't break if line begins with NUL. Don't return -2 as long as underlying
Timo Sirainen <tss@iki.fi>
parents:
2997
diff
changeset
|
274 if (stream->istream.eof || ret > 0) |
2473 | 275 return _read(stream); |
3438
22d4fd7fd436
Fixed breakage caused by CRLF-support.
Timo Sirainen <tss@iki.fi>
parents:
3430
diff
changeset
|
276 i_assert(new_pos > 0); |
2473 | 277 ret = -2; |
278 } else { | |
2167 | 279 i_assert(new_pos > stream->pos); |
280 ret = new_pos - stream->pos; | |
281 stream->pos = new_pos; | |
282 } | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
283 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
284 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
285 |
3629
e05a1af4bbc7
Added i_stream_seek_mark() and used it
Timo Sirainen <tss@iki.fi>
parents:
3438
diff
changeset
|
286 static void _seek(struct _istream *stream, uoff_t v_offset, |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3848
diff
changeset
|
287 bool mark __attr_unused__) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
288 { |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
289 struct raw_mbox_istream *rstream = (struct raw_mbox_istream *)stream; |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
290 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
291 stream->istream.v_offset = v_offset; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
292 stream->skip = stream->pos = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
293 stream->buffer = NULL; |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
294 |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
295 rstream->input_peak_offset = 0; |
2464
db61972ffeb3
istream-raw-mbox now sets stream->eof when it's at the end of message to fix
Timo Sirainen <tss@iki.fi>
parents:
2457
diff
changeset
|
296 rstream->eof = FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
297 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
298 |
3242
9a08cf5e5f61
i_stream_sync() replaced istream_raw_mbox_flush(). Use i_stream_stat()
Timo Sirainen <tss@iki.fi>
parents:
3035
diff
changeset
|
299 static void _sync(struct _istream *stream) |
9a08cf5e5f61
i_stream_sync() replaced istream_raw_mbox_flush(). Use i_stream_stat()
Timo Sirainen <tss@iki.fi>
parents:
3035
diff
changeset
|
300 { |
9a08cf5e5f61
i_stream_sync() replaced istream_raw_mbox_flush(). Use i_stream_stat()
Timo Sirainen <tss@iki.fi>
parents:
3035
diff
changeset
|
301 struct raw_mbox_istream *rstream = (struct raw_mbox_istream *)stream; |
9a08cf5e5f61
i_stream_sync() replaced istream_raw_mbox_flush(). Use i_stream_stat()
Timo Sirainen <tss@iki.fi>
parents:
3035
diff
changeset
|
302 |
9a08cf5e5f61
i_stream_sync() replaced istream_raw_mbox_flush(). Use i_stream_stat()
Timo Sirainen <tss@iki.fi>
parents:
3035
diff
changeset
|
303 i_stream_sync(rstream->input); |
9a08cf5e5f61
i_stream_sync() replaced istream_raw_mbox_flush(). Use i_stream_stat()
Timo Sirainen <tss@iki.fi>
parents:
3035
diff
changeset
|
304 |
9a08cf5e5f61
i_stream_sync() replaced istream_raw_mbox_flush(). Use i_stream_stat()
Timo Sirainen <tss@iki.fi>
parents:
3035
diff
changeset
|
305 rstream->istream.skip = 0; |
9a08cf5e5f61
i_stream_sync() replaced istream_raw_mbox_flush(). Use i_stream_stat()
Timo Sirainen <tss@iki.fi>
parents:
3035
diff
changeset
|
306 rstream->istream.pos = 0; |
9a08cf5e5f61
i_stream_sync() replaced istream_raw_mbox_flush(). Use i_stream_stat()
Timo Sirainen <tss@iki.fi>
parents:
3035
diff
changeset
|
307 } |
9a08cf5e5f61
i_stream_sync() replaced istream_raw_mbox_flush(). Use i_stream_stat()
Timo Sirainen <tss@iki.fi>
parents:
3035
diff
changeset
|
308 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3848
diff
changeset
|
309 static const struct stat *_stat(struct _istream *stream, bool exact) |
3242
9a08cf5e5f61
i_stream_sync() replaced istream_raw_mbox_flush(). Use i_stream_stat()
Timo Sirainen <tss@iki.fi>
parents:
3035
diff
changeset
|
310 { |
9a08cf5e5f61
i_stream_sync() replaced istream_raw_mbox_flush(). Use i_stream_stat()
Timo Sirainen <tss@iki.fi>
parents:
3035
diff
changeset
|
311 struct raw_mbox_istream *rstream = (struct raw_mbox_istream *)stream; |
4327 | 312 const struct stat *st; |
3242
9a08cf5e5f61
i_stream_sync() replaced istream_raw_mbox_flush(). Use i_stream_stat()
Timo Sirainen <tss@iki.fi>
parents:
3035
diff
changeset
|
313 |
4327 | 314 st = i_stream_stat(rstream->input, exact); |
315 if (st == NULL) | |
316 return NULL; | |
317 | |
318 stream->statbuf = *st; | |
319 stream->statbuf.st_size = -1; | |
320 return &stream->statbuf; | |
3242
9a08cf5e5f61
i_stream_sync() replaced istream_raw_mbox_flush(). Use i_stream_stat()
Timo Sirainen <tss@iki.fi>
parents:
3035
diff
changeset
|
321 } |
9a08cf5e5f61
i_stream_sync() replaced istream_raw_mbox_flush(). Use i_stream_stat()
Timo Sirainen <tss@iki.fi>
parents:
3035
diff
changeset
|
322 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
323 struct istream *i_stream_create_raw_mbox(pool_t pool, struct istream *input) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
324 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
325 struct raw_mbox_istream *rstream; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
326 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
327 i_stream_ref(input); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
328 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
329 rstream = p_new(pool, struct raw_mbox_istream, 1); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
330 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
331 rstream->input = input; |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
332 rstream->body_offset = (uoff_t)-1; |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
333 rstream->mail_size = (uoff_t)-1; |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
334 rstream->received_time = (time_t)-1; |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
335 rstream->next_received_time = (time_t)-1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
336 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
337 rstream->istream.iostream.close = _close; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
338 rstream->istream.iostream.destroy = _destroy; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
339 rstream->istream.iostream.set_max_buffer_size = _set_max_buffer_size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
340 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
341 rstream->istream.read = _read; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
342 rstream->istream.seek = _seek; |
3242
9a08cf5e5f61
i_stream_sync() replaced istream_raw_mbox_flush(). Use i_stream_stat()
Timo Sirainen <tss@iki.fi>
parents:
3035
diff
changeset
|
343 rstream->istream.sync = _sync; |
9a08cf5e5f61
i_stream_sync() replaced istream_raw_mbox_flush(). Use i_stream_stat()
Timo Sirainen <tss@iki.fi>
parents:
3035
diff
changeset
|
344 rstream->istream.stat = _stat; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
345 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
346 return _i_stream_create(&rstream->istream, pool, -1, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
347 input->real_stream->abs_start_offset); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
348 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
349 |
3941
08a302d3e525
Boolean changes broke istream_raw_mbox_is_valid_from() when it hit
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
350 static int istream_raw_mbox_is_valid_from(struct raw_mbox_istream *rstream) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
351 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
352 const unsigned char *data; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
353 size_t size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
354 time_t received_time; |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
355 char *sender; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
356 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
357 /* minimal: "From x Thu Nov 29 22:33:52 2001" = 31 chars */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
358 if (i_stream_read_data(rstream->input, &data, &size, 30) == -1) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
359 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
360 |
3430 | 361 if ((size == 1 && data[0] == '\n') || |
362 (size == 2 && data[0] == '\r' && data[1] == '\n')) { | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
363 /* EOF */ |
3941
08a302d3e525
Boolean changes broke istream_raw_mbox_is_valid_from() when it hit
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
364 return 1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
365 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
366 |
3430 | 367 if (size > 31 && memcmp(data, "\nFrom ", 6) == 0) { |
368 data += 6; | |
369 size -= 6; | |
370 } else if (size > 32 && memcmp(data, "\r\nFrom ", 7) == 0) { | |
371 data += 7; | |
372 size -= 7; | |
373 } else { | |
3941
08a302d3e525
Boolean changes broke istream_raw_mbox_is_valid_from() when it hit
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
374 return 0; |
3430 | 375 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
376 |
3430 | 377 while (memchr(data, '\n', size) == NULL) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
378 if (i_stream_read_data(rstream->input, &data, &size, size) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
379 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
380 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
381 |
3430 | 382 if (mbox_from_parse(data, size, &received_time, &sender) < 0) |
3941
08a302d3e525
Boolean changes broke istream_raw_mbox_is_valid_from() when it hit
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
383 return 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
384 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
385 rstream->next_received_time = received_time; |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
386 i_free(rstream->next_sender); |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
387 rstream->next_sender = sender; |
3941
08a302d3e525
Boolean changes broke istream_raw_mbox_is_valid_from() when it hit
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
388 return 1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
389 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
390 |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
391 uoff_t istream_raw_mbox_get_start_offset(struct istream *stream) |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
392 { |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
393 struct raw_mbox_istream *rstream = |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
394 (struct raw_mbox_istream *)stream->real_stream; |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
395 |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
396 return rstream->from_offset; |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
397 } |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
398 |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
399 uoff_t istream_raw_mbox_get_header_offset(struct istream *stream) |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
400 { |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
401 struct raw_mbox_istream *rstream = |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
402 (struct raw_mbox_istream *)stream->real_stream; |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
403 |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
404 if (rstream->hdr_offset == rstream->from_offset) |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
405 (void)_read(&rstream->istream); |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
406 |
3848
5703f0516342
Handle unexpectedly breaking mboxes better without crashing.
Timo Sirainen <tss@iki.fi>
parents:
3693
diff
changeset
|
407 if (rstream->corrupted) { |
5703f0516342
Handle unexpectedly breaking mboxes better without crashing.
Timo Sirainen <tss@iki.fi>
parents:
3693
diff
changeset
|
408 i_error("Unexpectedly lost From-line at " |
5703f0516342
Handle unexpectedly breaking mboxes better without crashing.
Timo Sirainen <tss@iki.fi>
parents:
3693
diff
changeset
|
409 "%"PRIuUOFF_T, rstream->from_offset); |
5703f0516342
Handle unexpectedly breaking mboxes better without crashing.
Timo Sirainen <tss@iki.fi>
parents:
3693
diff
changeset
|
410 return (uoff_t)-1; |
5703f0516342
Handle unexpectedly breaking mboxes better without crashing.
Timo Sirainen <tss@iki.fi>
parents:
3693
diff
changeset
|
411 } |
5703f0516342
Handle unexpectedly breaking mboxes better without crashing.
Timo Sirainen <tss@iki.fi>
parents:
3693
diff
changeset
|
412 |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
413 return rstream->hdr_offset; |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
414 } |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
415 |
2125
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
416 uoff_t istream_raw_mbox_get_body_offset(struct istream *stream) |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
417 { |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
418 struct raw_mbox_istream *rstream = |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
419 (struct raw_mbox_istream *)stream->real_stream; |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
420 uoff_t offset; |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
421 size_t pos; |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
422 |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
423 if (rstream->body_offset != (uoff_t)-1) |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
424 return rstream->body_offset; |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
425 |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
426 offset = stream->v_offset; |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
427 i_stream_seek(stream, rstream->hdr_offset); |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
428 while (rstream->body_offset == (uoff_t)-1) { |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
429 i_stream_get_data(stream, &pos); |
2125
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
430 i_stream_skip(stream, pos); |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
431 |
3848
5703f0516342
Handle unexpectedly breaking mboxes better without crashing.
Timo Sirainen <tss@iki.fi>
parents:
3693
diff
changeset
|
432 if (_read(&rstream->istream) < 0) { |
5703f0516342
Handle unexpectedly breaking mboxes better without crashing.
Timo Sirainen <tss@iki.fi>
parents:
3693
diff
changeset
|
433 if (rstream->corrupted) { |
5703f0516342
Handle unexpectedly breaking mboxes better without crashing.
Timo Sirainen <tss@iki.fi>
parents:
3693
diff
changeset
|
434 i_error("Unexpectedly lost From-line at " |
5703f0516342
Handle unexpectedly breaking mboxes better without crashing.
Timo Sirainen <tss@iki.fi>
parents:
3693
diff
changeset
|
435 "%"PRIuUOFF_T, rstream->from_offset); |
5703f0516342
Handle unexpectedly breaking mboxes better without crashing.
Timo Sirainen <tss@iki.fi>
parents:
3693
diff
changeset
|
436 } else { |
5703f0516342
Handle unexpectedly breaking mboxes better without crashing.
Timo Sirainen <tss@iki.fi>
parents:
3693
diff
changeset
|
437 i_assert(rstream->body_offset != (uoff_t)-1); |
5703f0516342
Handle unexpectedly breaking mboxes better without crashing.
Timo Sirainen <tss@iki.fi>
parents:
3693
diff
changeset
|
438 } |
2125
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
439 break; |
3848
5703f0516342
Handle unexpectedly breaking mboxes better without crashing.
Timo Sirainen <tss@iki.fi>
parents:
3693
diff
changeset
|
440 } |
2125
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
441 } |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
442 |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
443 i_stream_seek(stream, offset); |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
444 return rstream->body_offset; |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
445 } |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
446 |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
447 uoff_t istream_raw_mbox_get_body_size(struct istream *stream, uoff_t body_size) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
448 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
449 struct raw_mbox_istream *rstream = |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
450 (struct raw_mbox_istream *)stream->real_stream; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
451 const unsigned char *data; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
452 size_t size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
453 |
2125
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
454 i_assert(rstream->hdr_offset != (uoff_t)-1); |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
455 i_assert(rstream->body_offset != (uoff_t)-1); |
dc18cc3568b0
several fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2107
diff
changeset
|
456 |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
457 if (rstream->mail_size != (uoff_t)-1) { |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
458 return rstream->mail_size - |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
459 (rstream->body_offset - rstream->hdr_offset); |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
460 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
461 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
462 if (body_size != (uoff_t)-1) { |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
463 i_stream_seek(rstream->input, rstream->body_offset + body_size); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
464 if (istream_raw_mbox_is_valid_from(rstream) > 0) { |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
465 rstream->mail_size = body_size + |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
466 (rstream->body_offset - rstream->hdr_offset); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
467 return body_size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
468 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
469 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
470 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
471 /* have to read through the message body */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
472 while (i_stream_read_data(stream, &data, &size, 0) > 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
473 i_stream_skip(stream, size); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
474 |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
475 i_assert(rstream->mail_size != (uoff_t)-1); |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
476 return rstream->mail_size - |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
477 (rstream->body_offset - rstream->hdr_offset); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
478 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
479 |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
480 time_t istream_raw_mbox_get_received_time(struct istream *stream) |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
481 { |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
482 struct raw_mbox_istream *rstream = |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
483 (struct raw_mbox_istream *)stream->real_stream; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
484 |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
485 if (rstream->received_time == (time_t)-1) |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
486 (void)_read(&rstream->istream); |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
487 return rstream->received_time; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
488 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
489 |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
490 const char *istream_raw_mbox_get_sender(struct istream *stream) |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
491 { |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
492 struct raw_mbox_istream *rstream = |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
493 (struct raw_mbox_istream *)stream->real_stream; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
494 |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
495 if (rstream->sender == NULL) |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
496 (void)_read(&rstream->istream); |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
497 return rstream->sender == NULL ? "" : rstream->sender; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
498 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
499 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
500 void istream_raw_mbox_next(struct istream *stream, uoff_t body_size) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
501 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
502 struct raw_mbox_istream *rstream = |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
503 (struct raw_mbox_istream *)stream->real_stream; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
504 |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
505 body_size = istream_raw_mbox_get_body_size(stream, body_size); |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
506 rstream->mail_size = (uoff_t)-1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
507 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
508 rstream->received_time = rstream->next_received_time; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
509 rstream->next_received_time = (time_t)-1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
510 |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
511 i_free(rstream->sender); |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
512 rstream->sender = rstream->next_sender; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
513 rstream->next_sender = NULL; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
514 |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
515 rstream->from_offset = rstream->body_offset + body_size; |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
516 rstream->hdr_offset = rstream->from_offset; |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
517 rstream->body_offset = (uoff_t)-1; |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
518 |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
519 if (stream->v_offset != rstream->from_offset) |
3629
e05a1af4bbc7
Added i_stream_seek_mark() and used it
Timo Sirainen <tss@iki.fi>
parents:
3438
diff
changeset
|
520 i_stream_seek_mark(stream, rstream->from_offset); |
e05a1af4bbc7
Added i_stream_seek_mark() and used it
Timo Sirainen <tss@iki.fi>
parents:
3438
diff
changeset
|
521 i_stream_seek_mark(rstream->input, rstream->from_offset); |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
522 |
2464
db61972ffeb3
istream-raw-mbox now sets stream->eof when it's at the end of message to fix
Timo Sirainen <tss@iki.fi>
parents:
2457
diff
changeset
|
523 rstream->eof = FALSE; |
2465 | 524 rstream->istream.istream.eof = FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
525 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
526 |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
527 int istream_raw_mbox_seek(struct istream *stream, uoff_t offset) |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
528 { |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
529 struct raw_mbox_istream *rstream = |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
530 (struct raw_mbox_istream *)stream->real_stream; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3848
diff
changeset
|
531 bool check; |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
532 |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
533 rstream->corrupted = FALSE; |
2464
db61972ffeb3
istream-raw-mbox now sets stream->eof when it's at the end of message to fix
Timo Sirainen <tss@iki.fi>
parents:
2457
diff
changeset
|
534 rstream->eof = FALSE; |
2465 | 535 rstream->istream.istream.eof = FALSE; |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
536 |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
537 if (rstream->mail_size != (uoff_t)-1 && |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
538 rstream->hdr_offset + rstream->mail_size == offset) { |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
539 istream_raw_mbox_next(stream, (uoff_t)-1); |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
540 return 0; |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
541 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
542 |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
543 if (offset == rstream->from_offset) { |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
544 /* back to beginning of current message */ |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
545 offset = rstream->hdr_offset; |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
546 check = offset == 0; |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
547 } else { |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
548 rstream->body_offset = (uoff_t)-1; |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
549 rstream->mail_size = (uoff_t)-1; |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
550 rstream->received_time = (time_t)-1; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
551 rstream->next_received_time = (time_t)-1; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
552 |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
553 i_free(rstream->sender); |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
554 rstream->sender = NULL; |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
555 i_free(rstream->next_sender); |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
556 rstream->next_sender = NULL; |
1981
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
557 |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
558 rstream->from_offset = offset; |
eb282832fc75
mbox rewriting is almost working - the hard part is done.
Timo Sirainen <tss@iki.fi>
parents:
1978
diff
changeset
|
559 rstream->hdr_offset = offset; |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
560 check = TRUE; |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
561 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
562 |
3629
e05a1af4bbc7
Added i_stream_seek_mark() and used it
Timo Sirainen <tss@iki.fi>
parents:
3438
diff
changeset
|
563 i_stream_seek_mark(stream, offset); |
e05a1af4bbc7
Added i_stream_seek_mark() and used it
Timo Sirainen <tss@iki.fi>
parents:
3438
diff
changeset
|
564 i_stream_seek_mark(rstream->input, offset); |
2146
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
565 |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
566 if (check) |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
567 (void)_read(&rstream->istream); |
3a33250e6a2d
Complain if file isn't in mbox format. Complain if From-line wasn't found
Timo Sirainen <tss@iki.fi>
parents:
2126
diff
changeset
|
568 return rstream->corrupted ? -1 : 0; |
1978
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
569 } |
6303ef092c5b
mbox code compiles again, but syncing is only partially implemented so
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
570 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3848
diff
changeset
|
571 bool istream_raw_mbox_is_eof(struct istream *stream) |
2464
db61972ffeb3
istream-raw-mbox now sets stream->eof when it's at the end of message to fix
Timo Sirainen <tss@iki.fi>
parents:
2457
diff
changeset
|
572 { |
db61972ffeb3
istream-raw-mbox now sets stream->eof when it's at the end of message to fix
Timo Sirainen <tss@iki.fi>
parents:
2457
diff
changeset
|
573 struct raw_mbox_istream *rstream = |
db61972ffeb3
istream-raw-mbox now sets stream->eof when it's at the end of message to fix
Timo Sirainen <tss@iki.fi>
parents:
2457
diff
changeset
|
574 (struct raw_mbox_istream *)stream->real_stream; |
db61972ffeb3
istream-raw-mbox now sets stream->eof when it's at the end of message to fix
Timo Sirainen <tss@iki.fi>
parents:
2457
diff
changeset
|
575 |
db61972ffeb3
istream-raw-mbox now sets stream->eof when it's at the end of message to fix
Timo Sirainen <tss@iki.fi>
parents:
2457
diff
changeset
|
576 return rstream->eof; |
db61972ffeb3
istream-raw-mbox now sets stream->eof when it's at the end of message to fix
Timo Sirainen <tss@iki.fi>
parents:
2457
diff
changeset
|
577 } |