From: Aki Tuomi Date: Wed, 10 Feb 2021 11:57:08 +0000 (+0200) Subject: lib-storage: Emit "mail_opened" event when mails opened X-Git-Tag: 2.3.15~84 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c8fa10672b3259acc4cde7e3a4b9d7e2aceb0f79;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Emit "mail_opened" event when mails opened Adds a new event, "mail_opened" with "reason" as field. Also drop duplicate event in index_mail_init_stream(). --- diff --git a/src/lib-storage/index/index-mail.c b/src/lib-storage/index/index-mail.c index 847e09e6f5..6e2ba0a565 100644 --- a/src/lib-storage/index/index-mail.c +++ b/src/lib-storage/index/index-mail.c @@ -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; } diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index 6d9436d4c8..5e5dd90afd 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -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. diff --git a/src/lib-storage/mail.c b/src/lib-storage/mail.c index a7b2d8d820..61c49421cd 100644 --- a/src/lib-storage/mail.c +++ b/src/lib-storage/mail.c @@ -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"); +}