dovecot-2.1: mail-log: Use mail_log_update_wanted_fields() to av...

dovecot at dovecot.org dovecot at dovecot.org
Wed Oct 12 19:00:44 EEST 2011


details:   http://hg.dovecot.org/dovecot-2.1/rev/381555875651
changeset: 13634:381555875651
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Oct 12 19:09:02 2011 +0300
description:
mail-log: Use mail_log_update_wanted_fields() to avoid parsing message multiple times.

diffstat:

 src/plugins/mail-log/mail-log-plugin.c |  33 ++++++++++++++++++++++++++++++++-
 1 files changed, 32 insertions(+), 1 deletions(-)

diffs (52 lines):

diff -r e77601949937 -r 381555875651 src/plugins/mail-log/mail-log-plugin.c
--- a/src/plugins/mail-log/mail-log-plugin.c	Wed Oct 12 19:08:31 2011 +0300
+++ b/src/plugins/mail-log/mail-log-plugin.c	Wed Oct 12 19:09:02 2011 +0300
@@ -203,6 +203,34 @@
 }
 
 static void
+mail_log_update_wanted_fields(struct mail *mail, enum mail_log_field fields)
+{
+	enum mail_fetch_field wanted_fields = 0;
+	struct mailbox_header_lookup_ctx *wanted_headers = NULL;
+	const char *headers[4];
+	unsigned int hdr_idx = 0;
+
+	if ((fields & MAIL_LOG_FIELD_MSGID) != 0)
+		headers[hdr_idx++] = "Message-ID";
+	if ((fields & MAIL_LOG_FIELD_FROM) != 0)
+		headers[hdr_idx++] = "From";
+	if ((fields & MAIL_LOG_FIELD_SUBJECT) != 0)
+		headers[hdr_idx++] = "Subject";
+	if (hdr_idx > 0) {
+		i_assert(hdr_idx < N_ELEMENTS(headers));
+		headers[hdr_idx] = NULL;
+		wanted_headers = mailbox_header_lookup_init(mail->box, headers);
+	}
+
+	if ((fields & MAIL_LOG_FIELD_PSIZE) != 0)
+		wanted_fields |= MAIL_FETCH_PHYSICAL_SIZE;
+	if ((fields & MAIL_LOG_FIELD_VSIZE) != 0)
+		wanted_fields |= MAIL_FETCH_VIRTUAL_SIZE;
+
+	mail_add_temp_wanted_fields(mail, wanted_fields, wanted_headers);
+}
+
+static void
 mail_log_append_mail_message_real(struct mail_log_mail_txn_context *ctx,
 				  struct mail *mail, enum mail_log_event event,
 				  const char *desc)
@@ -212,9 +240,12 @@
 	struct mail_log_message *msg;
 	string_t *text;
 	uoff_t size;
-	
+
 	msg = p_new(ctx->pool, struct mail_log_message, 1);
 
+	/* avoid parsing through the message multiple times */
+	mail_log_update_wanted_fields(mail, muser->fields);
+
 	text = t_str_new(128);
 	str_append(text, desc);
 	str_append(text, ": ");


More information about the dovecot-cvs mailing list