From: Timo Sirainen Date: Fri, 3 Dec 2010 10:15:20 +0000 (+0000) Subject: dbox: Added dbox_file_get_plaintext_size() for easily getting it. X-Git-Tag: 2.0.8~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=427ad9fea54628d52f04c8a76269749a8e6fae7a;p=thirdparty%2Fdovecot%2Fcore.git dbox: Added dbox_file_get_plaintext_size() for easily getting it. --- diff --git a/src/lib-storage/index/dbox-common/dbox-file.c b/src/lib-storage/index/dbox-common/dbox-file.c index b9d19bd72d..21713e0633 100644 --- a/src/lib-storage/index/dbox-common/dbox-file.c +++ b/src/lib-storage/index/dbox-common/dbox-file.c @@ -685,6 +685,22 @@ const char *dbox_file_metadata_get(struct dbox_file *file, return NULL; } +uoff_t dbox_file_get_plaintext_size(struct dbox_file *file) +{ + const char *value; + + i_assert(file->metadata_read_offset == file->cur_offset); + + /* see if we have it in metadata */ + value = dbox_file_metadata_get(file, DBOX_METADATA_PHYSICAL_SIZE); + if (value != NULL) + return strtoul(value, NULL, 16); + else { + /* no. that means we can use the size in the header */ + return file->cur_physical_size; + } +} + void dbox_msg_header_fill(struct dbox_message_header *dbox_msg_hdr, uoff_t message_size) { diff --git a/src/lib-storage/index/dbox-common/dbox-file.h b/src/lib-storage/index/dbox-common/dbox-file.h index 03f12d9b0f..d458716412 100644 --- a/src/lib-storage/index/dbox-common/dbox-file.h +++ b/src/lib-storage/index/dbox-common/dbox-file.h @@ -183,6 +183,10 @@ int dbox_file_metadata_read(struct dbox_file *file); const char *dbox_file_metadata_get(struct dbox_file *file, enum dbox_metadata_key key); +/* Returns DBOX_METADATA_PHYSICAL_SIZE if set, otherwise physical size from + header. They differ only for e.g. compressed mails. */ +uoff_t dbox_file_get_plaintext_size(struct dbox_file *file); + /* Fix a broken dbox file by rename()ing over it with a fixed file. Everything before start_offset is assumed to be valid and is simply copied. The file is reopened afterwards. Returns 0 if ok, -1 if I/O error. */ diff --git a/src/lib-storage/index/dbox-common/dbox-mail.c b/src/lib-storage/index/dbox-common/dbox-mail.c index 57cc4f66bb..9da1e81f2c 100644 --- a/src/lib-storage/index/dbox-common/dbox-mail.c +++ b/src/lib-storage/index/dbox-common/dbox-mail.c @@ -79,22 +79,14 @@ int dbox_mail_get_physical_size(struct mail *_mail, uoff_t *size_r) struct dbox_mail *mail = (struct dbox_mail *)_mail; struct index_mail_data *data = &mail->imail.data; struct dbox_file *file; - const char *value; if (index_mail_get_physical_size(_mail, size_r) == 0) return 0; - /* see if we have it in metadata */ if (dbox_mail_metadata_read(mail, &file) < 0) return -1; - value = dbox_file_metadata_get(file, DBOX_METADATA_PHYSICAL_SIZE); - if (value != NULL) - data->physical_size = strtoul(value, NULL, 16); - else { - /* no. that means we can use the size in the header */ - data->physical_size = file->cur_physical_size; - } + data->physical_size = dbox_file_get_plaintext_size(file); *size_r = data->physical_size; return 0; }