Fix bug in IMAP debug output
[dockapps/wmnotify.git] / src / imap.c
index 2cae287..13a3b0b 100644 (file)
@@ -3,19 +3,7 @@
  *
  * Copyright (C) 2003 Hugo Villeneuve <hugo@hugovil.com>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ * This file is released under the GPLv2
  */
 
 /* Define filename_M */
@@ -129,13 +117,6 @@ get_packet:
                goto error;
        }
 
-       if (wmnotify_infos.debug) {
-               printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
-               printf("IMAP4 Server Response (size %d bytes):\n", len);
-               printf("%s", rx_buffer);
-               printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
-       }
-
        /*
         * Converting the last CRLF into a LF followed by a NULL termination
         * character.
@@ -143,6 +124,10 @@ get_packet:
        rx_buffer[len - 2] = '\n';
        rx_buffer[len - 1] = '\0';
 
+       if (wmnotify_infos.debug) {
+               printf("%s", rx_buffer);
+       }
+
        /*
         * Check the Server Completion Response returned by the IMAP4 server.
         * There are currently three Server Completion Responses codes:
@@ -257,6 +242,8 @@ static int IMAP4_SendCommand(int argc, char *argv[])
 {
        int len;
        int i;
+       char debug_buffer[sizeof(tx_buffer)];
+       int debug_len;
 
        /* Adding Transaction Label. */
        tlabel++;
@@ -265,16 +252,26 @@ static int IMAP4_SendCommand(int argc, char *argv[])
        len += sprintf(tx_buffer + len, "%d", tlabel);
        tlabel_len = len;
 
+       debug_len = 0;
+       debug_len += sprintf(debug_buffer + debug_len, "%s", tx_buffer);
+
        /* Adding command and it's arguments. */
-       for (i = 0; i < argc; i++)
+       for (i = 0; i < argc; i++) {
                len += sprintf(tx_buffer + len, " %s", argv[i]);
 
+               if (STREQ(argv[0], IMAP4_CMD_LOGIN) && (i == 2)) {
+                       debug_len += sprintf(debug_buffer + debug_len,
+                                            " XXXXXXXX");
+               }
+               else {
+                       debug_len += sprintf(debug_buffer + debug_len,
+                                            " %s", argv[i]);
+               }
+       }
+
        if (wmnotify_infos.debug) {
-               tx_buffer[len] = '\0';
-               printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
-               printf("IMAP4 Client Command (size %d bytes):\n%s\n", len,
-                      tx_buffer);
-               printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
+               debug_buffer[debug_len] = '\0';
+               printf("%s\n", debug_buffer);
        }
 
        /* Adding termination characters. */