From 5d1b6fe008d8cb54a1d874d7a4f43aae1039cc8f Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 10 Oct 2003 09:39:56 +0000 Subject: Merge in various small fixes, including two remote DOS svn path=/trunk/; revision=3838 --- imap.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'imap.c') diff --git a/imap.c b/imap.c index fac7cae0..e3a6f4ec 100644 --- a/imap.c +++ b/imap.c @@ -12,6 +12,7 @@ #if defined(STDC_HEADERS) #include #include +#include #endif #include "fetchmail.h" #include "socket.h" @@ -724,7 +725,8 @@ static int imap_getrange(int sock, memset(unseen_messages, 0, count * sizeof(unsigned int)); unseen = 0; - gen_send(sock, "SEARCH UNSEEN"); + /* don't count deleted messages, in case user enabled keep last time */ + gen_send(sock, "SEARCH UNSEEN NOT DELETED"); do { ok = gen_recv(sock, buf, sizeof(buf)); if (ok != 0) @@ -999,10 +1001,15 @@ static int imap_fetch_body(int sock, struct query *ctl, int number, int *lenp) /* * Try to extract a length from the FETCH response. RFC2060 requires * it to be present, but at least one IMAP server (Novell GroupWise) - * botches this. + * botches this. The overflow check is needed because of a broken + * server called dbmail that returns huge garbage lengths. */ - if ((cp = strchr(buf, '{'))) - *lenp = atoi(cp + 1); + if ((cp = strchr(buf, '{'))) { + errno = 0; + *lenp = (int)strtol(cp + 1, (char **)NULL, 10); + if (errno == ERANGE && (*lenp == LONG_MAX || *lenp == LONG_MIN)) + *lenp = -1; /* length is too big/small for us to handle */ + } else *lenp = -1; /* missing length part in FETCH reponse */ -- cgit v1.2.3