]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Send mail_opened event only once per mail
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 26 Sep 2025 11:39:51 +0000 (14:39 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Mon, 29 Sep 2025 16:49:57 +0000 (16:49 +0000)
The first time mail is opened it is read into cache, while the following
reads are likely to be using the cache. Sending a mail_opened event for the
following reads just confuses statistics.

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

index 70060ba4f75aaf37b0f62efcb0071444f1ab4244..a8a2faebe87189718e147f1d422bdc280fdd0cbc 100644 (file)
@@ -1878,6 +1878,7 @@ static void index_mail_reset_data(struct index_mail *mail)
        mail->mail.mail.seq = 0;
        mail->mail.mail.uid = 0;
        mail->mail.seq_pvt = 0;
+       mail->mail.mail_opened_event_sent = FALSE;
        mail->mail.mail.expunged = FALSE;
        mail->mail.mail.has_nuls = FALSE;
        mail->mail.mail.has_no_nuls = FALSE;
index eaeb2020138ddecf7a46200d6cac4a74ba27d506..813ab6cfd28429835e0e3938528b1012d98b589d 100644 (file)
@@ -610,6 +610,8 @@ struct mail_private {
        bool autoexpunged:1;
        /* mail created by mailbox_search_*() */
        bool search_mail:1;
+       /* mail_opened event has been sent for this mail/seq */
+       bool mail_opened_event_sent:1;
 };
 
 struct mailbox_list_context {
index 8bd4e83e93ca8060fd70f718a501dc291835a4c8..74f1e1a489cf6c835ae8a203ffaf77e9e4351883 100644 (file)
@@ -708,6 +708,14 @@ void mail_opened_event(struct mail *mail)
 {
        struct mail_private *pmail =
                container_of(mail, struct mail_private, mail);
+
+       /* If istream is opened twice for the same mail, count it as a single
+          mail_opened event. Their cost is effectively the same, so having
+          two events would just be confusing the statistics. */
+       if (pmail->mail_opened_event_sent)
+               return;
+       pmail->mail_opened_event_sent = TRUE;
+
        struct event_passthrough *e =
                event_create_passthrough(mail_event(mail))->
                set_name("mail_opened")->