}
#ifdef USE_IMAP
+ imap_keepalive ();
imap_disallow_reopen (Context);
#endif
#ifdef USE_IMAP
case OP_MAIN_IMAP_FETCH:
- ImapLastCheck = 0;
+ if (Context->magic == M_IMAP)
+ imap_check_mailbox (Context, &index_hint, 1);
break;
#endif
WHERE LIST *MailLists INITVAL(0);
WHERE LIST *SubscribedLists INITVAL(0);
-#ifdef USE_IMAP
-WHERE time_t ImapLastCheck INITVAL(0);
-#endif
-
/* bit vector for boolean variables */
#ifdef MAIN_C
unsigned char Options[(OPTMAX + 7)/8];
cmd->blen = IMAP_CMD_BUFSIZE;
dprint (3, (debugfile, "imap_cmd_step: shrank buffer to %u bytes\n", cmd->blen));
}
-
+
+ idata->lastread = time(NULL);
+
/* handle untagged messages. The caller still gets its shot afterwards. */
if (!ascii_strncmp (cmd->buf, "* ", 2) &&
cmd_handle_untagged (idata))
/*
* Copyright (C) 1996-8 Michael R. Elkins <me@mutt.org>
* Copyright (C) 1996-9 Brandon Long <blong@fiction.net>
- * Copyright (C) 1999-2002 Brendan Cully <brendan@kublai.com>
+ * Copyright (C) 1999-2003 Brendan Cully <brendan@kublai.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/* once again the context is new */
ctx->data = idata;
- if (idata->status == IMAP_FATAL)
- goto fail;
-
/* Clean up path and replace the one in the ctx */
imap_fix_path (idata, mx.mbox, buf, sizeof (buf));
FREE(&(idata->mailbox));
* to be changed. */
imap_allow_reopen (ctx);
- if ((rc = imap_check_mailbox (ctx, index_hint)) != 0)
+ if ((rc = imap_check_mailbox (ctx, index_hint, 0)) != 0)
return rc;
memset (&cmd, 0, sizeof (cmd));
idata->state = IMAP_AUTHENTICATED;
FREE (&(idata->mailbox));
mutt_free_list (&idata->flags);
+ idata->ctx = NULL;
}
/* free IMAP part of headers */
* 0 no change
* -1 error
*/
-int imap_check_mailbox (CONTEXT *ctx, int *index_hint)
+int imap_check_mailbox (CONTEXT *ctx, int *index_hint, int force)
{
/* overload keyboard timeout to avoid many mailbox checks in a row.
* Most users don't like having to wait exactly when they press a key. */
-
IMAP_DATA* idata;
- time_t now;
int result = 0;
idata = (IMAP_DATA*) ctx->data;
- now = time(NULL);
- if (now > ImapLastCheck + Timeout)
- {
- ImapLastCheck = now;
-
- if (imap_exec (idata, "NOOP", 0) != 0)
- return -1;
- }
+ if ((force || time(NULL) > idata->lastread + Timeout)
+ && imap_exec (idata, "NOOP", 0) != 0)
+ return -1;
/* We call this even when we haven't run NOOP in case we have pending
* changes to process, since we can reopen here. */
/*
* Copyright (C) 1996-8 Michael R. Elkins <me@mutt.org>
- * Copyright (C) 2000-1 Brendan Cully <brendan@kublai.com>
+ * Copyright (C) 2000-3 Brendan Cully <brendan@kublai.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/* imap.c */
int imap_access (const char*, int);
-int imap_check_mailbox (CONTEXT *ctx, int *index_hint);
+int imap_check_mailbox (CONTEXT *ctx, int *index_hint, int force);
int imap_close_connection (CONTEXT *ctx);
int imap_delete_mailbox (CONTEXT* idata, IMAP_MBOX mx);
int imap_open_mailbox (CONTEXT *ctx);
char* capstr;
unsigned char capabilities[(CAPMAX + 7)/8];
unsigned int seqno;
+ time_t lastread; /* last time we read a command for the server */
/* who knows, one day we may run multiple commands in parallel */
IMAP_COMMAND cmd;
/* imap_new_idata: Allocate and initialise a new IMAP_DATA structure.
* Returns NULL on failure (no mem) */
IMAP_DATA* imap_new_idata (void) {
- IMAP_DATA* idata;
-
- idata = safe_calloc (1, sizeof (IMAP_DATA));
- if (!idata)
- return NULL;
-
- idata->conn = NULL;
- idata->capstr = NULL;
- idata->state = IMAP_DISCONNECTED;
- idata->seqno = 0;
-
- idata->cmd.buf = NULL;
- idata->cmd.blen = 0;
- idata->cmd.state = IMAP_CMD_OK;
-
- return idata;
+ return safe_calloc (1, sizeof (IMAP_DATA));
}
/* imap_free_idata: Release and clear storage in an IMAP_DATA structure. */
void imap_keepalive (void)
{
- CONTEXT *ctx = Context;
-
- if (ctx == NULL || ctx->magic != M_IMAP || CTX_DATA->ctx != ctx)
- return;
+ CONNECTION *conn;
+ CONTEXT *ctx = NULL;
+ IMAP_DATA *idata;
+
+ conn = mutt_socket_head ();
+ while (conn)
+ {
+ if (conn->account.type == M_ACCT_TYPE_IMAP)
+ {
+ idata = (IMAP_DATA*) conn->data;
- imap_check_mailbox (ctx, NULL);
+ if (idata->state >= IMAP_AUTHENTICATED
+ && time(NULL) >= idata->lastread + ImapKeepalive)
+ {
+ if (idata->ctx)
+ ctx = idata->ctx;
+ else
+ {
+ ctx = safe_calloc (1, sizeof (CONTEXT));
+ ctx->data = idata;
+ }
+ imap_check_mailbox (ctx, NULL, 1);
+ if (!idata->ctx)
+ FREE (&ctx);
+ }
+ }
+
+ conn = conn->next;
+ }
}
int imap_wait_keepalive (pid_t pid)
#ifdef USE_IMAP
case M_IMAP:
- return (imap_check_mailbox (ctx, index_hint));
+ return (imap_check_mailbox (ctx, index_hint, 0));
#endif /* USE_IMAP */
#ifdef USE_POP