Commit 8369d8cf authored by Thomas Roessler's avatar Thomas Roessler

More IMAP folder update hacks. Brendan says it works.

parent dd4004ed
......@@ -458,11 +458,11 @@ int mutt_index_menu (void)
set_option (OPTSEARCHINVALID);
}
}
#ifdef USE_IMAP
imap_disallow_reopen (Context);
imap_disallow_reopen (Context);
#endif
}
check_lock = 0;
......
......@@ -954,7 +954,9 @@ int imap_make_msg_set (char* buf, size_t buflen, CONTEXT* ctx, int flag,
/* update the IMAP server to reflect message changes done within mutt.
* Arguments
* ctx: the current context
* expunge: 0 or 1 - do expunge? */
* expunge: 0 or 1 - do expunge?
*/
int imap_sync_mailbox (CONTEXT* ctx, int expunge)
{
char buf[HUGE_STRING];
......@@ -963,13 +965,21 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge)
int deleted;
int n;
int err_continue = M_NO; /* continue on error? */
int rc;
if (CTX_DATA->state != IMAP_SELECTED)
{
dprint (2, (debugfile, "imap_sync_mailbox: no mailbox selected\n"));
return -1;
}
imap_allow_reopen (ctx); /* This function is only called when the calling code
* expects the context to be changed.
*/
if ((rc = imap_check_mailbox (ctx, NULL)) != 0)
return rc;
/* if we are expunging anyway, we can do deleted messages very quickly... */
if (expunge && mutt_bit_isset (CTX_DATA->rights, IMAP_ACL_DELETE))
{
......@@ -1087,9 +1097,6 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge)
}
}
/* clear IMAP_REOPEN_PENDING, which may have been set during exec */
CTX_DATA->reopen &= ~IMAP_REOPEN_PENDING;
return 0;
}
......@@ -1101,6 +1108,8 @@ void imap_fastclose_mailbox (CONTEXT *ctx)
if (!ctx->data)
return;
CTX_DATA->reopen &= IMAP_REOPEN_ALLOW;
if ((CTX_DATA->state == IMAP_SELECTED) && (ctx == CTX_DATA->selected_ctx))
CTX_DATA->state = IMAP_AUTHENTICATED;
......@@ -1145,27 +1154,37 @@ int imap_check_mailbox (CONTEXT *ctx, int *index_hint)
{
char buf[LONG_STRING];
static time_t checktime=0;
time_t t;
/*
* gcc thinks it has to warn about uninitialized use
* of t. This is wrong.
*/
if (ImapCheckTimeout)
{
time_t k=time(NULL);
if (k-checktime < ImapCheckTimeout)
return 0;
checktime=k;
{
t = time(NULL);
t -= checktime;
}
CTX_DATA->check_status = 0;
if (imap_exec (buf, sizeof (buf), CTX_DATA, "NOOP", 0) != 0)
if ((ImapCheckTimeout && t >= ImapCheckTimeout)
|| ((CTX_DATA->reopen & IMAP_REOPEN_ALLOW) && (CTX_DATA->reopen & ~IMAP_REOPEN_ALLOW)))
{
imap_error ("imap_check_mailbox()", buf);
return -1;
}
if (CTX_DATA->check_status == IMAP_NEW_MAIL)
return M_NEW_MAIL;
if (CTX_DATA->check_status == IMAP_REOPENED)
return M_REOPENED;
if (ImapCheckTimeout) checktime += t;
CTX_DATA->check_status = 0;
if (imap_exec (buf, sizeof (buf), CTX_DATA, "NOOP", 0) != 0)
{
imap_error ("imap_check_mailbox()", buf);
return -1;
}
if (CTX_DATA->check_status == IMAP_NEW_MAIL)
return M_NEW_MAIL;
if (CTX_DATA->check_status == IMAP_REOPENED)
return M_REOPENED;
}
return 0;
}
......
......@@ -892,7 +892,7 @@ int mx_close_mailbox (CONTEXT *ctx)
/* allow IMAP to preserve the deleted flag across sessions */
if (ctx->magic == M_IMAP)
{
if (imap_sync_mailbox (ctx, purge) == -1)
if (imap_sync_mailbox (ctx, purge) != 0)
return -1;
}
else
......@@ -1072,7 +1072,7 @@ int mx_sync_mailbox (CONTEXT *ctx)
rc = imap_sync_mailbox (ctx, purge);
else
#endif
rc = sync_mailbox (ctx);
rc = sync_mailbox (ctx);
if (rc == 0)
{
#ifdef USE_IMAP
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment