/* interpret untagged status responses */
if (strstr(buf, "* CAPABILITY"))
+ {
strncpy(capabilities, buf + 12, sizeof(capabilities));
+ capabilities[sizeof(capabilities)-1] = '\0';
+ }
else if (strstr(buf, "EXISTS"))
{
count = atoi(buf+2);
* in a challenge-response.
*/
- if ((ctl->server.authenticate == A_ANY
- || ctl->server.authenticate == A_CRAM_MD5)
- && strstr(capabilities, "AUTH=CRAM-MD5"))
+ if ((ctl->server.authenticate == A_ANY && strstr(capabilities, "AUTH=CRAM-MD5"))
+ || ctl->server.authenticate == A_CRAM_MD5)
{
if ((ok = do_cram_md5 (sock, "AUTHENTICATE", ctl, NULL)))
{
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 */
- return (gen_transact(sock, "IDLE"));
+ /* 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;
+
+ /* get OK IDLE message */
+ return imap_ok(sock, NULL);
+ } else
+ /* not idle timeout */
+ return ok;
}
static int imap_getrange(int sock,