From: Timo Sirainen Date: Wed, 4 Apr 2012 02:34:11 +0000 (+0300) Subject: maildir: Remember the mail's GUID/filename in memory once it's fetched once. X-Git-Tag: 2.1.4~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46c903eac3abcc7d32780da76ee6a79c26d185b6;p=thirdparty%2Fdovecot%2Fcore.git maildir: Remember the mail's GUID/filename in memory once it's fetched once. This allows retrieving it later even if the message gets expunged. --- diff --git a/src/lib-storage/index/index-mail.h b/src/lib-storage/index/index-mail.h index 869dff9e70..69a99404dd 100644 --- a/src/lib-storage/index/index-mail.h +++ b/src/lib-storage/index/index-mail.h @@ -77,7 +77,7 @@ struct index_mail_data { uint32_t parse_line_num; struct message_part *parts; - const char *envelope, *body, *bodystructure, *uid_string, *guid; + const char *envelope, *body, *bodystructure, *guid, *filename; const char *from_envelope; struct message_part_envelope_data *envelope_data; diff --git a/src/lib-storage/index/maildir/maildir-mail.c b/src/lib-storage/index/maildir/maildir-mail.c index 8a6674b4d4..16a3a0b071 100644 --- a/src/lib-storage/index/maildir/maildir-mail.c +++ b/src/lib-storage/index/maildir/maildir-mail.c @@ -482,6 +482,11 @@ maildir_mail_get_special(struct mail *_mail, enum mail_fetch_field field, /* use GUID from uidlist if it exists */ i_assert(!_mail->saving); + if (mail->data.guid != NULL) { + *value_r = mail->data.guid; + return 0; + } + /* first make sure that we have a refreshed uidlist */ if (maildir_mail_get_fname(mbox, _mail, &fname) <= 0) return -1; @@ -490,7 +495,8 @@ maildir_mail_get_special(struct mail *_mail, enum mail_fetch_field field, MAILDIR_UIDLIST_REC_EXT_GUID); if (guid != NULL) { if (*guid != '\0') { - *value_r = p_strdup(mail->data_pool, guid); + *value_r = mail->data.guid = + p_strdup(mail->data_pool, guid); return 0; } @@ -503,9 +509,14 @@ maildir_mail_get_special(struct mail *_mail, enum mail_fetch_field field, } /* default to base filename: */ + if (maildir_mail_get_special(_mail, MAIL_FETCH_UIDL_FILE_NAME, + value_r) < 0) + return -1; + mail->data.guid = mail->data.filename; + return 0; case MAIL_FETCH_UIDL_FILE_NAME: - if (mail->data.guid != NULL) { - *value_r = mail->data.guid; + if (mail->data.filename != NULL) { + *value_r = mail->data.filename; return 0; } if (fname != NULL) { @@ -521,10 +532,10 @@ maildir_mail_get_special(struct mail *_mail, enum mail_fetch_field field, fname = fname != NULL ? fname + 1 : path; } end = strchr(fname, MAILDIR_INFO_SEP); - mail->data.guid = end == NULL ? + mail->data.filename = end == NULL ? p_strdup(mail->data_pool, fname) : p_strdup_until(mail->data_pool, fname, end); - *value_r = mail->data.guid; + *value_r = mail->data.filename; return 0; case MAIL_FETCH_UIDL_BACKEND: uidl = maildir_uidlist_lookup_ext(mbox->uidlist, _mail->uid,