From 87426e377fe64a2c0564726799c60f69dc10dfee Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 3 Aug 2001 18:12:27 +0000 Subject: Justin Guyett's fix. svn path=/trunk/; revision=3436 --- driver.c | 9 ++++++++- imap.c | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/driver.c b/driver.c index 43772458..bc99d592 100644 --- a/driver.c +++ b/driver.c @@ -428,7 +428,14 @@ static int fetch_messages(int mailserver_socket, struct query *ctl, /* request a message */ err = (ctl->server.base_protocol->fetch_headers)(mailserver_socket,ctl,num, &len); - if (err != 0) + if (err == PS_TRANSIENT) /* server is probably Exchange */ + { + report_build(stdout, + _("couldn't fetch headers, msg %d (%d octets)"), + num, msgsizes[num-1]); + continue; + } + else if (err != 0) return(err); /* -1 means we didn't see a size in the response */ diff --git a/imap.c b/imap.c index 0adb7075..96ca7ee3 100644 --- a/imap.c +++ b/imap.c @@ -656,6 +656,14 @@ static int imap_is_old(int sock, struct query *ctl, int number) return(seen); } +static char *skip_token(char *ptr) +{ + while(isspace(*ptr)) ptr++; + while(!isspace(*ptr) && !iscntrl(*ptr)) ptr++; + while(isspace(*ptr)) ptr++; + return(ptr); +} + static int imap_fetch_headers(int sock, struct query *ctl,int number,int *lenp) /* request headers of nth message */ { @@ -675,11 +683,18 @@ static int imap_fetch_headers(int sock, struct query *ctl,int number,int *lenp) for (;;) { int ok; + char *ptr; if ((ok = gen_recv(sock, buf, sizeof(buf)))) return(ok); - if (sscanf(buf+2, "%d FETCH (%*s {%d}", &num, lenp) == 2) - break; + ptr = skip_token(buf); /* either "* " or "AXXXX " */ + if (sscanf(ptr, "%d FETCH (%*s {%d}", &num, lenp) == 2) + break; + /* try to recover from chronically fucked-up M$ Exchange servers */ + else if (!strncmp(ptr, "NO", 2)) + return(PS_TRANSIENT); + else if (!strncmp(ptr, "BAD", 3)) + return(PS_TRANSIENT); } if (num != number) -- cgit v1.2.3