This might be useful to someone so I'll throw it out there.

Patch against 1.0.5 adds support for two new configuration params:

pop3_debug_client_commands = TOP, RETR, DELE
imap_debug_client_commands = FETCH, DELETE

Obviously add in whichever ones you're interested in, or none, or
comment them out completely.

It'll log the appropriate events:

Oct 12 18:30:18 kea dovecot: IMAP(zach): Client command: FETCH

The parameters are included for POP3 events. Wasn't sure quite how to do
the same for IMAP and for my purposes it's not too important so imap
command parameters aren't logged.

Running smoothly here with a few dozen IMAP and POP3 users. Not
suggesting this gets added to the codebase - I just needed it to help
debug some other IMAP software and thought it might be useful.

Zach.
diff -ur dovecot-1.0.5/src/imap/client.c dovecot-1.0.5-debugcmd/src/imap/client.c
--- dovecot-1.0.5/src/imap/client.c2007-08-25 04:35:29.000000000 +1200
+++ dovecot-1.0.5-debugcmd/src/imap/client.c2007-10-11 11:54:22.000000000 +1300
@@ -13,6 +13,8 @@
extern struct mail_storage_callbacks mail_storage_callbacks;
+char **imap_debug_client_commands_arr;
+
static struct client *my_client; /* we don't need more than one currently */
static struct timeout *to_idle;
@@ -21,6 +23,10 @@
{
struct client *client;
+imap_debug_client_commands_arr = NULL;
+if (getenv("IMAP_DEBUG_CLIENT_COMMANDS") != NULL)
+imap_debug_client_commands_arr = t_strsplit_spaces(getenv("IMAP_DEBUG_CLIENT_COMMANDS"), ", ");
+
/* always use nonblocking I/O */
net_set_nonblock(fd_in, TRUE);
net_set_nonblock(fd_out, TRUE);
@@ -337,6 +343,8 @@
static bool client_handle_input(struct client_command_context *cmd)
{
+int i;
+
struct client *client = cmd->client;
if (cmd->func != NULL) {
@@ -385,6 +393,15 @@
} else {
/* find the command function */
cmd->func = command_find(cmd->name);
+
+if (imap_debug_client_commands_arr != NULL) {
+for (i = 0; imap_debug_client_commands_arr[i] != NULL; i++) {
+if (strcasecmp(cmd->name, imap_debug_client_commands_arr[i]) == 0) {
+i_info("Client command: %s", cmd->name);
+break;
+}
+}
+}
}
client->input_skip_line = TRUE;
diff -ur dovecot-1.0.5/src/master/mail-process.c dovecot-1.0.5-debugcmd/src/master/mail-process.c
--- dovecot-1.0.5/src/master/mail-process.c2007-07-21 19:02:34.000000000 +1200
+++ dovecot-1.0.5-debugcmd/src/master/mail-process.c2007-10-11 11:54:22.000000000 +1300
@@ -252,6 +252,10 @@
env_put("MAILDIR_COPY_PRESERVE_FILENAME=1");
if (set->mail_debug)
env_put("DEBUG=1");
+if (*set->pop3_debug_client_commands != '\0')
+env_put(t_strconcat("POP3_DEBUG_CLIENT_COMMANDS=", set->pop3_debug_client_commands, NULL));
+if (*set->imap_debug_client_commands != '\0')
+env_put(t_strconcat("IMAP_DEBUG_CLIENT_COMMANDS=", set->imap_debug_client_commands, NULL));
if (set->mail_full_filesystem_access)
env_put("FULL_FILESYSTEM_ACCESS=1");
if (set->pop3_no_flag_updates)
diff -ur dovecot-1.0.5/src/master/master-settings-defs.c dovecot-1.0.5-debugcmd/src/master/master-settings-defs.c
--- dovecot-1.0.5/src/master/master-settings-defs.c2007-07-16 07:51:07.000000000 +1200
+++ dovecot-1.0.5-debugcmd/src/master/master-settings-defs.c2007-10-11 11:54:22.000000000 +1300
@@ -66,6 +66,8 @@
DEF(SET_INT, mail_cache_min_mail_count),
DEF(SET_INT, mailbox_idle_check_interval),
DEF(SET_BOOL, mail_debug),
+DEF(SET_STR, pop3_debug_client_commands),
+DEF(SET_STR, imap_debug_client_commands),
DEF(SET_BOOL, mail_full_filesystem_access),
DEF(SET_INT, mail_max_keyword_length),
DEF(SET_BOOL, mail_save_crlf),
diff -ur dovecot-1.0.5/src/master/master-settings.c dovecot-1.0.5-debugcmd/src/master/master-settings.c
--- dovecot-1.0.5/src/master/master-settings.c2007-07-16 07:51:07.000000000 +1200
+++ dovecot-1.0.5-debugcmd/src/master/master-settings.c2007-10-11 11:54:22.000000000 +1300
@@ -215,6 +215,8 @@
MEMBER(mail_cache_min_mail_count) 0,
MEMBER(mailbox_idle_check_interval) 30,
MEMBER(mail_debug) FALSE,
+MEMBER(pop3_debug_client_commands) "",
+MEMBER(imap_debug_client_commands) "",
MEMBER(mail_full_filesystem_access) FALSE,
MEMBER(mail_max_keyword_length) 50,
MEMBER(mail_save_crlf) FALSE,
diff -ur dovecot-1.0.5/src/master/master-settings.h dovecot-1.0.5-debugcmd/src/master/master-settings.h
--- dovecot-1.0.5/src/master/master-settings.h2007-07-16 07:51:07.000000000 +1200
+++ dovecot-1.0.5-debugcmd/src/master/master-settings.h2007-10-11 11:54:22.000000000 +1300
@@ -74,6 +74,8 @@
unsigned int mail_cache_min_mail_count;
unsigned int mailbox_idle_check_interval;
bool mail_debug;
+const char *pop3_debug_client_commands;
+const char *imap_debug_client_commands;
bool mail_full_filesystem_access;
unsigned int mail_max_keyword_length;
bool mail_save_crlf;
diff -ur dovecot-1.0.5/src/pop3/client.c dovecot-1.0.5-debugcmd/src/pop3/client.c
--- dovecot-1.0.5/src/pop3/client.c2007-08-25 04:58:50.000000000 +1200
+++ dovecot-1.0.5-debugcmd/src/pop3/client.c2007-10-11 11:54:22.000000000 +1300
@@ -385,6 +385,10 @@
return;
}
+pop3_debug_client_commands_arr = NULL;
+if (getenv("POP3_DEBUG_CLIENT_COMMANDS") != NULL)
+pop3_debug_client_commands_arr = t_strsplit_spaces(getenv("POP3_DEBUG_CLIENT_COMMANDS"), ", ");
+
o_stream_cork(client->output);
while (!client->output->closed &&
(line = i_stream_next_line(client->input)) != NULL) {
diff -ur dovecot-1.0.5/src/pop3/commands.c dovecot-1.0.5-debugcmd/src/pop3/commands.c
--- dovecot-1.0.5/src/pop3/commands.c2007-05-19 23:14:04.000000000 +1200
+++ dovecot-1.0.5-debugcmd/src/pop3/commands.c2007-10-11 11:54:22.000000000 +1300
@@ -668,11 +668,22 @@
int client_command_execute(struct client *client,
const char *name, const char *args)
{
+int i;
+
/* keep the command uppercased */
name = t_str_ucase(name);
while (*args == ' ') args++;
+if (pop3_debug_client_commands_arr != NULL) {
+for (i = 0; pop3_debug_client_commands_arr[i] != NULL; i++) {
+if (strcasecmp(name, pop3_debug_client_commands_arr[i]) == 0) {
+i_info("Client command: %s %s", name, args);
+break;
+}
+}
+}
+
switch (*name) {
case 'C':
if (strcmp(name, "CAPA") == 0)
diff -ur dovecot-1.0.5/src/pop3/common.h dovecot-1.0.5-debugcmd/src/pop3/common.h
--- dovecot-1.0.5/src/pop3/common.h2007-05-19 23:14:04.000000000 +1200
+++ dovecot-1.0.5-debugcmd/src/pop3/common.h2007-10-11 11:54:22.000000000 +1300
@@ -21,6 +21,7 @@
extern bool enable_last_command, no_flag_updates, reuse_xuidl, lock_session;
extern const char *uidl_format, *logout_format;
extern enum uidl_keys uidl_keymask;
+extern char **pop3_debug_client_commands_arr;
extern void (*hook_mail_storage_created)(struct mail_storage *storage);
extern void (*hook_client_created)(struct client **client);
diff -ur dovecot-1.0.5/src/pop3/main.c dovecot-1.0.5-debugcmd/src/pop3/main.c
--- dovecot-1.0.5/src/pop3/main.c2007-07-16 07:58:50.000000000 +1200
+++ dovecot-1.0.5-debugcmd/src/pop3/main.c2007-10-11 11:54:22.000000000 +1300
@@ -48,6 +48,7 @@
bool lock_session = FALSE;
const char *uidl_format, *logout_format;
enum uidl_keys uidl_keymask;
+char **pop3_debug_client_commands_arr;
static void sig_die(int signo, void *context __attr_unused__)
{

Reply via email to