From e102848bf5ac943bceeb35da09b0998ae485d5ad Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Mon, 28 May 2001 15:34:28 +0000 Subject: [PATCH] Detect external modifications of IMAP folders. From Brendan Cully. --- imap/command.c | 7 ++++++- imap/imap.c | 11 ++++++++--- imap/imap_private.h | 7 ++++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/imap/command.c b/imap/command.c index 61dd622b..1d7e3cf8 100644 --- a/imap/command.c +++ b/imap/command.c @@ -263,7 +263,12 @@ static void cmd_finish (IMAP_DATA* idata) { dprint (2, (debugfile, "cmd_finish: Expunging mailbox\n")); imap_expunge_mailbox (idata); - idata->reopen &= ~(IMAP_EXPUNGE_PENDING|IMAP_NEWMAIL_PENDING); + /* Detect whether we've gotten unexpected EXPUNGE messages */ + if (idata->reopen & IMAP_EXPUNGE_PENDING && + !(idata->reopen & IMAP_EXPUNGE_EXPECTED)) + idata->check_status = IMAP_EXPUNGE_PENDING; + idata->reopen &= ~(IMAP_EXPUNGE_PENDING | IMAP_NEWMAIL_PENDING | + IMAP_EXPUNGE_EXPECTED); } } diff --git a/imap/imap.c b/imap/imap.c index 1ba339d6..8f911dc3 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -1006,6 +1006,8 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint) mutt_bit_isset(idata->rights, IMAP_ACL_DELETE)) { mutt_message _("Expunging messages from server..."); + /* Set expunge bit so we don't get spurious reopened messages */ + idata->reopen |= IMAP_EXPUNGE_EXPECTED; if (imap_exec (idata, "EXPUNGE", 0) != 0) { imap_error ("imap_sync_mailbox: EXPUNGE failed", idata->cmd.buf); @@ -1096,9 +1098,12 @@ int imap_check_mailbox (CONTEXT *ctx, int *index_hint) idata->check_status &= ~IMAP_NEWMAIL_PENDING; return M_NEW_MAIL; } - /* TODO: we should be able to detect external changes and return - * M_REOPENED here. */ - + if (idata->check_status & IMAP_EXPUNGE_PENDING) + { + idata->check_status &= ~IMAP_EXPUNGE_PENDING; + return M_REOPENED; + } + return 0; } diff --git a/imap/imap_private.h b/imap/imap_private.h index 78f6e62f..3dbcdf6f 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -49,9 +49,10 @@ #define SEQLEN 5 -#define IMAP_REOPEN_ALLOW (1<<0) -#define IMAP_EXPUNGE_PENDING (1<<1) -#define IMAP_NEWMAIL_PENDING (1<<2) +#define IMAP_REOPEN_ALLOW (1<<0) +#define IMAP_EXPUNGE_PENDING (1<<1) +#define IMAP_NEWMAIL_PENDING (1<<2) +#define IMAP_EXPUNGE_EXPECTED (1<<3) /* imap_exec flags (see imap_exec) */ #define IMAP_CMD_FAIL_OK (1<<0) -- 2.40.0