From: Richard Russon Date: Sun, 13 Jan 2019 15:05:15 +0000 (+0000) Subject: mutt_mailbox_check: factor out Context X-Git-Tag: 2019-10-25~373^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=58a96533b8b2da1a3eb93e03034d3888eec12f3d;p=neomutt mutt_mailbox_check: factor out Context --- diff --git a/browser.c b/browser.c index 88ed321cb..7b24858a2 100644 --- a/browser.c +++ b/browser.c @@ -728,7 +728,7 @@ static int examine_directory(struct Menu *menu, struct BrowserState *state, return -1; } - mutt_mailbox_check(0); + mutt_mailbox_check(Context->mailbox, 0); dp = opendir(d); if (!dp) @@ -819,7 +819,7 @@ static int examine_mailboxes(struct Menu *menu, struct BrowserState *state) if (STAILQ_EMPTY(&AllMailboxes)) return -1; - mutt_mailbox_check(0); + mutt_mailbox_check(Context ? Context->mailbox : NULL, 0); struct MailboxNode *np = NULL; STAILQ_FOREACH(np, &AllMailboxes, entries) @@ -984,7 +984,7 @@ static void init_menu(struct BrowserState *state, struct Menu *menu, if (mailbox) { menu->is_mailbox_list = true; - snprintf(title, titlelen, _("Mailboxes [%d]"), mutt_mailbox_check(0)); + snprintf(title, titlelen, _("Mailboxes [%d]"), mutt_mailbox_check(Context ? Context->mailbox : NULL, 0)); } else { diff --git a/commands.c b/commands.c index aa35fa608..547b0bc5d 100644 --- a/commands.c +++ b/commands.c @@ -804,7 +804,7 @@ void mutt_shell_escape(void) if ((rc != 0) || WaitKey) mutt_any_key_to_continue(NULL); - mutt_mailbox_check(MUTT_MAILBOX_CHECK_FORCE); + mutt_mailbox_check(Context->mailbox, MUTT_MAILBOX_CHECK_FORCE); } /** @@ -1319,5 +1319,5 @@ bool mutt_check_traditional_pgp(struct EmailList *el, int *redraw) */ void mutt_check_stats(void) { - mutt_mailbox_check(MUTT_MAILBOX_CHECK_FORCE | MUTT_MAILBOX_CHECK_FORCE_STATS); + mutt_mailbox_check(Context->mailbox, MUTT_MAILBOX_CHECK_FORCE | MUTT_MAILBOX_CHECK_FORCE_STATS); } diff --git a/context.c b/context.c index 789c7c8ac..de09f3d32 100644 --- a/context.c +++ b/context.c @@ -278,6 +278,10 @@ void ctx_mailbox_changed(struct Mailbox *m, enum MailboxNotification action) case MBN_RESORT: mutt_sort_headers(ctx, true); break; + case MBN_UNTAG: + if (ctx->last_tag && ctx->last_tag->deleted) + ctx->last_tag = NULL; + break; } } diff --git a/enter.c b/enter.c index b134361b0..ae044c7c7 100644 --- a/enter.c +++ b/enter.c @@ -37,6 +37,7 @@ #include "mutt.h" #include "alias.h" #include "browser.h" +#include "context.h" #include "curs_lib.h" #include "enter_state.h" #include "globals.h" @@ -496,7 +497,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, int flags, bool mu { first = 1; /* clear input if user types a real key later */ mutt_mb_wcstombs(buf, buflen, state->wbuf, state->curpos); - mutt_mailbox(buf, buflen); + mutt_mailbox(Context ? Context->mailbox : NULL, buf, buflen); state->curpos = state->lastchar = mutt_mb_mbstowcs(&state->wbuf, &state->wbuflen, 0, buf); break; diff --git a/index.c b/index.c index 91b381797..b2b6b35ac 100644 --- a/index.c +++ b/index.c @@ -663,7 +663,7 @@ static int main_change_folder(struct Menu *menu, int op, struct Mailbox *m, #endif mutt_clear_error(); - mutt_mailbox_check(MUTT_MAILBOX_CHECK_FORCE); /* force the mailbox check after we have changed the folder */ + mutt_mailbox_check(Context ? Context->mailbox : NULL, MUTT_MAILBOX_CHECK_FORCE); /* force the mailbox check after we have changed the folder */ menu->redraw = REDRAW_FULL; OptSearchInvalid = true; @@ -1016,7 +1016,7 @@ int mutt_index_menu(void) if (!attach_msg) { /* force the mailbox check after we enter the folder */ - mutt_mailbox_check(MUTT_MAILBOX_CHECK_FORCE); + mutt_mailbox_check(Context ? Context->mailbox : NULL, MUTT_MAILBOX_CHECK_FORCE); } #ifdef USE_INOTIFY mutt_monitor_add(NULL); @@ -1131,12 +1131,12 @@ int mutt_index_menu(void) { /* check for new mail in the incoming folders */ oldcount = newcount; - newcount = mutt_mailbox_check(0); + newcount = mutt_mailbox_check(Context ? Context->mailbox : NULL, 0); if (newcount != oldcount) menu->redraw |= REDRAW_STATUS; if (do_mailbox_notify) { - if (mutt_mailbox_notify()) + if (mutt_mailbox_notify(Context ? Context->mailbox : NULL)) { menu->redraw |= REDRAW_STATUS; if (BeepNew) @@ -2195,7 +2195,7 @@ int mutt_index_menu(void) { mutt_str_strfcpy(buf, Context->mailbox->path, sizeof(buf)); mutt_pretty_mailbox(buf, sizeof(buf)); - mutt_mailbox(buf, sizeof(buf)); + mutt_mailbox(Context ? Context->mailbox : NULL, buf, sizeof(buf)); if (!buf[0]) { mutt_error(_("No mailboxes have new mail")); @@ -2240,7 +2240,7 @@ int mutt_index_menu(void) { /* By default, fill buf with the next mailbox that contains unread * mail */ - mutt_mailbox(buf, sizeof(buf)); + mutt_mailbox(Context ? Context->mailbox : NULL, buf, sizeof(buf)); } if (mutt_enter_fname(cp, buf, sizeof(buf), 1) == -1) diff --git a/mailbox.c b/mailbox.c index af5bd7829..3bcbf860e 100644 --- a/mailbox.c +++ b/mailbox.c @@ -122,22 +122,23 @@ void mailbox_free(struct Mailbox **m) /** * mailbox_check - Check a mailbox for new mail - * @param m Mailbox to check - * @param ctx_sb stat() info for the current mailbox (Context) + * @param m_cur Current Mailbox + * @param m_check Mailbox to check + * @param ctx_sb stat() info for the current Mailbox * @param check_stats If true, also count the total, new and flagged messages */ -static void mailbox_check(struct Mailbox *m, struct stat *ctx_sb, bool check_stats) +static void mailbox_check(struct Mailbox *m_cur, struct Mailbox *m_check, struct stat *ctx_sb, bool check_stats) { struct stat sb = { 0 }; #ifdef USE_SIDEBAR - short orig_new = m->has_new; - int orig_count = m->msg_count; - int orig_unread = m->msg_unread; - int orig_flagged = m->msg_flagged; + short orig_new = m_check->has_new; + int orig_count = m_check->msg_count; + int orig_unread = m_check->msg_unread; + int orig_flagged = m_check->msg_flagged; #endif - enum MailboxType mb_magic = mx_path_probe(m->path, NULL); + enum MailboxType mb_magic = mx_path_probe(m_check->path, NULL); switch (mb_magic) { @@ -146,33 +147,33 @@ static void mailbox_check(struct Mailbox *m, struct stat *ctx_sb, bool check_sta case MUTT_NOTMUCH: case MUTT_IMAP: if (mb_magic != MUTT_IMAP) - m->has_new = false; - m->magic = mb_magic; + m_check->has_new = false; + m_check->magic = mb_magic; break; default: - m->has_new = false; + m_check->has_new = false; - if (stat(m->path, &sb) != 0 || (S_ISREG(sb.st_mode) && sb.st_size == 0) || - ((m->magic == MUTT_UNKNOWN) && (m->magic = mx_path_probe(m->path, NULL)) <= 0)) + if (stat(m_check->path, &sb) != 0 || (S_ISREG(sb.st_mode) && sb.st_size == 0) || + ((m_check->magic == MUTT_UNKNOWN) && (m_check->magic = mx_path_probe(m_check->path, NULL)) <= 0)) { /* if the mailbox still doesn't exist, set the newly created flag to be * ready for when it does. */ - m->newly_created = true; - m->magic = MUTT_UNKNOWN; - m->size = 0; + m_check->newly_created = true; + m_check->magic = MUTT_UNKNOWN; + m_check->size = 0; return; } break; // kept for consistency. } /* check to see if the folder is the currently selected folder before polling */ - if (!Context || (Context->mailbox->path[0] == '\0') || - ((m->magic == MUTT_IMAP || m->magic == MUTT_NNTP || - m->magic == MUTT_NOTMUCH || m->magic == MUTT_POP) ? - (mutt_str_strcmp(m->path, Context->mailbox->path) != 0) : + if (!m_cur || (m_cur->path[0] == '\0') || + ((m_check->magic == MUTT_IMAP || m_check->magic == MUTT_NNTP || + m_check->magic == MUTT_NOTMUCH || m_check->magic == MUTT_POP) ? + (mutt_str_strcmp(m_check->path, m_cur->path) != 0) : (sb.st_dev != ctx_sb->st_dev || sb.st_ino != ctx_sb->st_ino))) { - switch (m->magic) + switch (m_check->magic) { case MUTT_IMAP: case MUTT_MBOX: @@ -180,26 +181,26 @@ static void mailbox_check(struct Mailbox *m, struct stat *ctx_sb, bool check_sta case MUTT_MAILDIR: case MUTT_MH: case MUTT_NOTMUCH: - if (mx_mbox_check_stats(m, 0) == 0) + if (mx_mbox_check_stats(m_check, 0) == 0) MailboxCount++; break; default:; /* do nothing */ } } - else if (CheckMboxSize && Context && (Context->mailbox->path[0] != '\0')) - m->size = (off_t) sb.st_size; /* update the size of current folder */ + else if (CheckMboxSize && m_cur && (m_cur->path[0] != '\0')) + m_check->size = (off_t) sb.st_size; /* update the size of current folder */ #ifdef USE_SIDEBAR - if ((orig_new != m->has_new) || (orig_count != m->msg_count) || - (orig_unread != m->msg_unread) || (orig_flagged != m->msg_flagged)) + if ((orig_new != m_check->has_new) || (orig_count != m_check->msg_count) || + (orig_unread != m_check->msg_unread) || (orig_flagged != m_check->msg_flagged)) { mutt_menu_set_current_redraw(REDRAW_SIDEBAR); } #endif - if (!m->has_new) - m->notified = false; - else if (!m->notified) + if (!m_check->has_new) + m_check->notified = false; + else if (!m_check->notified) MailboxNotify++; } @@ -553,6 +554,7 @@ enum CommandResult mutt_parse_unmailboxes(struct Buffer *buf, struct Buffer *s, /** * mutt_mailbox_check - Check all AllMailboxes for new mail + * @param m_cur Current Mailbox * @param force Force flags, see below * @retval num Number of mailboxes with new mail * @@ -562,7 +564,7 @@ enum CommandResult mutt_parse_unmailboxes(struct Buffer *buf, struct Buffer *s, * * Check all AllMailboxes for new mail and total/new/flagged messages */ -int mutt_mailbox_check(int force) +int mutt_mailbox_check(struct Mailbox *m_cur, int force) { struct stat contex_sb; time_t t; @@ -596,12 +598,12 @@ int mutt_mailbox_check(int force) MailboxNotify = 0; /* check device ID and serial number instead of comparing paths */ - if (!Context || !Context->mailbox || (Context->mailbox->magic == MUTT_IMAP) || - (Context->mailbox->magic == MUTT_POP) + if (!m_cur || (m_cur->magic == MUTT_IMAP) || + (m_cur->magic == MUTT_POP) #ifdef USE_NNTP - || (Context->mailbox->magic == MUTT_NNTP) + || (m_cur->magic == MUTT_NNTP) #endif - || stat(Context->mailbox->path, &contex_sb) != 0) + || stat(m_cur->path, &contex_sb) != 0) { contex_sb.st_dev = 0; contex_sb.st_ino = 0; @@ -610,7 +612,7 @@ int mutt_mailbox_check(int force) struct MailboxNode *np = NULL; STAILQ_FOREACH(np, &AllMailboxes, entries) { - mailbox_check(np->m, &contex_sb, + mailbox_check(m_cur, np->m, &contex_sb, check_stats || (!np->m->first_check_stats_done && MailCheckStats)); np->m->first_check_stats_done = true; } @@ -699,11 +701,12 @@ void mutt_mailbox_setnotified(struct Mailbox *m) /** * mutt_mailbox_notify - Notify the user if there's new mail + * @param m_cur Current Mailbox * @retval true If there is new mail */ -bool mutt_mailbox_notify(void) +bool mutt_mailbox_notify(struct Mailbox *m_cur) { - if (mutt_mailbox_check(0) && MailboxNotify) + if (mutt_mailbox_check(m_cur, 0) && MailboxNotify) { return mutt_mailbox_list(); } @@ -712,16 +715,17 @@ bool mutt_mailbox_notify(void) /** * mutt_mailbox - incoming folders completion routine - * @param s Buffer containing name of current mailbox - * @param slen Buffer length + * @param m_cur Current Mailbox + * @param s Buffer containing name of current mailbox + * @param slen Buffer length * * Given a folder name, find the next incoming folder with new mail. */ -void mutt_mailbox(char *s, size_t slen) +void mutt_mailbox(struct Mailbox *m_cur, char *s, size_t slen) { mutt_expand_path(s, slen); - if (mutt_mailbox_check(0)) + if (mutt_mailbox_check(m_cur, 0)) { int found = 0; for (int pass = 0; pass < 2; pass++) @@ -743,7 +747,7 @@ void mutt_mailbox(char *s, size_t slen) } } - mutt_mailbox_check(MUTT_MAILBOX_CHECK_FORCE); /* mailbox was wrong - resync things */ + mutt_mailbox_check(m_cur, MUTT_MAILBOX_CHECK_FORCE); /* mailbox was wrong - resync things */ } /* no folders with new mail */ diff --git a/mailbox.h b/mailbox.h index dc9667ca2..26ea8b975 100644 --- a/mailbox.h +++ b/mailbox.h @@ -58,6 +58,7 @@ enum MailboxNotification MBN_INVALID, ///< Email list was changed MBN_RESORT, ///< Email list needs resorting MBN_UPDATE, ///< Update internal tables + MBN_UNTAG, ///< Clear the 'last-tagged' pointer }; /** @@ -174,10 +175,10 @@ void mutt_mailbox_setnotified(struct Mailbox *m); #define MUTT_MAILBOX_CHECK_FORCE (1 << 0) #define MUTT_MAILBOX_CHECK_FORCE_STATS (1 << 1) -void mutt_mailbox(char *s, size_t slen); +void mutt_mailbox(struct Mailbox *m_cur, char *s, size_t slen); bool mutt_mailbox_list(void); -int mutt_mailbox_check(int force); -bool mutt_mailbox_notify(void); +int mutt_mailbox_check(struct Mailbox *m_cur, int force); +bool mutt_mailbox_notify(struct Mailbox *m_cur); enum CommandResult mutt_parse_mailboxes(struct Buffer *path, struct Buffer *s, unsigned long data, struct Buffer *err); enum CommandResult mutt_parse_unmailboxes(struct Buffer *path, struct Buffer *s, unsigned long data, struct Buffer *err); void mutt_mailbox_changed(struct Mailbox *m, enum MailboxNotification action); diff --git a/main.c b/main.c index 09e0f1eef..8b18ad845 100644 --- a/main.c +++ b/main.c @@ -1131,13 +1131,13 @@ int main(int argc, char *argv[], char *envp[]) bool passive = ImapPassive; ImapPassive = false; #endif - if (mutt_mailbox_check(0) == 0) + if (mutt_mailbox_check(Context ? Context->mailbox : NULL, 0) == 0) { mutt_message(_("No mailbox with new mail")); goto main_curses; // TEST37: neomutt -Z (no new mail) } folder[0] = '\0'; - mutt_mailbox(folder, sizeof(folder)); + mutt_mailbox(Context ? Context->mailbox : NULL, folder, sizeof(folder)); #ifdef USE_IMAP ImapPassive = passive; #endif diff --git a/mx.c b/mx.c index 511d9f360..5811b510d 100644 --- a/mx.c +++ b/mx.c @@ -518,9 +518,9 @@ static int trash_append(struct Mailbox *m) } #ifdef USE_IMAP - if (Context->mailbox->magic == MUTT_IMAP && (imap_path_probe(Trash, NULL) == MUTT_IMAP)) + if (m->magic == MUTT_IMAP && (imap_path_probe(Trash, NULL) == MUTT_IMAP)) { - if (imap_fast_trash(Context->mailbox, Trash) == 0) + if (imap_fast_trash(m, Trash) == 0) return 0; } #endif @@ -815,7 +815,7 @@ int mx_mbox_close(struct Context **pctx) /** * mx_mbox_sync - Save changes to mailbox * @param[in] ctx Context - * @param[out] index_hint Currently selected mailbox + * @param[out] index_hint Currently selected Email * @retval 0 Success * @retval -1 Error */ @@ -854,7 +854,7 @@ int mx_mbox_sync(struct Context *ctx, int *index_hint) return 0; } - if (m->msg_deleted) + if (m->msg_deleted != 0) { char buf[SHORT_STRING]; @@ -879,8 +879,7 @@ int mx_mbox_sync(struct Context *ctx, int *index_hint) m->msg_deleted = 0; } } - else if (ctx->last_tag && ctx->last_tag->deleted) - ctx->last_tag = NULL; /* reset last tagged msg now useless */ + mutt_mailbox_changed(m, MBN_UNTAG); } /* really only for IMAP - imap_sync_mailbox results in a call to @@ -890,16 +889,16 @@ int mx_mbox_sync(struct Context *ctx, int *index_hint) if (purge && m->msg_deleted && (mutt_str_strcmp(m->path, Trash) != 0)) { - if (trash_append(ctx->mailbox) != 0) + if (trash_append(m) != 0) return -1; } #ifdef USE_IMAP if (m->magic == MUTT_IMAP) - rc = imap_sync_mailbox(ctx->mailbox, purge, false); + rc = imap_sync_mailbox(m, purge, false); else #endif - rc = sync_mailbox(ctx->mailbox, index_hint); + rc = sync_mailbox(m, index_hint); if (rc == 0) { #ifdef USE_IMAP diff --git a/pager.c b/pager.c index c131a1a3b..48ac6b57f 100644 --- a/pager.c +++ b/pager.c @@ -2444,7 +2444,7 @@ int mutt_pager(const char *banner, const char *fname, int flags, struct Pager *e } } - if (mutt_mailbox_notify() || do_new_mail) + if (mutt_mailbox_notify(Context ? Context->mailbox : NULL) || do_new_mail) { if (BeepNew) beep(); diff --git a/status.c b/status.c index 19d3ff0bd..3226788ad 100644 --- a/status.c +++ b/status.c @@ -103,9 +103,9 @@ static const char *status_format_str(char *buf, size_t buflen, size_t col, int c if (!optional) { snprintf(fmt, sizeof(fmt), "%%%sd", prec); - snprintf(buf, buflen, fmt, mutt_mailbox_check(0)); + snprintf(buf, buflen, fmt, mutt_mailbox_check(Context ? Context->mailbox : NULL, 0)); } - else if (mutt_mailbox_check(0) == 0) + else if (mutt_mailbox_check(Context ? Context->mailbox : NULL, 0) == 0) optional = 0; break;