[Patch] mail_log plugin supports remote, local ip addresses

Vitaliy T vitaliy.tokarev at gmail.com
Tue Aug 5 12:07:36 UTC 2014


Hello,

In attached file you will find patch for mail_log plugin to output
local, remote ip addresses. It may be usefull for somebody.

To enable support for dovecot 2.2.x versions change the line 'include
"net.h"' instead of 'include "network.h"'.


Thank you.

P.S. Sorry, for previous empty message.

-- 
With Best Regards,
Vitaliy T.
-------------- next part --------------
--- src/plugins/mail-log/mail-log-plugin.c.orig	2014-08-05 13:12:21.000000000 +0400
+++ src/plugins/mail-log/mail-log-plugin.c	2014-08-05 13:15:30.000000000 +0400
@@ -13,6 +13,8 @@
 
 #include <stdlib.h>
 
+#include "network.h"
+
 #define MAILBOX_NAME_LOG_LEN 64
 #define HEADER_LOG_LEN 80
 
@@ -27,7 +29,9 @@
 	MAIL_LOG_FIELD_VSIZE	= 0x10,
 	MAIL_LOG_FIELD_FLAGS	= 0x20,
 	MAIL_LOG_FIELD_FROM	= 0x40,
-	MAIL_LOG_FIELD_SUBJECT	= 0x80
+	MAIL_LOG_FIELD_SUBJECT	= 0x80,
+	MAIL_LOG_FIELD_REMOTE_IP = 0x100,
+	MAIL_LOG_FIELD_LOCAL_IP	= 0x200
 };
 #define MAIL_LOG_DEFAULT_FIELDS \
 	(MAIL_LOG_FIELD_UID | MAIL_LOG_FIELD_BOX | \
@@ -58,6 +62,8 @@
 	"flags",
 	"from",
 	"subject",
+	"rip",
+	"lip",
 	NULL
 };
 
@@ -265,6 +271,14 @@
 				 mail_get_keywords(mail));
 		str_append(text, "), ");
 	}
+	if ((muser->fields & MAIL_LOG_FIELD_REMOTE_IP) != 0) {
+		str_printfa(text, "rip=%s", net_ip2addr(mail->box->storage->user->remote_ip));
+		str_append(text, ", ");
+	}
+	if ((muser->fields & MAIL_LOG_FIELD_LOCAL_IP) != 0) {
+		str_printfa(text, "lip=%s", net_ip2addr(mail->box->storage->user->local_ip));
+		str_append(text, ", ");
+	}
 	str_truncate(text, str_len(text)-2);
 
 	msg->event = event;


More information about the dovecot mailing list