#ifdef USE_IMAP
case OP_MAIN_IMAP_FETCH:
if (Context && Context->magic == MUTT_IMAP)
- imap_check_mailbox (Context, &index_hint, 1);
+ imap_check_mailbox (Context, 1);
break;
case OP_MAIN_IMAP_LOGOUT_ALL:
imap_munge_mbox_name (idata, mbox, sizeof (mbox), mx.mbox);
snprintf (buf, sizeof (buf), "DELETE %s", mbox);
- if (imap_exec ((IMAP_DATA*) idata, buf, 0) != 0)
+ if (imap_exec (idata, buf, 0) != 0)
return -1;
return 0;
else
memcpy (&conn->account, creds, sizeof (ACCOUNT));
- idata = (IMAP_DATA*)conn->data;
+ idata = conn->data;
if (flags & MUTT_IMAP_CONN_NONEW)
{
if (!idata)
* ctx: the current context
* expunge: 0 or 1 - do expunge?
*/
-int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint)
+int imap_sync_mailbox (CONTEXT* ctx, int expunge)
{
IMAP_DATA* idata;
CONTEXT* appendctx = NULL;
int n;
int rc;
- idata = (IMAP_DATA*) ctx->data;
+ idata = ctx->data;
if (idata->state < IMAP_SELECTED)
{
* to be changed. */
imap_allow_reopen (ctx);
- if ((rc = imap_check_mailbox (ctx, index_hint, 0)) != 0)
+ if ((rc = imap_check (idata, 0)) != 0)
return rc;
/* if we are expunging anyway, we can do deleted messages very quickly... */
IMAP_DATA* idata;
int i;
- idata = (IMAP_DATA*) ctx->data;
+ idata = ctx->data;
/* Check to see if the mailbox is actually open */
if (!idata)
return 0;
* 0 no change
* -1 error
*/
-int imap_check_mailbox (CONTEXT *ctx, int *index_hint, int force)
+int imap_check_mailbox (CONTEXT *ctx, int force)
+{
+ return imap_check (ctx->data, force);
+}
+
+int imap_check (IMAP_DATA *idata, 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;
int result = 0;
- idata = (IMAP_DATA*) ctx->data;
-
/* try IDLE first, unless force is set */
if (!force && option (OPTIMAPIDLE) && mutt_bit_isset (idata->capabilities, IDLE)
&& (idata->state != IMAP_IDLE || time(NULL) >= idata->lastread + ImapKeepalive))
static int imap_check_mailbox_reopen (CONTEXT *ctx, int *index_hint)
{
int rc;
+ (void)index_hint;
imap_allow_reopen (ctx);
- rc = imap_check_mailbox (ctx, index_hint, 0);
+ rc = imap_check (ctx->data, 0);
imap_disallow_reopen (ctx);
return rc;
int imap_search (CONTEXT* ctx, const pattern_t* pat)
{
BUFFER buf;
- IMAP_DATA* idata = (IMAP_DATA*)ctx->data;
+ IMAP_DATA* idata = ctx->data;
int i;
for (i = 0; i < ctx->msgcount; i++)
IMAP_MBOX mx;
int triedcreate = 0;
- idata = (IMAP_DATA*) ctx->data;
+ idata = ctx->data;
if (imap_parse_path (dest, &mx))
{
}
/* check that the save-to folder is in the same account */
- if (!mutt_account_match (&(CTX_DATA->conn->account), &(mx.account)))
+ if (!mutt_account_match (&(idata->conn->account), &(mx.account)))
{
dprint (3, (debugfile, "imap_fast_trash: %s not same server as %s\n",
dest, ctx->path));
/* imap.c */
int imap_access (const char*, int);
-int imap_check_mailbox (CONTEXT *ctx, int *index_hint, int force);
-int imap_delete_mailbox (CONTEXT* idata, IMAP_MBOX mx);
-int imap_sync_mailbox (CONTEXT *ctx, int expunge, int *index_hint);
+int imap_check_mailbox (CONTEXT* ctx, int force);
+int imap_delete_mailbox (CONTEXT* ctx, IMAP_MBOX mx);
+int imap_sync_mailbox (CONTEXT *ctx, int expunge);
int imap_close_mailbox (CONTEXT *ctx);
int imap_buffy_check (int force, int check_stats);
int imap_status (char *path, int queue);
} IMAP_DATA;
/* I wish that were called IMAP_CONTEXT :( */
-/* -- macros -- */
-#define CTX_DATA ((IMAP_DATA *) ctx->data)
-
/* -- private IMAP functions -- */
/* imap.c */
+int imap_check (IMAP_DATA* idata, int force);
int imap_create_mailbox (IMAP_DATA* idata, char* mailbox);
int imap_rename_mailbox (IMAP_DATA* idata, IMAP_MBOX* mx, const char* newname);
IMAP_STATUS* imap_mboxcache_get (IMAP_DATA* idata, const char* mbox,
* fails. Thanks Sam. */
short fetched = 0;
- idata = (IMAP_DATA*) ctx->data;
+ idata = ctx->data;
h = ctx->hdrs[msgno];
if ((msg->fp = msg_cache_get (idata, h)))
IMAP_MBOX mx;
int rc;
- idata = (IMAP_DATA*) ctx->data;
+ idata = ctx->data;
if (imap_parse_path (ctx->path, &mx))
return -1;
int err_continue = MUTT_NO;
int triedcreate = 0;
- idata = (IMAP_DATA*) ctx->data;
+ idata = ctx->data;
if (imap_parse_path (dest, &mx))
{
}
/* check that the save-to folder is in the same account */
- if (!mutt_account_match (&(CTX_DATA->conn->account), &(mx.account)))
+ if (!mutt_account_match (&(idata->conn->account), &(mx.account)))
{
dprint (3, (debugfile, "imap_copy_messages: %s not same server as %s\n",
dest, ctx->path));
static int msg_cache_clean_cb (const char* id, body_cache_t* bcache, void* data)
{
unsigned int uv, uid, n;
- IMAP_DATA* idata = (IMAP_DATA*)data;
+ IMAP_DATA* idata = data;
if (sscanf (id, "%u-%u", &uv, &uid) != 2)
return 0;
long bytes;
int rc = -1; /* default now is that string isn't FETCH response*/
- idata = (IMAP_DATA*) ctx->data;
+ idata = ctx->data;
if (buf[0] != '*')
return rc;
void imap_keepalive (void)
{
CONNECTION *conn;
- CONTEXT *ctx = NULL;
IMAP_DATA *idata;
+ time_t now = time(NULL);
- conn = mutt_socket_head ();
- while (conn)
+ for (conn = mutt_socket_head(); conn; conn = conn->next)
{
if (conn->account.type == MUTT_ACCT_TYPE_IMAP)
{
- int need_free = 0;
-
- idata = (IMAP_DATA*) conn->data;
-
+ idata = conn->data;
if (idata->state >= IMAP_AUTHENTICATED
- && time(NULL) >= idata->lastread + ImapKeepalive)
+ && now >= idata->lastread + ImapKeepalive)
{
- if (idata->ctx)
- ctx = idata->ctx;
- else
- {
- ctx = safe_calloc (1, sizeof (CONTEXT));
- ctx->data = idata;
- /* imap_close_mailbox will set ctx->iadata->ctx to NULL, so we can't
- * rely on the value of iadata->ctx to determine if this placeholder
- * context needs to be freed.
- */
- need_free = 1;
- }
- /* if the imap connection closes during this call, ctx may be invalid
- * after this point, and thus should not be read.
- */
- imap_check_mailbox (ctx, NULL, 1);
- if (need_free)
- FREE (&ctx);
+ imap_check(idata, 1);
}
}
-
- conn = conn->next;
}
}
void imap_allow_reopen (CONTEXT *ctx)
{
- if (ctx && ctx->magic == MUTT_IMAP && CTX_DATA->ctx == ctx)
- CTX_DATA->reopen |= IMAP_REOPEN_ALLOW;
+ IMAP_DATA* idata = ctx->data;
+ if (ctx && ctx->magic == MUTT_IMAP && idata->ctx == ctx)
+ idata->reopen |= IMAP_REOPEN_ALLOW;
}
void imap_disallow_reopen (CONTEXT *ctx)
{
- if (ctx && ctx->magic == MUTT_IMAP && CTX_DATA->ctx == ctx)
- CTX_DATA->reopen &= ~IMAP_REOPEN_ALLOW;
+ IMAP_DATA* idata = ctx->data;
+ if (ctx && ctx->magic == MUTT_IMAP && idata->ctx == ctx)
+ idata->reopen &= ~IMAP_REOPEN_ALLOW;
}
int imap_account_match (const ACCOUNT* a1, const ACCOUNT* a2)
/* allow IMAP to preserve the deleted flag across sessions */
if (ctx->magic == MUTT_IMAP)
{
- if ((check = imap_sync_mailbox (ctx, purge, index_hint)) != 0)
+ if ((check = imap_sync_mailbox (ctx, purge)) != 0)
{
ctx->closing = 0;
return check;
#ifdef USE_IMAP
if (ctx->magic == MUTT_IMAP)
- rc = imap_sync_mailbox (ctx, purge, index_hint);
+ rc = imap_sync_mailbox (ctx, purge);
else
#endif
rc = sync_mailbox (ctx, index_hint);