]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
maildir: Remember the mail's GUID/filename in memory once it's fetched once.
authorTimo Sirainen <tss@iki.fi>
Wed, 4 Apr 2012 02:34:11 +0000 (05:34 +0300)
committerTimo Sirainen <tss@iki.fi>
Wed, 4 Apr 2012 02:34:11 +0000 (05:34 +0300)
This allows retrieving it later even if the message gets expunged.

src/lib-storage/index/index-mail.h
src/lib-storage/index/maildir/maildir-mail.c

index 869dff9e70f51d69cee3427e20f04bf9779b18ed..69a99404dd628d78eb83b5262cb92c578df4b5ea 100644 (file)
@@ -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;
 
index 8a6674b4d4d1cfe768d214e50f3bac8e8b36b852..16a3a0b071f28f8ea5827246937dd7cd1ae586c6 100644 (file)
@@ -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,