From: Timo Sirainen Date: Sun, 14 Dec 2008 05:29:45 +0000 (+0200) Subject: mail-log plugin: Added from and subject fields. X-Git-Tag: 1.2.alpha5~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=39afc7584d935b2dc7332c21966a7b20da03f1ec;p=thirdparty%2Fdovecot%2Fcore.git mail-log plugin: Added from and subject fields. --HG-- branch : HEAD --- diff --git a/dovecot-example.conf b/dovecot-example.conf index ab5d28a66b..4b95509ba1 100644 --- a/dovecot-example.conf +++ b/dovecot-example.conf @@ -1189,7 +1189,7 @@ plugin { #mail_log_events = delete undelete expunge copy mailbox_delete mailbox_rename # Group events within a transaction to one line. #mail_log_group_events = - # Available fields: uid, box, msgid, size, vsize, flags + # Available fields: uid, box, msgid, from, subject, size, vsize, flags # size and vsize are available only for expunge and copy events. #mail_log_fields = uid box msgid size } diff --git a/src/plugins/mail-log/mail-log-plugin.c b/src/plugins/mail-log/mail-log-plugin.c index c947f8193a..7f25fd0d75 100644 --- a/src/plugins/mail-log/mail-log-plugin.c +++ b/src/plugins/mail-log/mail-log-plugin.c @@ -12,7 +12,7 @@ #include #define MAILBOX_NAME_LOG_LEN 64 -#define MSGID_LOG_LEN 80 +#define HEADER_LOG_LEN 80 #define MAIL_LOG_CONTEXT(obj) \ MODULE_CONTEXT(obj, mail_log_storage_module) @@ -27,7 +27,9 @@ enum mail_log_field { MAIL_LOG_FIELD_MSGID = 0x04, MAIL_LOG_FIELD_PSIZE = 0x08, MAIL_LOG_FIELD_VSIZE = 0x10, - MAIL_LOG_FIELD_FLAGS = 0x20 + MAIL_LOG_FIELD_FLAGS = 0x20, + MAIL_LOG_FIELD_FROM = 0x40, + MAIL_LOG_FIELD_SUBJECT = 0x80 }; #define MAIL_LOG_DEFAULT_FIELDS \ (MAIL_LOG_FIELD_UID | MAIL_LOG_FIELD_BOX | \ @@ -56,6 +58,8 @@ static const char *field_names[] = { "size", "vsize", "flags", + "from", + "subject", NULL }; @@ -264,12 +268,21 @@ mail_log_group_changes(struct mailbox *box, } } +static void mail_log_add_hdr(struct mail *mail, string_t *str, + const char *name, const char *header) +{ + const char *value; + + if (mail_get_first_header(mail, header, &value) <= 0) + value = ""; + str_printfa(str, "%s=%s, ", name, str_sanitize(value, HEADER_LOG_LEN)); +} + static void mail_log_action(struct mailbox_transaction_context *dest_trans, struct mail *mail, enum mail_log_event event, const char *data) { struct mail_log_transaction_context *lt = MAIL_LOG_CONTEXT(dest_trans); - const char *msgid; uoff_t size; string_t *str; pool_t pool; @@ -307,12 +320,12 @@ static void mail_log_action(struct mailbox_transaction_context *dest_trans, if (event == MAIL_LOG_EVENT_COPY) str_printfa(str, "dest=%s, ", data); - if ((mail_log_set.fields & MAIL_LOG_FIELD_MSGID) != 0) { - if (mail_get_first_header(mail, "Message-ID", &msgid) <= 0) - msgid = "(null)"; - str_printfa(str, "msgid=%s, ", - str_sanitize(msgid, MSGID_LOG_LEN)); - } + if ((mail_log_set.fields & MAIL_LOG_FIELD_MSGID) != 0) + mail_log_add_hdr(mail, str, "msgid", "Message-ID"); + if ((mail_log_set.fields & MAIL_LOG_FIELD_FROM) != 0) + mail_log_add_hdr(mail, str, "from", "From"); + if ((mail_log_set.fields & MAIL_LOG_FIELD_SUBJECT) != 0) + mail_log_add_hdr(mail, str, "subject", "Subject"); if ((mail_log_set.fields & MAIL_LOG_FIELD_PSIZE) != 0 && (event & (MAIL_LOG_EVENT_EXPUNGE | MAIL_LOG_EVENT_COPY)) != 0) {