From 8369d8cf6436ed2fa76229262d949a9b5cf80de6 Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Tue, 29 Feb 2000 22:27:08 +0000 Subject: [PATCH] More IMAP folder update hacks. Brendan says it works. --- curs_main.c | 6 +++--- imap/imap.c | 59 +++++++++++++++++++++++++++++++++++------------------ mx.c | 4 ++-- 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/curs_main.c b/curs_main.c index 5936a53d..32b2a3c9 100644 --- a/curs_main.c +++ b/curs_main.c @@ -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; diff --git a/imap/imap.c b/imap/imap.c index 63de926a..711eaa54 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -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; } diff --git a/mx.c b/mx.c index fdefa123..e6375e07 100644 --- a/mx.c +++ b/mx.c @@ -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 -- 2.40.0