dovecot-2.0: mail-log: Fixed logging save/copy
dovecot at dovecot.org
dovecot at dovecot.org
Fri Jul 16 19:21:28 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/222472f295f3
changeset: 11846:222472f295f3
user: Timo Sirainen <tss at iki.fi>
date: Fri Jul 16 17:21:13 2010 +0100
description:
mail-log: Fixed logging save/copy
diffstat:
src/plugins/mail-log/mail-log-plugin.c | 58 ++++++++++++++++++++++------
1 files changed, 45 insertions(+), 13 deletions(-)
diffs (133 lines):
diff -r e827618654ec -r 222472f295f3 src/plugins/mail-log/mail-log-plugin.c
--- a/src/plugins/mail-log/mail-log-plugin.c Fri Jul 16 17:06:52 2010 +0100
+++ b/src/plugins/mail-log/mail-log-plugin.c Fri Jul 16 17:21:13 2010 +0100
@@ -38,13 +38,14 @@
MAIL_LOG_EVENT_UNDELETE = 0x02,
MAIL_LOG_EVENT_EXPUNGE = 0x04,
MAIL_LOG_EVENT_SAVE = 0x08,
- MAIL_LOG_EVENT_MAILBOX_DELETE = 0x10,
- MAIL_LOG_EVENT_MAILBOX_RENAME = 0x20,
- MAIL_LOG_EVENT_FLAG_CHANGE = 0x40
+ MAIL_LOG_EVENT_COPY = 0x10,
+ MAIL_LOG_EVENT_MAILBOX_DELETE = 0x20,
+ MAIL_LOG_EVENT_MAILBOX_RENAME = 0x40,
+ MAIL_LOG_EVENT_FLAG_CHANGE = 0x80
};
#define MAIL_LOG_DEFAULT_EVENTS \
(MAIL_LOG_EVENT_DELETE | MAIL_LOG_EVENT_UNDELETE | \
- MAIL_LOG_EVENT_EXPUNGE | MAIL_LOG_EVENT_SAVE | \
+ MAIL_LOG_EVENT_EXPUNGE | MAIL_LOG_EVENT_SAVE | MAIL_LOG_EVENT_COPY | \
MAIL_LOG_EVENT_MAILBOX_DELETE | MAIL_LOG_EVENT_MAILBOX_RENAME)
static const char *field_names[] = {
@@ -64,6 +65,7 @@
"undelete",
"expunge",
"save",
+ "copy",
"mailbox_delete",
"mailbox_rename",
"flag_change",
@@ -80,6 +82,8 @@
struct mail_log_message {
struct mail_log_message *prev, *next;
+ enum mail_log_event event;
+ bool ignore;
const char *pretext, *text;
};
@@ -217,7 +221,8 @@
str_append(text, ", ");
}
if ((muser->fields & MAIL_LOG_FIELD_UID) != 0) {
- if (event != MAIL_LOG_EVENT_SAVE)
+ if (event != MAIL_LOG_EVENT_SAVE &&
+ event != MAIL_LOG_EVENT_COPY)
mail_log_append_uid(ctx, msg, text, mail->uid);
else {
/* with mbox mail->uid contains the uid, but handle
@@ -260,10 +265,22 @@
}
str_truncate(text, str_len(text)-2);
+ msg->event = event;
msg->text = p_strdup(ctx->pool, str_c(text));
DLLIST2_APPEND(&ctx->messages, &ctx->messages_tail, msg);
}
+static void mail_log_add_dummy_msg(struct mail_log_mail_txn_context *ctx,
+ enum mail_log_event event)
+{
+ struct mail_log_message *msg;
+
+ msg = p_new(ctx->pool, struct mail_log_message, 1);
+ msg->event = event;
+ msg->ignore = TRUE;
+ DLLIST2_APPEND(&ctx->messages, &ctx->messages_tail, msg);
+}
+
static void
mail_log_append_mail_message(struct mail_log_mail_txn_context *ctx,
struct mail *mail, enum mail_log_event event,
@@ -272,8 +289,10 @@
struct mail_log_user *muser =
MAIL_LOG_USER_CONTEXT(mail->box->storage->user);
- if ((muser->events & event) == 0)
+ if ((muser->events & event) == 0) {
+ mail_log_add_dummy_msg(ctx, event);
return;
+ }
T_BEGIN {
mail_log_append_mail_message_real(ctx, mail, event, desc);
@@ -314,7 +333,7 @@
str_sanitize(mailbox_get_name(src->box),
MAILBOX_NAME_LOG_LEN));
}
- mail_log_append_mail_message(ctx, dst, MAIL_LOG_EVENT_SAVE, desc);
+ mail_log_append_mail_message(ctx, dst, MAIL_LOG_EVENT_COPY, desc);
}
static void mail_log_mail_expunge(void *txn, struct mail *mail)
@@ -357,6 +376,18 @@
"flag_change");
}
+static void mail_log_save(const struct mail_log_message *msg, uint32_t uid)
+{
+ if (msg->ignore) {
+ /* not logging this save/copy */
+ } else if (msg->pretext == NULL)
+ i_info("%s", msg->text);
+ else if (uid != 0)
+ i_info("%s%u%s", msg->pretext, uid, msg->text);
+ else
+ i_info("%serror%s", msg->pretext, msg->text);
+}
+
static void
mail_log_mail_transaction_commit(void *txn,
struct mail_transaction_commit_changes *changes)
@@ -370,13 +401,14 @@
seq_range_array_iter_init(&iter, &changes->saved_uids);
for (msg = ctx->messages; msg != NULL; msg = msg->next) {
- if (msg->pretext == NULL) {
+ if (msg->event == MAIL_LOG_EVENT_SAVE ||
+ msg->event == MAIL_LOG_EVENT_COPY) {
+ if (!seq_range_array_iter_nth(&iter, n++, &uid))
+ uid = 0;
+ mail_log_save(msg, uid);
+ } else {
+ i_assert(msg->pretext == NULL);
i_info("%s", msg->text);
- } else {
- if (seq_range_array_iter_nth(&iter, n++, &uid))
- i_info("%s%u%s", msg->pretext, uid, msg->text);
- else
- i_info("%serror%s", msg->pretext, msg->text);
}
}
i_assert(!seq_range_array_iter_nth(&iter, n, &uid));
More information about the dovecot-cvs
mailing list