]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Make sure mail event is created before accessing streams or metadata
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 29 Nov 2021 14:43:29 +0000 (15:43 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 21 Dec 2021 10:06:58 +0000 (10:06 +0000)
This is in preparation for the next commit which delays the mail event
creation. The event duration behaves better if the event is created before
any potentially slow access is done.

src/lib-storage/mail-storage-private.h
src/lib-storage/mail.c

index a809b44ad370b2a39ff571469ea3701348bb3e1c..f5f569c36e94fc364e3752b6bc3dca8abd385baf 100644 (file)
@@ -814,6 +814,7 @@ void mail_set_mail_cache_corrupted(struct mail *mail, const char *fmt, ...)
 /* Indicate mail being expunged by autoexpunge */
 void mail_autoexpunge(struct mail *mail);
 
+void mail_event_create(struct mail *mail);
 /* Returns TRUE if everything should already be in memory after this call
    or if prefetching is not supported, i.e. the caller shouldn't do more
    prefetching before this message is handled. */
index 720349fc8ec095f3490229d37e4e4d04828e4a9c..366670330a24a7e8adcb3c602f73fa055cb7e572 100644 (file)
@@ -99,6 +99,13 @@ void mail_add_temp_wanted_fields(struct mail *mail,
        p->v.add_temp_wanted_fields(mail, fields, headers);
 }
 
+void mail_event_create(struct mail *mail)
+{
+       struct mail_private *p = (struct mail_private *)mail;
+
+       i_assert(p->_event != NULL);
+}
+
 struct event *mail_event(struct mail *mail)
 {
        struct mail_private *p = (struct mail_private *)mail;
@@ -653,6 +660,7 @@ bool mail_stream_access_start(struct mail *mail)
                return FALSE;
        }
        mail->mail_stream_accessed = TRUE;
+       mail_event_create(mail);
        return TRUE;
 }
 
@@ -663,6 +671,7 @@ bool mail_metadata_access_start(struct mail *mail)
                return FALSE;
        }
        mail->mail_metadata_accessed = TRUE;
+       mail_event_create(mail);
        return TRUE;
 }