]> granicus.if.org Git - neomutt/commitdiff
check for new mail while in pager when idle
authorStefan Assmann <sassmann@kpanic.de>
Mon, 8 Aug 2016 12:41:44 +0000 (14:41 +0200)
committerRichard Russon <rich@flatcap.org>
Sun, 4 Sep 2016 19:02:44 +0000 (20:02 +0100)
Currently, when the pager is open and mutt is idle the mailboxes aren't
checked for new mails. Change the behaviour to get notified of newly
arrived mail.

Closes #19  - new-mail doesn't fire if pager open
Closes #100 - check for new mail while in pager when idle

curs_main.c
pager.c
pager.h

index a1ad012bab9fe2bda28db5dea43fa7df6b16bfa4..3bc2fbbdf98ec3ae7fefd1aff3bc59ad3ff18636 100644 (file)
@@ -358,7 +358,7 @@ static int mx_toggle_write (CONTEXT *ctx)
   return 0;
 }
 
-static void update_index (MUTTMENU *menu, CONTEXT *ctx, int check,
+void update_index (MUTTMENU *menu, CONTEXT *ctx, int check,
                          int oldcount, int index_hint)
 {
   /* store pointers to the newly added messages */
diff --git a/pager.c b/pager.c
index 82858c6f2b7552595a96a9424b905471c064cee1..1c759300b61f990b4bf2f7876af55d3a4dec2767 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -29,6 +29,7 @@
 #include "pager.h"
 #include "attach.h"
 #include "mbyte.h"
+#include "mailbox.h"
 #ifdef USE_SIDEBAR
 #include "sidebar.h"
 #endif
@@ -1622,6 +1623,9 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
   int indicator = indexlen / 3;        /* the indicator line of the PI */
   int old_PagerIndexLines;             /* some people want to resize it
                                         * while inside the pager... */
+  int index_hint = 0;                  /* used to restore cursor position */
+  int oldcount = -1;
+  int check;
 
 #ifdef USE_NNTP
   char *followup_to;
@@ -1945,6 +1949,40 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
       mutt_clear_error ();
     mutt_curs_set (1);
 
+    if (Context && !option (OPTATTACHMSG))
+    {
+      /* check for new mail */
+      check = mx_check_mailbox (Context, &index_hint);
+      if (check < 0)
+      {
+        if (!Context->path)
+        {
+          /* fatal error occurred */
+          FREE (&Context);
+          redraw = REDRAW_FULL;
+          ch = -1;
+        }
+      }
+      else if ((check == MUTT_NEW_MAIL) || (check == MUTT_REOPENED) || (check == MUTT_FLAGS))
+      {
+        oldcount = Context ? Context->msgcount : 0;
+        update_index (index, Context, check, oldcount, index_hint);
+      }
+      /* notify user of newly arrived mail */
+      if (mutt_buffy_notify())
+      {
+        redraw |= REDRAW_STATUS;
+        if (option (OPTBEEPNEW))
+          beep();
+        if (NewMailCmd)
+        {
+          char cmd[LONG_STRING];
+          menu_status_line (cmd, sizeof (cmd), index, NONULL (NewMailCmd));
+          mutt_system (cmd);
+        }
+      }
+    }
+
     if (SigInt)
     {
       mutt_query_exit ();
diff --git a/pager.h b/pager.h
index 36c8725e2a60d7dd1988158f754b4d6f1f1e924c..ae8866f67f9338642fc8ee0f3af63d2c915a4b6c 100644 (file)
--- a/pager.h
+++ b/pager.h
@@ -48,3 +48,4 @@ typedef struct
 
 int mutt_do_pager (const char *, const char *, int, pager_t *);
 int mutt_pager (const char *, const char *, int, pager_t *);
+void update_index (MUTTMENU *menu, CONTEXT *ctx, int check, int oldcount, int index_hint);