mail-log-plugin.c revision 6deb39ab9145dd6b01d7ecb99f2526b53b3172bf
/* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "llist.h"
#include "str.h"
#include "str-sanitize.h"
#include "imap-util.h"
#include "mail-user.h"
#include "mail-storage-private.h"
#include "notify-plugin.h"
#include "mail-log-plugin.h"
#define MAILBOX_NAME_LOG_LEN 64
#define HEADER_LOG_LEN 80
#define MAIL_LOG_USER_CONTEXT(obj) \
enum mail_log_field {
MAIL_LOG_FIELD_UID = 0x01,
MAIL_LOG_FIELD_BOX = 0x02,
MAIL_LOG_FIELD_MSGID = 0x04,
MAIL_LOG_FIELD_PSIZE = 0x08,
MAIL_LOG_FIELD_VSIZE = 0x10,
MAIL_LOG_FIELD_FLAGS = 0x20,
MAIL_LOG_FIELD_FROM = 0x40,
MAIL_LOG_FIELD_SUBJECT = 0x80
};
#define MAIL_LOG_DEFAULT_FIELDS \
enum mail_log_event {
MAIL_LOG_EVENT_DELETE = 0x01,
MAIL_LOG_EVENT_UNDELETE = 0x02,
MAIL_LOG_EVENT_EXPUNGE = 0x04,
MAIL_LOG_EVENT_SAVE = 0x08,
MAIL_LOG_EVENT_COPY = 0x10,
MAIL_LOG_EVENT_MAILBOX_CREATE = 0x20,
MAIL_LOG_EVENT_MAILBOX_DELETE = 0x40,
MAIL_LOG_EVENT_MAILBOX_RENAME = 0x80,
MAIL_LOG_EVENT_FLAG_CHANGE = 0x100
};
#define MAIL_LOG_DEFAULT_EVENTS \
static const char *field_names[] = {
"uid",
"box",
"msgid",
"size",
"vsize",
"flags",
"from",
"subject",
};
static const char *event_names[] = {
"delete",
"undelete",
"expunge",
"save",
"copy",
"mailbox_create",
"mailbox_delete",
"mailbox_rename",
"flag_change",
};
struct mail_log_user {
enum mail_log_field fields;
enum mail_log_event events;
bool cached_only;
};
struct mail_log_message {
enum mail_log_event event;
bool ignore;
};
struct mail_log_mail_txn_context {
};
{
unsigned int i;
for (i = 0; field_names[i] != NULL; i++) {
return 1 << i;
}
return 0;
}
{
unsigned int i;
/* v1.x backwards compatibility */
name = "save";
}
for (i = 0; event_names[i] != NULL; i++) {
return 1 << i;
}
return 0;
}
{
const char *const *tmp;
if (field == 0)
}
return fields;
}
{
const char *const *tmp;
if (event == 0)
}
return events;
}
{
struct mail_log_user *muser;
const char *str;
muser->cached_only =
}
{
const char *mailbox_str;
}
static void
{
const char *value;
value = "";
}
static void
{
if (uid != 0)
else {
/* we don't know the uid yet, assign it later */
str_truncate(str, 0);
}
}
static void
{
enum mail_fetch_field wanted_fields = 0;
const char *headers[4];
unsigned int hdr_idx = 0;
if ((fields & MAIL_LOG_FIELD_MSGID) != 0)
if ((fields & MAIL_LOG_FIELD_FROM) != 0)
if ((fields & MAIL_LOG_FIELD_SUBJECT) != 0)
if (hdr_idx > 0) {
}
if ((fields & MAIL_LOG_FIELD_PSIZE) != 0)
if ((fields & MAIL_LOG_FIELD_VSIZE) != 0)
if (wanted_headers != NULL)
}
static void
const char *desc)
{
struct mail_log_user *muser =
struct mail_log_message *msg;
/* avoid parsing through the message multiple times */
}
if (event != MAIL_LOG_EVENT_SAVE &&
else {
/* with mbox mail->uid contains the uid, but handle
this consistently with all mailbox formats */
}
/* make sure UID is assigned to this mail */
}
}
else
}
else
}
}
}
}
}
enum mail_log_event event)
{
struct mail_log_message *msg;
}
static void
const char *desc)
{
struct mail_log_user *muser =
if (event == MAIL_LOG_EVENT_SAVE ||
return;
}
T_BEGIN {
} T_END;
}
static void *
{
struct mail_log_mail_txn_context *ctx;
return ctx;
}
{
struct mail_log_mail_txn_context *ctx =
(struct mail_log_mail_txn_context *)txn;
}
{
struct mail_log_mail_txn_context *ctx =
(struct mail_log_mail_txn_context *)txn;
const char *desc;
/* copying a mail from virtual storage. src points to the
backend mail, but we want to log the virtual mailbox name. */
}
}
{
struct mail_log_mail_txn_context *ctx =
(struct mail_log_mail_txn_context *)txn;
}
enum mail_flags old_flags)
{
struct mail_log_mail_txn_context *ctx =
(struct mail_log_mail_txn_context *)txn;
"flag_change");
} else if ((old_flags & MAIL_DELETED) == 0) {
"delete");
} else {
"undelete");
}
}
static void
const char *const *old_keywords ATTR_UNUSED)
{
struct mail_log_mail_txn_context *ctx =
(struct mail_log_mail_txn_context *)txn;
"flag_change");
}
{
else if (uid != 0)
else
}
static void
struct mail_transaction_commit_changes *changes)
{
struct mail_log_mail_txn_context *ctx =
(struct mail_log_mail_txn_context *)txn;
struct mail_log_message *msg;
struct seq_range_iter iter;
unsigned int n = 0;
uid = 0;
} else {
}
}
}
static void mail_log_mail_transaction_rollback(void *txn)
{
struct mail_log_mail_txn_context *ctx =
(struct mail_log_mail_txn_context *)txn;
}
static void
{
return;
i_info("Mailbox created: %s",
}
static void
{
return;
i_info("Mailbox deleted: %s",
}
static void
{
return;
i_info("Mailbox renamed: %s -> %s",
}
static const struct notify_vfuncs mail_log_vfuncs = {
};
static struct notify_context *mail_log_ctx;
static struct mail_storage_hooks mail_log_mail_storage_hooks = {
};
{
}
void mail_log_plugin_deinit(void)
{
}