diff options
author | Eric S. Raymond <esr@thyrsus.com> | 1997-06-05 20:29:46 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 1997-06-05 20:29:46 +0000 |
commit | 1529aa80917fd187250f7126d0f8ef0770830506 (patch) | |
tree | f77287aa15b08f303ebba3c4f58c3f0855d816a2 | |
parent | e2a7a0b8398879f9e2d00f4fd63f488a1de136ef (diff) | |
download | fetchmail-1529aa80917fd187250f7126d0f8ef0770830506.tar.gz fetchmail-1529aa80917fd187250f7126d0f8ef0770830506.tar.bz2 fetchmail-1529aa80917fd187250f7126d0f8ef0770830506.zip |
Deal with 0-length response.
svn path=/trunk/; revision=1065
-rw-r--r-- | imap.c | 28 |
1 files changed, 22 insertions, 6 deletions
@@ -499,7 +499,7 @@ static int imap_fetch_headers(int sock, struct query *ctl,int number,int *lenp) static int imap_fetch_body(int sock, struct query *ctl, int number, int *lenp) /* request body of nth message */ { - char buf [POPBUFSIZE+1]; + char buf [POPBUFSIZE+1], *cp; int num; /* expunges change the fetch numbers */ @@ -543,24 +543,40 @@ static int imap_fetch_body(int sock, struct query *ctl, int number, int *lenp) if ((ok = gen_recv(sock, buf, sizeof(buf)))) return(ok); } while - /* third token can be "RFC822" or "BODY[]" */ - (sscanf(buf+2, "%d FETCH (%*s {%d}", &num, lenp) != 2); + (sscanf(buf+2, "%d FETCH", &num) != 1); if (num != number) return(PS_ERROR); + + /* try to extract a length */ + if ((cp = strchr(buf, '{'))) + *lenp = atoi(cp + 1); else - return(PS_SUCCESS); + *lenp = 0; + + return(PS_SUCCESS); } static int imap_trail(int sock, struct query *ctl, int number) /* discard tail of FETCH response after reading message text */ { - char buf [POPBUFSIZE+1]; + int num; /* expunges change the fetch numbers */ /* number -= deletecount; */ - return(gen_recv(sock, buf, sizeof(buf))); + for (;;) + { + char buf[POPBUFSIZE+1]; + int ok; + + if ((ok = gen_recv(sock, buf, sizeof(buf)))) + return(ok); + if (strstr(buf, "OK FETCH")) + break; + } + + return(PS_SUCCESS); } static int imap_delete(int sock, struct query *ctl, int number) |