From 9822112a35d7962b08730668ea2aa2355315ea42 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 1 Oct 1996 06:23:07 +0000 Subject: Fix broken response parsing. svn path=/trunk/; revision=184 --- imap.c | 81 +++++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 46 insertions(+), 35 deletions(-) (limited to 'imap.c') diff --git a/imap.c b/imap.c index 369b2944..70e29150 100644 --- a/imap.c +++ b/imap.c @@ -74,43 +74,54 @@ int imap_ok (argbuf,socket) char *argbuf; int socket; { - int ok; - char buf [POPBUFSIZE+1]; - char *bufp; - int n; - - do { - if (SockGets(socket, buf, sizeof(buf)) < 0) - return(PS_SOCKET); - - if (outlevel == O_VERBOSE) - fprintf(stderr,"%s\n",buf); - - /* interpret untagged status responses */ - if (strstr(buf, "EXISTS")) - exists = atoi(buf+2); - if (strstr(buf, "RECENT")) - recent = atoi(buf+2); - if (sscanf(buf + 2, "OK [UNSEEN %d]", &n) == 1) - unseen = n; - - } while - (tag[0] != '\0' && strncmp(buf, tag, strlen(tag))); - - if (tag[0] == '\0') { - strcpy(argbuf, buf); - return(0); - } - else { - if (strncmp(buf + TAGLEN + 1, "OK", 2) == 0) { - strcpy(argbuf, buf + TAGLEN); - return(0); + int ok; + char buf [POPBUFSIZE+1]; + char *bufp; + int n; + + do { + if (SockGets(socket, buf, sizeof(buf)) < 0) + return(PS_SOCKET); + + if (outlevel == O_VERBOSE) + fprintf(stderr,"%s\n",buf); + + /* interpret untagged status responses */ + if (strstr(buf, "EXISTS")) + exists = atoi(buf+2); + if (strstr(buf, "RECENT")) + recent = atoi(buf+2); + if (sscanf(buf + 2, "OK [UNSEEN %d]", &n) == 1) + unseen = n; + + } while + (tag[0] != '\0' && strncmp(buf, tag, strlen(tag))); + + if (tag[0] == '\0') + { + strcpy(argbuf, buf); + return(0); } - else if (strncmp(buf + TAGLEN + 1, "BAD", 2) == 0) - return(PS_ERROR); else - return(PS_PROTOCOL); - } + { + char *cp; + + /* skip the tag */ + for (cp = buf; !isspace(*cp); cp++) + continue; + while (isspace(*cp)) + cp++; + + if (strncmp(cp, "OK", 2) == 0) + { + strcpy(argbuf, cp); + return(0); + } + else if (strncmp(cp, "BAD", 2) == 0) + return(PS_ERROR); + else + return(PS_PROTOCOL); + } } int imap_getauth(socket, queryctl, buf) -- cgit v1.2.3