dovecot: mail_get_physical_size() returns now the message stream...

dovecot at dovecot.org dovecot at dovecot.org
Fri Dec 21 23:04:25 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/ac32dc7ae0c1
changeset: 7016:ac32dc7ae0c1
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Dec 21 22:58:11 2007 +0200
description:
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.

diffstat:

3 files changed, 18 insertions(+), 12 deletions(-)
src/lib-storage/index/index-mail.c     |    3 +++
src/lib-storage/index/mbox/mbox-mail.c |   25 ++++++++++++++-----------
src/lib-storage/mail-storage.h         |    2 +-

diffs (70 lines):

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 @@ static void index_mail_get_cached_body_s
 	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 @@ static int mbox_mail_get_physical_size(s
 	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;
-
-	if (mbox_mail_seek(mail) < 0)
+	struct istream *input;
+	struct message_size hdr_size;
+	uoff_t body_offset, body_size, next_offset;
+
+	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 @@ static int mbox_mail_get_physical_size(s
 	}
 
 	/* verify that the calculated body size is correct */
-	body_size = istream_raw_mbox_get_body_size(stream, body_size);
-
-	data->physical_size = (body_offset - hdr_offset) + body_size;
+	body_size = istream_raw_mbox_get_body_size(mbox->mbox_stream,
+						   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 @@ int mail_get_save_date(struct mail *mail
 /* 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.


More information about the dovecot-cvs mailing list