From: Hugo Villeneuve Date: Sat, 14 Jan 2017 16:02:46 +0000 (-0500) Subject: Improve IMAP debug messages X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=8b2b74d6ab3f9a5efc7dc4e8dca9e699a265058f;p=dockapps%2Fwmnotify.git Improve IMAP debug messages --- diff --git a/src/imap.c b/src/imap.c index 13a3b0b..1c33b80 100644 --- a/src/imap.c +++ b/src/imap.c @@ -29,6 +29,7 @@ #include "network.h" #include "imap.h" +#define DEBUG_RESPONSE_LINE_INDENT " " #define IMAP4_ENDL "\r\n" /* CRLF */ @@ -60,6 +61,29 @@ static int unseen_string_found; extern char tx_buffer[WMNOTIFY_BUFSIZE + 1]; extern char rx_buffer[WMNOTIFY_BUFSIZE + 1]; +static void +IMAP4_debug_response(const char *buf, int len) +{ + int k, l; + + k = strlen(rx_buffer); + + if (k >= sizeof(rx_buffer)) { + k = 0; + } + + printf(DEBUG_RESPONSE_LINE_INDENT); + for (l = 0; l < k; l++) { + if ((rx_buffer[l] == '\n') && (l < (k - 1))) { + printf("\n" DEBUG_RESPONSE_LINE_INDENT); + } + else + { + printf("%c", rx_buffer[l]); + } + } +} + static int IMAP4_ReceiveResponse(void) { int len; @@ -125,7 +149,7 @@ get_packet: rx_buffer[len - 1] = '\0'; if (wmnotify_infos.debug) { - printf("%s", rx_buffer); + IMAP4_debug_response(rx_buffer, len); } /*