aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1996-10-01 06:23:07 +0000
committerEric S. Raymond <esr@thyrsus.com>1996-10-01 06:23:07 +0000
commit9822112a35d7962b08730668ea2aa2355315ea42 (patch)
tree1f3c3d697b1cb5ecafc2fc05f6685997e854726a
parent62de2ec3f7d426a042992c33f38607149d2d2e70 (diff)
downloadfetchmail-9822112a35d7962b08730668ea2aa2355315ea42.tar.gz
fetchmail-9822112a35d7962b08730668ea2aa2355315ea42.tar.bz2
fetchmail-9822112a35d7962b08730668ea2aa2355315ea42.zip
Fix broken response parsing.
svn path=/trunk/; revision=184
-rw-r--r--imap.c81
1 files changed, 46 insertions, 35 deletions
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)