157
157
struct index_mail *mail = (struct index_mail *)_mail;
158
158
struct index_mail_data *data = &mail->data;
159
159
struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
160
const struct mail_index_header *hdr;
161
160
struct istream *input;
162
161
struct message_size hdr_size;
163
uoff_t size, body_offset, body_size, next_offset, old_offset;
162
uoff_t size, body_offset, body_size, old_offset;
166
164
size = index_mail_get_physical_size(_mail);
167
165
if (size != (uoff_t)-1)
172
170
input = mail_get_stream(_mail, &hdr_size, NULL);
173
171
if (input == NULL)
174
172
return (uoff_t)-1;
175
i_stream_sync(mbox->mbox_stream);
177
174
/* our header size varies, so don't do any caching */
178
175
body_offset = istream_raw_mbox_get_body_offset(mbox->mbox_stream);
179
176
if (body_offset == (uoff_t)-1)
180
177
return (uoff_t)-1;
182
/* use the next message's offset to avoid reading through the entire
183
message body to find out its size */
184
hdr = mail_index_get_header(mail->trans->trans_view);
185
if (_mail->seq == hdr->messages_count) {
186
/* last message, use the synced mbox size */
189
trailer_size = (STORAGE(mbox->storage)->flags &
190
MAIL_STORAGE_FLAG_SAVE_CRLF) != 0 ? 2 : 1;
192
body_size = hdr->sync_size - body_offset - trailer_size;
193
} else if (mbox_file_lookup_offset(mbox, mail->trans->trans_view,
194
_mail->seq + 1, &next_offset,
196
body_size = next_offset - body_offset;
198
body_size = (uoff_t)-1;
201
179
/* verify that the calculated body size is correct */
202
180
body_size = istream_raw_mbox_get_body_size(mbox->mbox_stream,
205
183
data->physical_size = hdr_size.physical_size + body_size;
206
i_stream_seek(data->stream, old_offset);
207
i_stream_sync(mbox->mbox_stream);
208
184
return data->physical_size;