]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Add mail.event
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 21 Nov 2017 11:59:40 +0000 (12:59 +0100)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 13 Dec 2017 11:22:17 +0000 (13:22 +0200)
src/lib-storage/index/index-mail.c
src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.c
src/lib-storage/mail-storage.h

index e6f73b12cf9212fafc691442d0368d3b6c9692fa..a8883bee678c0220842abdfc24ff241405c5c3a4 100644 (file)
@@ -1565,6 +1565,12 @@ index_mail_alloc(struct mailbox_transaction_context *t,
        return &mail->mail.mail;
 }
 
+static void index_mail_init_event(struct mail *mail)
+{
+       mail->event = event_create(mail->box->event);
+       event_add_category(mail->event, &event_category_mail);
+}
+
 void index_mail_init(struct index_mail *mail,
                     struct mailbox_transaction_context *t,
                     enum mail_fetch_field wanted_fields,
@@ -1576,6 +1582,7 @@ void index_mail_init(struct index_mail *mail,
        mail->mail.v = *t->box->mail_vfuncs;
        mail->mail.mail.box = t->box;
        mail->mail.mail.transaction = t;
+       index_mail_init_event(&mail->mail.mail);
        t->mail_ref_count++;
        mail->mail.data_pool = pool_alloconly_create("index_mail", 16384);
        mail->ibox = INDEX_STORAGE_CONTEXT(t->box);
@@ -1682,6 +1689,11 @@ void index_mail_close(struct mail *_mail)
                return;
        }
 
+       /* make sure old mail isn't visible in the event anymore even if it's
+          attempted to be used. */
+       event_unref(&_mail->event);
+       index_mail_init_event(&mail->mail.mail);
+
        /* If uid == 0 but seq != 0, we came here from saving a (non-mbox)
           message. If that happens, don't bother checking if anything should
           be cached since it was already checked. Also by now the transaction
@@ -1904,6 +1916,11 @@ void index_mail_set_seq(struct mail *_mail, uint32_t seq, bool saving)
        mail_index_lookup_uid(_mail->transaction->view, seq,
                              &mail->mail.mail.uid);
 
+       event_add_int(_mail->event, "seq", _mail->seq);
+       event_add_int(_mail->event, "uid", _mail->uid);
+       event_set_append_log_prefix(_mail->event, t_strdup_printf(
+               "%sUID %u: ", saving ? "saving " : "", _mail->uid));
+
        if (mail_index_view_is_inconsistent(_mail->transaction->view)) {
                mail_set_expunged(&mail->mail.mail);
                return;
@@ -2055,6 +2072,7 @@ void index_mail_free(struct mail *_mail)
 
        if (headers_ctx != NULL)
                mailbox_header_lookup_unref(&headers_ctx);
+       event_unref(&_mail->event);
        pool_unref(&mail->mail.data_pool);
        pool_unref(&mail->mail.pool);
 }
index e6c641d387b5dc57f728821afbfb71c3952e8e9b..6a7e37c2fe1f70b3d49085c22e9913b611a5cfd1 100644 (file)
@@ -730,6 +730,7 @@ extern struct mail_module_register mail_module_register;
 
 extern struct event_category event_category_storage;
 extern struct event_category event_category_mailbox;
+extern struct event_category event_category_mail;
 
 #define MAIL_STORAGE_CONTEXT(obj) \
        MODULE_CONTEXT(obj, mail_storage_mail_index_module)
index d990ff7800fc23716c99b67d1705f2e8415435b1..30968e7445cbdd7a90e8f3a4f300d78ceefbc0b6 100644 (file)
@@ -47,6 +47,10 @@ struct event_category event_category_mailbox = {
        .parent = &event_category_storage,
        .name = "mailbox",
 };
+struct event_category event_category_mail = {
+       .parent = &event_category_mailbox,
+       .name = "mail",
+};
 
 struct mail_storage_module_register mail_storage_module_register = { 0 };
 struct mail_module_register mail_module_register = { 0 };
index 179aa5e347a363d5ce09dd62f2c20ba8b408d1c4..08d1ea376de75ad73773eb3a2e5972e0a967aeeb 100644 (file)
@@ -388,6 +388,7 @@ struct mail {
        /* always set */
        struct mailbox *box;
        struct mailbox_transaction_context *transaction;
+       struct event *event;
        uint32_t seq, uid;
 
        bool expunged:1;