diff options
author | Matthias Andree <matthias.andree@gmx.de> | 2006-03-10 09:49:10 +0000 |
---|---|---|
committer | Matthias Andree <matthias.andree@gmx.de> | 2006-03-10 09:49:10 +0000 |
commit | ed2c1b48f6dfd0bd89eeae3ebce37f54211c5c69 (patch) | |
tree | fb20126bc51dcd7ac1f5107073a8d56b5d08f7d7 /imap.c | |
parent | e240c62c314ea8b75f8b99c312311b32dc0a4fb8 (diff) | |
download | fetchmail-ed2c1b48f6dfd0bd89eeae3ebce37f54211c5c69.tar.gz fetchmail-ed2c1b48f6dfd0bd89eeae3ebce37f54211c5c69.tar.bz2 fetchmail-ed2c1b48f6dfd0bd89eeae3ebce37f54211c5c69.zip |
Merge Sunil Shetye's patch to fix NOOP-based IDLE emulation.
Bug reported by Casper Gripenberg and Brendan Lynch.
Another patch (not merged) sent by Brendan Lynch.
svn path=/branches/BRANCH_6-3/; revision=4724
Diffstat (limited to 'imap.c')
-rw-r--r-- | imap.c | 52 |
1 files changed, 29 insertions, 23 deletions
@@ -621,7 +621,6 @@ static int imap_idle(int sock) { int ok; - stage = STAGE_IDLE; saved_timeout = mytimeout; if (has_idle) { @@ -629,6 +628,7 @@ static int imap_idle(int sock) * at least every 28 minutes: * (the server may have an inactivity timeout) */ mytimeout = 1680; /* 28 min */ + stage = STAGE_IDLE; /* enter IDLE mode */ ok = gen_transact(sock, "IDLE"); @@ -637,37 +637,43 @@ static int imap_idle(int sock) SockWrite(sock, "DONE\r\n", 6); if (outlevel >= O_MONITOR) report(stdout, "IMAP> DONE\n"); - } else - /* not idle timeout */ - return ok; + /* reset stage and timeout here: we are not idling any more */ + mytimeout = saved_timeout; + stage = STAGE_FETCH; + /* get OK IDLE message */ + ok = imap_ok(sock, NULL); + } } else { /* no idle support, fake it */ - /* when faking an idle, we can't assume the server will - * send us the new messages out of the blue (RFC2060); - * this timeout is potentially the delay before we notice - * new mail (can be small since NOOP checking is cheap) */ - mytimeout = 28; + /* Note: stage and timeout have not been changed here as NOOP + * does not idle */ ok = gen_transact(sock, "NOOP"); - /* if there's an error (not likely) or we just found mail (stage - * has changed, timeout has also been restored), we're done */ - if (ok != 0 || stage != STAGE_IDLE) - return(ok); - /* wait (briefly) for an unsolicited status update */ - ok = imap_ok(sock, NULL); - /* again, this is new mail or an error */ - if (ok != PS_IDLETIMEOUT) - return(ok); + /* no error, but no new mail either */ + if (ok == PS_SUCCESS && recentcount == 0) + { + /* There are some servers who do send new mail + * notification out of the blue. This is in compliance + * with RFC 2060 section 5.3. Wait for that with a low + * timeout */ + mytimeout = 28; + stage = STAGE_IDLE; + /* We are waiting for notification; no tag needed */ + tag[0] = '\0'; + /* wait (briefly) for an unsolicited status update */ + ok = imap_ok(sock, NULL); + if (ok == PS_IDLETIMEOUT) { + /* no notification came; ok */ + ok = PS_SUCCESS; + } + } } /* restore normal timeout value */ + set_timeout(0); mytimeout = saved_timeout; stage = STAGE_FETCH; - /* get OK IDLE message */ - if (has_idle) - return imap_ok(sock, NULL); - - return PS_SUCCESS; + return(ok); } static int imap_getrange(int sock, |