From a03fa1904f2ad439b13090987c992d0c8c6e6f6a Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Tue, 11 Oct 2016 12:01:00 +0100 Subject: [PATCH] fix: overhaul the index/pager updates Wherever you are in the index/pager, you will be notified of new mail when it arrives. Make sure the last message displayed is the one saying "new mail". Notes: If you have a mail filtering system that marks mail as read, you won't get notifications when it arrives in a mailbox. When you send an email, the "sent" copy won't trigger a new mail notification. Fixes: #20 - Notification of sent mail Fixes: #195 - Cursor loses position when leaving pager --- curs_main.c | 31 ++++++++++++++++++++++--------- pager.c | 49 ++++++++++++++++++++++++++++++++++++------------- 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/curs_main.c b/curs_main.c index 897c3d4dd..0bf2fbd33 100644 --- a/curs_main.c +++ b/curs_main.c @@ -826,21 +826,26 @@ int mutt_index_menu (void) } else if (check == MUTT_NEW_MAIL || check == MUTT_REOPENED || check == MUTT_FLAGS) { - update_index (menu, Context, check, oldcount, index_hint); - /* notify the user of new mail */ if (check == MUTT_REOPENED) mutt_error _("Mailbox was externally modified. Flags may be wrong."); else if (check == MUTT_NEW_MAIL) { - mutt_message _("New mail in this mailbox."); - if (option (OPTBEEPNEW)) - beep (); - if (NewMailCmd) + for (i = oldcount; i < Context->msgcount; i++) { - char cmd[LONG_STRING]; - menu_status_line(cmd, sizeof(cmd), menu, NONULL(NewMailCmd)); - mutt_system(cmd); + if (Context->hdrs[i]->read == 0) + { + mutt_message _("New mail in this mailbox."); + if (option (OPTBEEPNEW)) + beep (); + if (NewMailCmd) + { + char cmd[LONG_STRING]; + menu_status_line(cmd, sizeof(cmd), menu, NONULL(NewMailCmd)); + mutt_system(cmd); + } + break; + } } } else if (check == MUTT_FLAGS) mutt_message _("Mailbox was externally modified."); @@ -848,6 +853,11 @@ int mutt_index_menu (void) /* avoid the message being overwritten by buffy */ do_buffy_notify = 0; + int q = Context->quiet; + Context->quiet = 1; + update_index (menu, Context, check, oldcount, index_hint); + Context->quiet = q; + menu->redraw = REDRAW_FULL; menu->max = Context->vcount; @@ -1919,6 +1929,7 @@ int mutt_index_menu (void) if (option (OPTPGPAUTODEC) && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))) mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw); + int index_hint = Context->hdrs[Context->v2r[menu->current]]->index; if ((op = mutt_display_message (CURHDR)) == -1) { unset_option (OPTNEEDRESORT); @@ -1927,6 +1938,8 @@ int mutt_index_menu (void) menu->menu = MENU_PAGER; menu->oldcurrent = menu->current; + update_index (menu, Context, MUTT_NEW_MAIL, menu->max, index_hint); + continue; case OP_EXIT: diff --git a/pager.c b/pager.c index ed90991f7..19dc2cd84 100644 --- a/pager.c +++ b/pager.c @@ -2014,8 +2014,11 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) mutt_clear_error (); mutt_curs_set (1); + int do_new_mail = 0; + if (Context && !option (OPTATTACHMSG)) { + oldcount = Context ? Context->msgcount : 0; /* check for new mail */ check = mx_check_mailbox (Context, &index_hint); if (check < 0) @@ -2030,28 +2033,48 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) } else if ((check == MUTT_NEW_MAIL) || (check == MUTT_REOPENED) || (check == MUTT_FLAGS)) { - oldcount = Context ? Context->msgcount : 0; - index->max = Context ? Context->vcount : 0; - index_hint = (Context->vcount && (index->current >= 0) && (index->current < Context->vcount)) ? Context->hdrs[Context->v2r[index->current]]->index : 0; - update_index (index, Context, check, oldcount, index_hint); - /* notify user of newly arrived mail */ if (check == MUTT_NEW_MAIL) { - mutt_message _("New mail in this mailbox."); - redraw = REDRAW_FULL; - if (option (OPTBEEPNEW)) - beep(); - if (NewMailCmd) + for (i = oldcount; i < Context->msgcount; i++) { - char cmd[LONG_STRING]; - menu_status_line (cmd, sizeof (cmd), index, NONULL (NewMailCmd)); - mutt_system (cmd); + HEADER *h = Context->hdrs[i]; + + if (h && (h->read == 0)) + { + mutt_message _("New mail in this mailbox."); + do_new_mail = 1; + break; + } } + if (index) + { + oldcount = Context ? Context->msgcount : 0; + index->max = Context ? Context->vcount : 0; + index_hint = Context->hdrs[Context->v2r[index->current]]->index; + int q = Context->quiet; + Context->quiet = 1; + update_index (index, Context, check, oldcount, index_hint); + Context->quiet = q; + } + + redraw = REDRAW_FULL; set_option (OPTSEARCHINVALID); } } + + if (mutt_buffy_notify() || do_new_mail) + { + if (option (OPTBEEPNEW)) + beep(); + if (NewMailCmd) + { + char cmd[LONG_STRING]; + menu_status_line (cmd, sizeof (cmd), index, NONULL (NewMailCmd)); + mutt_system (cmd); + } + } } if (SigInt) -- 2.40.0