diff -ru -I Id: -x CVS -N dbmail/config.h dbmail.working/config.h
--- dbmail/config.h	2002-12-06 17:02:51.000000000 +1300
+++ dbmail.working/config.h	2002-12-06 17:02:15.000000000 +1300
@@ -13,6 +13,9 @@
 
 #define FIELDSIZE 1024
 #define FIELDLEN FIELDSIZE
+/* set the process titles to something useful */
+//#define PROC_TITLES
+
 typedef char field_t[FIELDSIZE];
  
 typedef struct
diff -ru -I Id: -x CVS -N dbmail/imapcommands.c dbmail.working/imapcommands.c
--- dbmail/imapcommands.c	2002-12-06 17:58:54.000000000 +1300
+++ dbmail.working/imapcommands.c	2002-12-06 17:53:36.000000000 +1300
@@ -20,6 +20,10 @@
 #include <sys/types.h>
 #include <time.h>
 #include "debug.h"
+#include "config.h"
+#ifdef PROC_TITLES
+#include "proctitleutils.h"
+#endif
 
 #ifndef MAX_LINESIZE
 #define MAX_LINESIZE 1024
@@ -176,6 +180,9 @@
   /* login ok */
   trace(TRACE_MESSAGE, "_ic_login(): user (id %llu, name %s) login accepted @ %s\r\n",
 	userid,args[0],timestr);
+#ifdef PROC_TITLES
+  set_proc_title("USER %s [%s]", args[0], ci->ip);
+#endif
 
   /* update client info */
   ud->userid = userid;
@@ -281,6 +288,9 @@
 
   trace(TRACE_MESSAGE, "IMAPD [PID %d]: user (id %llu, name %s) login accepted @ %s\r\n",(int)getpid(),
 	userid,username,timestr);
+#ifdef PROC_TITLES
+  set_proc_title("USER %s [%s]", args[0], ci->ip);
+#endif
   
   fprintf(ci->tx,"%s OK AUTHENTICATE completed\r\n",tag);
   return 0;
diff -ru -I Id: -x CVS -N dbmail/imapd.c dbmail.working/imapd.c
--- dbmail/imapd.c	2002-12-06 17:02:51.000000000 +1300
+++ dbmail.working/imapd.c	2002-12-06 17:02:00.000000000 +1300
@@ -18,6 +18,9 @@
 #include "debug.h"
 #include "misc.h"
 #include "config.h"
+#ifdef PROC_TITLES
+#include "proctitleutils.h"
+#endif
 
 #define PNAME "dbmail/imap4d"
 
@@ -41,7 +52,11 @@
 int mainStop = 0;
 
 
+#ifdef PROC_TITLES
+int main(int argc, char *argv[], char **envp)
+#else
 int main(int argc, char *argv[])
+#endif
 {
   serverConfig_t config;
   struct list imapItems, sysItems;
@@ -68,6 +83,10 @@
       mainRestart = 0;
 
       trace(TRACE_DEBUG, "main(): reading config");
+#ifdef PROC_TITLES
+      init_set_proc_title(argc, argv, envp, PNAME);
+      set_proc_title("%s", "Idle");
+#endif
 
       ReadConfig("IMAP", configFile, &imapItems);
       ReadConfig("DBMAIL", configFile, &sysItems);
diff -ru -I Id: -x CVS -N dbmail/pop3.c dbmail.working/pop3.c
--- dbmail/pop3.c	2002-12-06 17:02:51.000000000 +1300
+++ dbmail.working/pop3.c	2002-12-06 17:02:00.000000000 +1300
@@ -11,6 +11,9 @@
 #include "auth.h"
 #include "clientinfo.h"
 #include "pop3.h"
+#ifdef PROC_TITLES
+#include "proctitleutils.h"
+#endif
 
 #define INCOMING_BUFFER_SIZE 512
 #define APOP_STAMP_SIZE 255
@@ -358,6 +361,9 @@
 										trace(TRACE_MESSAGE,"pop3(): user %s logged in [messages=%llu, octets=%llu]",
 					 username, curr_session.virtual_totalmessages,
 					 curr_session.virtual_totalsize);
+#ifdef PROC_TITLES
+                    set_proc_title("USER %s [%s]", username, client_ip);
+#endif
 									}
 									return result;
 								}
@@ -640,6 +646,9 @@
 				trace(TRACE_MESSAGE,"pop3(): user %s logged in [messages=%llu, octets=%llu]",
 			 username, curr_session.virtual_totalmessages,
 			 curr_session.virtual_totalsize);
+#ifdef PROC_TITLES
+        set_proc_title("USER %s [%s]", username, client_ip);
+#endif
 			}
 			return result;
 		}
diff -ru -I Id: -x CVS -N dbmail/pop3d.c dbmail.working/pop3d.c
--- dbmail/pop3d.c	2002-12-06 17:02:51.000000000 +1300
+++ dbmail.working/pop3d.c	2002-12-06 17:02:00.000000000 +1300
@@ -20,6 +20,9 @@
 #include "config.h"
 #include "clientinfo.h"
 #include "pop3.h"
+#ifdef PROC_TITLES
+#include "proctitleutils.h"
+#endif
 
 
 #define PNAME "dbmail/pop3d"
@@ -55,7 +66,11 @@
 char *apop_stamp;
 char *timeout_setting;
 
+#ifdef PROC_TITLES
+int main(int argc, char *argv[], char **envp)
+#else
 int main(int argc, char *argv[])
+#endif
 {
 	serverConfig_t config;
 	struct list popItems, sysItems;
@@ -82,6 +97,10 @@
       mainRestart = 0;
 
       trace(TRACE_DEBUG, "main(): reading config");
+#ifdef PROC_TITLES
+      init_set_proc_title(argc, argv, envp, PNAME);
+      set_proc_title("%s", "Idle");
+#endif
 
       ReadConfig("POP", configFile, &popItems);
       ReadConfig("DBMAIL", configFile, &sysItems);
diff -ru -I Id: -x CVS -N dbmail/proctitleutils.c dbmail.working/proctitleutils.c
--- dbmail/proctitleutils.c	1970-01-01 12:00:00.000000000 +1200
+++ dbmail.working/proctitleutils.c	2002-12-06 16:01:29.000000000 +1300
@@ -0,0 +1,73 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdarg.h>
+#include <malloc.h>
+#include "proctitleutils.h"
+
+/* Globals */
+static char **Argv = ((void *)0);
+static char *LastArgv = ((void *)0);
+static int start = 0;
+
+void init_set_proc_title(int argc, char *argv[], char *envp[], const char *name)
+{
+  int i, envpsize;
+  extern char **environ;
+  char **p;
+  char *ptr;
+
+  for(i = envpsize = 0; envp[i] != NULL; i++)
+    envpsize += strlen(envp[i]) + 1;
+  
+  if((p = (char **) malloc((i + 1) * sizeof(char *))) != NULL ) {
+    environ = p;
+
+    for(i = 0; envp[i] != NULL; i++) {
+      if((environ[i] = malloc(strlen(envp[i]) + 1)) != NULL)
+      strcpy(environ[i], envp[i]);
+    }
+    
+    environ[i] = NULL;
+  }
+
+  Argv = argv;
+    
+  for(i = 0; envp[i] != NULL; i++) {
+    if((LastArgv + 1) == envp[i]) // Not sure if this conditional is needed
+      LastArgv = envp[i] + strlen(envp[i]);
+  }
+
+  // Clear the title (from the start of argv to the start of envp)
+  // All command line arguments should have been taken care of by now...
+  for(ptr=Argv[0]; ptr<envp[0]; ptr++)
+    *ptr='\0';
+    
+  set_proc_title("%s : ", name);
+  start=strlen(name)+3;
+}
+
+void set_proc_title(char *fmt,...)
+{
+  va_list msg;
+  static char statbuf[8192];
+  char *p = Argv[0];
+  int maxlen = (LastArgv - Argv[0]) - 2;
+
+  // Clear old Argv[0]
+  for(p+=start;*p; p++)
+    *p='\0';
+   
+  va_start(msg,fmt);
+
+  memset(statbuf, 0, sizeof(statbuf));
+  vsnprintf(statbuf, sizeof(statbuf), fmt, msg);
+
+  va_end(msg);
+
+  snprintf(Argv[0]+start, maxlen, "%s", statbuf);
+  
+  Argv[1] = ((void *)0) ;
+}
+
+
diff -ru -I Id: -x CVS -N dbmail/proctitleutils.h dbmail.working/proctitleutils.h
--- dbmail/proctitleutils.h	1970-01-01 12:00:00.000000000 +1200
+++ dbmail.working/proctitleutils.h	2002-12-06 15:52:33.000000000 +1300
@@ -0,0 +1,8 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdarg.h>
+#include <malloc.h>
+
+void set_proc_title(char *fmt,...);
+void init_set_proc_title(int argc, char *argv[], char *envp[], const char *name);
diff -ru -I Id: -x CVS -N dbmail/serverchild.c dbmail.working/serverchild.c
--- dbmail/serverchild.c	2002-12-06 17:02:51.000000000 +1300
+++ dbmail.working/serverchild.c	2002-12-06 16:07:48.000000000 +1300
@@ -25,6 +25,9 @@
 #include <arpa/inet.h>
 #include <netdb.h>
 #include <signal.h>
+#ifdef PROC_TITLES
+#include "proctitleutils.h"
+#endif
 
 int ChildStopRequested = 0;
 int connected = 0;
@@ -305,6 +308,9 @@
       
       /* streams are ready, perform handling */
       info->ClientHandler(&client);
+#ifdef PROC_TITLES
+      set_proc_title("%s", "Idle");
+#endif
 
       trace(TRACE_DEBUG, "PerformChildTask(): client handling complete, closing streams");
 
