diff -ru fetchmail-6.2.1/driver.c fetchmail-6.2.1cg1/driver.c --- fetchmail-6.2.1/driver.c Thu Dec 26 22:56:58 2002 +++ fetchmail-6.2.1cg1/driver.c Sat Feb 8 03:40:09 2003 @@ -70,9 +70,16 @@ int mailserver_socket_temp = -1; /* socket to free if connect timeout */ static int timeoutcount; /* count consecutive timeouts */ +static int idletimeout; /* timeout occured in idle stage? */ static jmp_buf restart; +int isidletimeout(void) +/* last timeout occured in idle stage? */ +{ + return idletimeout; +} + void set_timeout(int timeleft) /* reset the nonresponse-timeout */ { @@ -82,6 +89,8 @@ if (timeleft == 0) timeoutcount = 0; + idletimeout = 1; + ntimeout.it_interval.tv_sec = ntimeout.it_interval.tv_usec = 0; ntimeout.it_value.tv_sec = timeleft; ntimeout.it_value.tv_usec = 0; @@ -92,8 +101,11 @@ static RETSIGTYPE timeout_handler (int signal) /* handle SIGALRM signal indicating a server timeout */ { - timeoutcount++; - longjmp(restart, THROW_TIMEOUT); + if(stage != STAGE_IDLE) { + timeoutcount++; + longjmp(restart, THROW_TIMEOUT); + } else + idletimeout = 1; } static RETSIGTYPE sigpipe_handler (int signal) diff -ru fetchmail-6.2.1/fetchmail.h fetchmail-6.2.1cg1/fetchmail.h --- fetchmail-6.2.1/fetchmail.h Thu Dec 26 22:57:02 2002 +++ fetchmail-6.2.1cg1/fetchmail.h Sat Feb 8 02:34:29 2003 @@ -94,6 +94,7 @@ #define PS_BSMTP 12 /* output batch could not be opened */ #define PS_MAXFETCH 13 /* poll ended by fetch limit */ #define PS_SERVBUSY 14 /* server is busy */ +#define PS_IDLETIMEOUT 15 /* timeout on imap IDLE */ /* leave space for more codes */ #define PS_UNDEFINED 23 /* something I hadn't thought of */ #define PS_TRANSIENT 24 /* transient failure (internal use) */ @@ -426,6 +427,7 @@ /* driver.c -- main driver loop */ void set_timeout(int); +int isidletimeout(void); int do_protocol(struct query *, const struct method *); /* transact.c: transaction support */ diff -ru fetchmail-6.2.1/imap.c fetchmail-6.2.1cg1/imap.c --- fetchmail-6.2.1/imap.c Thu Dec 26 22:57:03 2002 +++ fetchmail-6.2.1cg1/imap.c Sat Feb 8 04:15:48 2003 @@ -526,11 +526,33 @@ static int imap_idle(int sock) /* start an RFC2177 IDLE */ { + int ok; + + /* special timeout to terminate the IDLE and re-issue it + * at least every 28 minutes: + * (the server may have an inactivity timeout) */ stage = STAGE_IDLE; saved_timeout = mytimeout; - mytimeout = 0; + mytimeout = 1680; /* 28 min */ + + /* enter IDLE mode */ + ok = gen_transact(sock, "IDLE"); + + if(ok == PS_IDLETIMEOUT) { + /* send "DONE" continuation */ + SockWrite(sock, "DONE\r\n", 6); + if (outlevel >= O_MONITOR) + report(stdout, "IMAP> DONE\n"); + + /* restore normal timeout value */ + mytimeout = saved_timeout; + stage = STAGE_FETCH; - return (gen_transact(sock, "IDLE")); + /* get OK IDLE message */ + return imap_ok(sock, NULL); + } else + /* not idle timeout */ + return ok; } static int imap_getrange(int sock, diff -ru fetchmail-6.2.1/transact.c fetchmail-6.2.1cg1/transact.c --- fetchmail-6.2.1/transact.c Tue Nov 26 05:04:56 2002 +++ fetchmail-6.2.1cg1/transact.c Sat Feb 8 02:35:22 2003 @@ -1450,7 +1450,10 @@ { set_timeout(0); phase = oldphase; - return(PS_SOCKET); + if(isidletimeout()) + return(PS_IDLETIMEOUT); + else + return(PS_SOCKET); } else {