dovecot-2.0: mbox: Fixed looking up header MD5 values when they ...
dovecot at dovecot.org
dovecot at dovecot.org
Fri Oct 30 00:19:26 EET 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/1484bfe9bb2a
changeset: 10232:1484bfe9bb2a
user: Timo Sirainen <tss at iki.fi>
date: Thu Oct 29 18:17:54 2009 -0400
description:
mbox: Fixed looking up header MD5 values when they didn't exist yet.
diffstat:
1 file changed, 27 insertions(+), 15 deletions(-)
src/lib-storage/index/mbox/mbox-mail.c | 42 ++++++++++++++++++++------------
diffs (71 lines):
diff -r 410b72cf8567 -r 1484bfe9bb2a src/lib-storage/index/mbox/mbox-mail.c
--- a/src/lib-storage/index/mbox/mbox-mail.c Thu Oct 29 17:41:37 2009 -0400
+++ b/src/lib-storage/index/mbox/mbox-mail.c Thu Oct 29 18:17:54 2009 -0400
@@ -145,15 +145,30 @@ static int mbox_mail_get_save_date(struc
return 0;
}
+static bool
+mbox_mail_get_md5_header(struct index_mail *mail, const char **value_r)
+{
+ static uint8_t empty_md5[16] =
+ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
+ const void *ext_data;
+
+ mail_index_lookup_ext(mail->trans->trans_view, mail->mail.mail.seq,
+ mbox->md5hdr_ext_idx, &ext_data, NULL);
+ if (ext_data != NULL && memcmp(ext_data, empty_md5, 16) != 0) {
+ *value_r = binary_to_hex(ext_data, 16);
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
static int
mbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
const char **value_r)
{
- static uint8_t empty_md5[16] =
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- struct index_mail *mail = (struct index_mail *)_mail;
- struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
- const void *ext_data;
+ struct index_mail *mail = (struct index_mail *)_mail;
+ struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
switch (field) {
case MAIL_FETCH_FROM_ENVELOPE:
@@ -163,16 +178,8 @@ mbox_mail_get_special(struct mail *_mail
*value_r = istream_raw_mbox_get_sender(mbox->mbox_stream);
return 0;
case MAIL_FETCH_HEADER_MD5:
- mail_index_lookup_ext(mail->trans->trans_view, _mail->seq,
- mbox->md5hdr_ext_idx, &ext_data, NULL);
- if (ext_data == NULL) {
- *value_r = "";
+ if (mbox_mail_get_md5_header(mail, value_r))
return 0;
- }
- if (memcmp(ext_data, empty_md5, 16) != 0) {
- *value_r = binary_to_hex(ext_data, 16);
- return 0;
- }
/* i guess in theory the empty_md5 is valid and can happen,
but it's almost guaranteed that it means the MD5 sum is
@@ -181,7 +188,12 @@ mbox_mail_get_special(struct mail *_mail
mbox_prepare_resync(mail);
if (mbox_sync(mbox, MBOX_SYNC_FORCE_SYNC) < 0)
return -1;
- break;
+
+ if (!mbox_mail_get_md5_header(mail, value_r)) {
+ i_error("mbox resyncing didn't save header MD5 values");
+ return -1;
+ }
+ return 0;
default:
break;
}
More information about the dovecot-cvs
mailing list