Improve IMAP error handling to print the command which caused the error;

if the command is a LOGIN command, mask out the username and password.
This commit is contained in:
Theodore Ts'o 2004-01-16 01:41:28 +00:00
parent 9e8e31c1c2
commit 3d0d729ea9

View File

@ -26,8 +26,8 @@ exit 0
@DPATCH@
diff -urNad /usr/projects/isync/SF-cvs/isync/src/imap.c isync/src/imap.c
--- /usr/projects/isync/SF-cvs/isync/src/imap.c 2004-01-14 18:31:49.000000000 -0500
+++ isync/src/imap.c 2004-01-14 18:39:18.000000000 -0500
--- /usr/projects/isync/SF-cvs/isync/src/imap.c 2004-01-15 14:24:40.000000000 -0500
+++ isync/src/imap.c 2004-01-15 20:36:15.000000000 -0500
@@ -3,6 +3,7 @@
* isync - IMAP4 to maildir mailbox synchronizer
* Copyright (C) 2000-2002 Michael R. Elkins <me@mutt.org>
@ -133,12 +133,20 @@ diff -urNad /usr/projects/isync/SF-cvs/isync/src/imap.c isync/src/imap.c
return 0;
}
@@ -415,39 +458,114 @@
@@ -415,39 +458,121 @@
}
}
-static int
-imap_exec (imap_t * imap, const char *fmt, ...)
+static void print_imap_command(const char *cmd, FILE *f)
+{
+ if (strncmp(cmd, "LOGIN", 5))
+ fputs(cmd, f);
+ else
+ fputs("LOGIN USERNAME PASSWORD", f);
+}
+
+static struct imap_cmd *issue_imap_cmd(imap_t *imap,
+ const char *fmt, ...)
{
@ -177,10 +185,9 @@ diff -urNad /usr/projects/isync/SF-cvs/isync/src/imap.c isync/src/imap.c
- printf (">>> %s", buf);
+ if (num_in_progress)
+ printf("(%d in progress) ", num_in_progress);
+ if (strncmp(tmp, "LOGIN", 5))
+ printf (">>> %s", buf);
+ else
+ printf (">>> LOGIN USERNAME PASSWORD\n");
+ printf(">>> %d ", cmd->tag);
+ print_imap_command(tmp, stdout);
+ fputc('\n', stdout);
fflush (stdout);
}
n = socket_write (imap->sock, buf, strlen (buf));
@ -190,7 +197,7 @@ diff -urNad /usr/projects/isync/SF-cvs/isync/src/imap.c isync/src/imap.c
- return -1;
+ free(cmd);
+ return NULL;
+ }
}
+ cmd->next = in_progress;
+ in_progress = cmd;
+ num_in_progress++;
@ -202,7 +209,7 @@ diff -urNad /usr/projects/isync/SF-cvs/isync/src/imap.c isync/src/imap.c
+ printf("(Socket input pending)\n");
+ get_cmd_result(imap);
+ }
}
+ }
+ return cmd;
+}
+
@ -260,7 +267,7 @@ diff -urNad /usr/projects/isync/SF-cvs/isync/src/imap.c isync/src/imap.c
arg = next_arg (&cmd);
if (*arg == '*')
@@ -456,7 +574,7 @@
@@ -456,7 +581,7 @@
if (!arg)
{
fprintf (stderr, "IMAP error: unable to parse untagged response\n");
@ -269,7 +276,7 @@ diff -urNad /usr/projects/isync/SF-cvs/isync/src/imap.c isync/src/imap.c
}
if (!strcmp ("NAMESPACE", arg))
@@ -528,23 +646,14 @@
@@ -528,23 +653,14 @@
imap->recent = atoi (arg);
else if (!strcmp ("FETCH", arg1))
{
@ -296,7 +303,7 @@ diff -urNad /usr/projects/isync/SF-cvs/isync/src/imap.c isync/src/imap.c
}
}
#if HAVE_LIBSSL
@@ -555,7 +664,7 @@
@@ -555,7 +671,7 @@
if (!imap->cram)
{
fprintf (stderr, "IMAP error, not doing CRAM-MD5 authentication\n");
@ -305,7 +312,7 @@ diff -urNad /usr/projects/isync/SF-cvs/isync/src/imap.c isync/src/imap.c
}
resp = cram (cmd, imap->box->user, imap->box->pass);
@@ -568,34 +677,88 @@
@@ -568,34 +684,94 @@
if (n <= 0)
{
socket_perror ("write", imap->sock, n);
@ -344,8 +351,14 @@ diff -urNad /usr/projects/isync/SF-cvs/isync/src/imap.c isync/src/imap.c
+ }
+ arg = next_arg (&cmd);
+ if (strncmp("OK", arg, 2)) {
+ fprintf(stderr, "tag %u returned error: %s\n",
+ tag, arg);
+ if (cmdp->cmd) {
+ fputc('\'', stderr);
+ print_imap_command(cmdp->cmd, stderr);
+ fputc('\'', stderr);
+ } else
+ fprintf(stderr, "tag %u", tag);
+ fprintf(stderr, " returned an error (%s): %s\n",
+ arg, cmd ? cmd : "");
+ cmdp->response = -1;
+ }
+ parse_response_code (imap, cmd);
@ -408,7 +421,7 @@ diff -urNad /usr/projects/isync/SF-cvs/isync/src/imap.c isync/src/imap.c
#ifdef HAVE_LIBSSL
static int
start_tls (imap_t *imap, config_t * cfg)
@@ -1039,6 +1202,7 @@
@@ -1039,6 +1215,7 @@
size_t n;
char buf[1024];
@ -416,7 +429,7 @@ diff -urNad /usr/projects/isync/SF-cvs/isync/src/imap.c isync/src/imap.c
send_server (imap->sock, "UID FETCH %d BODY.PEEK[]", uid);
for (;;)
@@ -1160,7 +1324,9 @@
@@ -1160,7 +1337,9 @@
(buf[0] != 0) ? " " : "", Flags[i]);
}
@ -427,7 +440,7 @@ diff -urNad /usr/projects/isync/SF-cvs/isync/src/imap.c isync/src/imap.c
}
int
@@ -1249,6 +1415,7 @@
@@ -1249,6 +1428,7 @@
strcat (flagstr,") ");
}
@ -435,7 +448,7 @@ diff -urNad /usr/projects/isync/SF-cvs/isync/src/imap.c isync/src/imap.c
send_server (imap->sock, "APPEND %s%s %s{%d}",
imap->prefix, imap->box->box, flagstr, len + extra);
@@ -1341,6 +1508,7 @@
@@ -1341,6 +1521,7 @@
}
/* didn't receive an APPENDUID */