From 43c7869f8707c43b219f886b26fdbada6935ae69 Mon Sep 17 00:00:00 2001
From: Bron Gondwana <brong@fastmail.fm>
Date: Wed, 24 Dec 2008 23:26:29 +1100
Subject: [PATCH] statistics for pop3 connections

Log statistics on the number of retr, top and dele commands run during
a pop3 session (XXX: config option?)

===================================================================
---
 imap/pop3d.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/imap/pop3d.c b/imap/pop3d.c
index db86d84..c597c03 100644
--- a/imap/pop3d.c
+++ b/imap/pop3d.c
@@ -125,6 +125,9 @@ struct protstream *popd_in = NULL;
 static int popd_logfd = -1;
 unsigned popd_exists = 0;
 unsigned popd_login_time;
+int count_retr = 0;
+int count_top = 0;
+int count_dele = 0;
 struct msg {
     unsigned uid;
     unsigned size;
@@ -316,6 +319,12 @@ static void popd_reset(void)
 {
     proc_cleanup();
 
+    syslog(LOG_NOTICE, "counts: retr=<%d> top=<%d> dele=<%d>",
+                       count_retr, count_top, count_dele);
+    count_retr = 0;
+    count_top = 0;
+    count_dele = 0;
+
     /* close local mailbox */
     if (popd_mailbox) {
 	mailbox_close(popd_mailbox);
@@ -477,6 +486,10 @@ int service_main(int argc __attribute__((unused)),
     popd_in = prot_new(0, 0);
     popd_out = prot_new(1, 1);
 
+    count_retr = 0;
+    count_top = 0;
+    count_dele = 0;
+
     /* Find out name of client host */
     salen = sizeof(popd_remoteaddr);
     if (getpeername(0, (struct sockaddr *)&popd_remoteaddr, &salen) == 0 &&
@@ -608,6 +621,9 @@ void shut_down(int code)
 	free(backend);
     }
 
+    syslog(LOG_NOTICE, "counts: retr=<%d> top=<%d> dele=<%d>",
+                       count_retr, count_top, count_dele);
+
     mboxlist_close();
     mboxlist_done();
 
@@ -942,6 +958,7 @@ static void cmdloop(void)
 		}
 		else {
 		    blat(msg, -1);
+		    count_retr++;
 		}
 	    }
 	}
@@ -963,6 +980,7 @@ static void cmdloop(void)
 		else {
 		    popd_msg[msg].deleted = 1;
 		    prot_printf(popd_out, "+OK message deleted\r\n");
+		    count_dele++;
 		}
 	    }
 	}
@@ -1004,6 +1022,7 @@ static void cmdloop(void)
 		}
 		else {
 		    blat(msg, lines);
+		    count_top++;
 		}
 	    }
 	}
-- 
1.5.6.5

