]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
maildir: Fixed a race condition in getting a new message's GUID.
authorTimo Sirainen <tss@iki.fi>
Thu, 23 Sep 2010 17:18:51 +0000 (18:18 +0100)
committerTimo Sirainen <tss@iki.fi>
Thu, 23 Sep 2010 17:18:51 +0000 (18:18 +0100)
src/lib-storage/index/maildir/maildir-mail.c

index 366774c0bf8f864a5d9b6d1f349eae421905f246..8742cc310275353bb15827dc26bf512418cd174b 100644 (file)
@@ -469,11 +469,17 @@ maildir_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
 {
        struct index_mail *mail = (struct index_mail *)_mail;
        struct maildir_mailbox *mbox = (struct maildir_mailbox *)_mail->box;
-       const char *path, *fname, *end, *guid, *uidl;
+       const char *path, *fname = NULL, *end, *guid, *uidl;
 
        switch (field) {
        case MAIL_FETCH_GUID:
                /* use GUID from uidlist if it exists */
+               i_assert(!_mail->saving);
+
+               /* first make sure that we have a refreshed uidlist */
+               if (maildir_mail_get_fname(mbox, _mail, &fname) <= 0)
+                       return -1;
+
                guid = maildir_uidlist_lookup_ext(mbox->uidlist, _mail->uid,
                                                  MAILDIR_UIDLIST_REC_EXT_GUID);
                if (guid != NULL) {
@@ -487,7 +493,10 @@ maildir_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
                        *value_r = mail->data.guid;
                        return 0;
                }
-               if (!_mail->saving) {
+               if (fname != NULL) {
+                       /* we came here from MAIL_FETCH_GUID,
+                          avoid a second lookup */
+               } else if (!_mail->saving) {
                        if (maildir_mail_get_fname(mbox, _mail, &fname) <= 0)
                                return -1;
                } else {