mail-log-plugin.c revision 15780ce9a9aaf06b585f43850a60b89bf1ea3e1f
5e0ce63bb65db34d7f48b34bbb5545fa791781c4Timo Sirainen/* Copyright (C) 2007 Timo Sirainen */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen *((void **)array_idx_modifiable(&(obj)->module_contexts, \
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen/* defined by imap, pop3, lda */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenextern void (*hook_mail_storage_created)(struct mail_storage *storage);
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainenconst char *mail_log_plugin_version = PACKAGE_VERSION;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstatic void (*mail_log_next_hook_mail_storage_created)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstatic unsigned int mail_log_storage_module_id = 0;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenstatic bool mail_log_storage_module_id_set = FALSE;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenstatic void mail_log_action(struct mail *mail, const char *action)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen msgid = mail_get_first_header(mail, "Message-ID");
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen i_info("%s: uid=%u, msgid=%s", action, mail->uid,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen msgid == NULL ? "(null)" : str_sanitize(msgid, MSGID_LOG_LEN));
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstatic int mail_log_mail_expunge(struct mail *_mail)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen struct mail_private *mail = (struct mail_private *)_mail;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen struct mail_log_mail *lmail = MAIL_LOG_CONTEXT(mail);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenmail_log_mail_update_flags(struct mail *_mail, enum modify_type modify_type,
e11a64ffc7f08b4cb05bcc27668d154d33d0c2e0Timo Sirainen struct mail_private *mail = (struct mail_private *)_mail;
03f5c621d06d6b6d77a145196c9633a7aa64dc78Timo Sirainen struct mail_log_mail *lmail = MAIL_LOG_CONTEXT(mail);
e11a64ffc7f08b4cb05bcc27668d154d33d0c2e0Timo Sirainen if (lmail->super.update_flags(_mail, modify_type, flags) < 0)
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen if (((old_flags ^ new_flags) & MAIL_DELETED) == 0)
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen mail_log_action(_mail, (new_flags & MAIL_DELETED) != 0 ?
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenstatic struct mail *
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenmail_log_mail_alloc(struct mailbox_transaction_context *t,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen struct mail_log_mailbox *lbox = MAIL_LOG_CONTEXT(t->box);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen _mail = lbox->super.mail_alloc(t, wanted_fields, wanted_headers);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen lmail = p_new(mail->pool, struct mail_log_mail, 1);
af81f402ddc897c74c1e85abd02879612ce44882Timo Sirainen mail->v.update_flags = mail_log_mail_update_flags;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenmail_log_copy(struct mailbox_transaction_context *t, struct mail *mail,
67c24901ac5e1521e38a91efc452faeb3e2135a1Timo Sirainen enum mail_flags flags, struct mail_keywords *keywords,
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen struct mail_log_mailbox *lbox = MAIL_LOG_CONTEXT(t->box);
67c24901ac5e1521e38a91efc452faeb3e2135a1Timo Sirainen if (lbox->super.copy(t, mail, flags, keywords, dest_mail) < 0)
67c24901ac5e1521e38a91efc452faeb3e2135a1Timo Sirainen name = str_sanitize(mailbox_get_name(t->box), MAILBOX_NAME_LOG_LEN);
67c24901ac5e1521e38a91efc452faeb3e2135a1Timo Sirainen mail_log_action(mail, t_strdup_printf("copy -> %s", name));
e11a64ffc7f08b4cb05bcc27668d154d33d0c2e0Timo Sirainenstatic struct mailbox *
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainenmail_log_mailbox_open(struct mail_storage *storage, const char *name,
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen struct istream *input, enum mailbox_open_flags flags)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen struct mail_log_mail_storage *lstorage = MAIL_LOG_CONTEXT(storage);
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen box = lstorage->super.mailbox_open(storage, name, input, flags);
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen lbox = p_new(box->pool, struct mail_log_mailbox, 1);
b3142c8e513bc78da821fa70f479016148fa95e5Timo Sirainen array_idx_set(&box->module_contexts, mail_log_storage_module_id, &lbox);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenmail_log_mailbox_delete(struct mail_storage *storage, const char *name)
b3142c8e513bc78da821fa70f479016148fa95e5Timo Sirainen struct mail_log_mail_storage *lstorage = MAIL_LOG_CONTEXT(storage);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen if (lstorage->super.mailbox_delete(storage, name) < 0)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen i_info("Mailbox deleted: %s", str_sanitize(name, MAILBOX_NAME_LOG_LEN));
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainenstatic void mail_log_mail_storage_created(struct mail_storage *storage)
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen if (mail_log_next_hook_mail_storage_created != NULL)
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen mail_log_next_hook_mail_storage_created(storage);
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen lstorage = p_new(storage->pool, struct mail_log_mail_storage, 1);
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen storage->v.mailbox_open = mail_log_mailbox_open;
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen storage->v.mailbox_delete = mail_log_mailbox_delete;
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen mail_log_storage_module_id = mail_storage_module_id++;