# HG changeset patch # User Timo Sirainen # Date 1198270691 -7200 # Node ID ac32dc7ae0c12fa4c6e51f15da8d5a8b41e3c96a # Parent 03cb4c0802a7bb7a80d34300098323ca02a02ef3 mail_get_physical_size() returns now the message stream's size and not the physical size on disk that varies. This fixes mbox issues and it's also more correct conceptually, because it doesn't return metadata size with other formats either. diff -r 03cb4c0802a7 -r ac32dc7ae0c1 src/lib-storage/index/index-mail.c --- a/src/lib-storage/index/index-mail.c Fri Dec 21 21:39:58 2007 +0200 +++ b/src/lib-storage/index/index-mail.c Fri Dec 21 22:58:11 2007 +0200 @@ -334,6 +334,9 @@ if (!data->hdr_size_set) return; + /* we've already called get_cached_msgpart_sizes() and it didn't work. + try to do this by using cached virtual size and a quick physical + size lookup. */ if (!index_mail_get_cached_virtual_size(mail, &tmp)) return; diff -r 03cb4c0802a7 -r ac32dc7ae0c1 src/lib-storage/index/mbox/mbox-mail.c --- a/src/lib-storage/index/mbox/mbox-mail.c Fri Dec 21 21:39:58 2007 +0200 +++ b/src/lib-storage/index/mbox/mbox-mail.c Fri Dec 21 22:58:11 2007 +0200 @@ -172,17 +172,19 @@ struct index_mail_data *data = &mail->data; struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox; const struct mail_index_header *hdr; - struct istream *stream; - uoff_t hdr_offset, body_offset, body_size; - uoff_t next_offset; + struct istream *input; + struct message_size hdr_size; + uoff_t body_offset, body_size, next_offset; - if (mbox_mail_seek(mail) < 0) + if (index_mail_get_physical_size(_mail, size_r) == 0) + return 0; + + /* we want to return the header size as seen by mail_get_stream(). */ + if (mail_get_stream(_mail, &hdr_size, NULL, &input) < 0) return -1; /* our header size varies, so don't do any caching */ - stream = mbox->mbox_stream; - hdr_offset = istream_raw_mbox_get_header_offset(stream); - body_offset = istream_raw_mbox_get_body_offset(stream); + body_offset = istream_raw_mbox_get_body_offset(mbox->mbox_stream); if (body_offset == (uoff_t)-1) { mail_storage_set_critical(_mail->box->storage, "Couldn't get mbox size"); @@ -208,9 +210,10 @@ } /* verify that the calculated body size is correct */ - body_size = istream_raw_mbox_get_body_size(stream, body_size); + body_size = istream_raw_mbox_get_body_size(mbox->mbox_stream, + body_size); - data->physical_size = (body_offset - hdr_offset) + body_size; + data->physical_size = hdr_size.physical_size + body_size; *size_r = data->physical_size; return 0; } diff -r 03cb4c0802a7 -r ac32dc7ae0c1 src/lib-storage/mail-storage.h --- a/src/lib-storage/mail-storage.h Fri Dec 21 21:39:58 2007 +0200 +++ b/src/lib-storage/mail-storage.h Fri Dec 21 22:58:11 2007 +0200 @@ -430,7 +430,7 @@ /* Get the space used by the mail as seen by the reader. Linefeeds are always counted as being CR+LF. */ int mail_get_virtual_size(struct mail *mail, uoff_t *size_r); -/* Get the space used by the mail in disk. */ +/* Get the size of the stream returned by mail_get_stream(). */ int mail_get_physical_size(struct mail *mail, uoff_t *size_r); /* Get value for single header field, or NULL if header wasn't found.