]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Emit "mail_opened" event when mails opened
authorAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 10 Feb 2021 11:57:08 +0000 (13:57 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 15 Apr 2021 07:06:27 +0000 (07:06 +0000)
Adds a new event, "mail_opened" with "reason" as field. Also drop duplicate
event in index_mail_init_stream().

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

index 847e09e6f541ad891f2800ee11980b2cbca34721..6e2ba0a5659911697dba8ad9148900c002fb46fc 100644 (file)
@@ -1311,12 +1311,6 @@ int index_mail_init_stream(struct index_mail *mail,
        bool has_nuls, body_size_from_stream = FALSE;
        int ret;
 
-       if (mail->mail.get_stream_reason != NULL &&
-           mail->mail.get_stream_reason[0] != '\0') {
-               e_debug(_mail->event,
-                       "Opened mail because: %s",
-                       mail->mail.get_stream_reason);
-       }
        _mail->mail_stream_opened = TRUE;
 
        if (!data->initialized_wrapper_stream &&
@@ -2536,9 +2530,10 @@ void index_mail_set_cache_corrupted(struct mail *mail,
        }
 }
 
-int index_mail_opened(struct mail *mail ATTR_UNUSED,
+int index_mail_opened(struct mail *mail,
                      struct istream **stream ATTR_UNUSED)
 {
+       mail_opened_event(mail);
        return 0;
 }
 
index 6d9436d4c82a4a383feb327364342ab97ec8fe56..5e5dd90afd8be99cb65b5e1379de07c48cb5c614 100644 (file)
@@ -795,6 +795,9 @@ bool mail_has_attachment_keywords(struct mail *mail);
    and 1 if attachment was found. */
 int mail_set_attachment_keywords(struct mail *mail);
 
+/* Emit mail opened events */
+void mail_opened_event(struct mail *mail);
+
 void mailbox_set_deleted(struct mailbox *box);
 int mailbox_mark_index_deleted(struct mailbox *box, bool del);
 /* Easy wrapper for getting mailbox's MAILBOX_LIST_PATH_TYPE_MAILBOX.
index a7b2d8d8206a81d68bc41aba48814cfd55c17405..61c49421cd01ca31afc6497170bd459b7a32f0a8 100644 (file)
@@ -575,3 +575,17 @@ int mail_set_attachment_keywords(struct mail *mail)
 
        return ret;
 }
+
+void mail_opened_event(struct mail *mail)
+{
+       struct mail_private *pmail =
+               container_of(mail, struct mail_private, mail);
+       struct event_passthrough *e = event_create_passthrough(mail->event)->
+               set_name("mail_opened")->
+               add_str("reason", pmail->get_stream_reason);
+       if (pmail->get_stream_reason != NULL)
+               e_debug(e->event(), "Opened mail because: %s",
+                       pmail->get_stream_reason);
+       else
+               e_debug(e->event(), "Opened mail");
+}