<<< Date Index >>>     <<< Thread Index >>>

Re: new mail notification



On Thu, Jun 24, 2010 at 5:18 PM, David Champion <dgc@xxxxxxxxxxxx> wrote:
> If you could rework this as a receive-hook (a hook like mutt's other
> hooks which triggers when new mail is received) it would be more
> flexible and would probably look more attractive to the maintainers.

David, thanks a lot for your comment.
A patch is attached, please have a look.

m.
diff -rupN mutt-1.5.20/curs_main.c mutt-1.5.20-my/curs_main.c
--- mutt-1.5.20/curs_main.c     2009-06-14 04:48:36.000000000 +0200
+++ mutt-1.5.20-my/curs_main.c  2010-06-25 10:40:19.000000000 +0200
@@ -502,6 +502,7 @@ int mutt_index_menu (void)
          mutt_message _("New mail in this mailbox.");
          if (option (OPTBEEPNEW))
            beep ();
+          mutt_message_hook (Context, 0, M_RECEIVEHOOK);
        } else if (check == M_FLAGS)
          mutt_message _("Mailbox was externally modified.");
 
diff -rupN mutt-1.5.20/hook.c mutt-1.5.20-my/hook.c
--- mutt-1.5.20/hook.c  2009-01-13 15:47:49.000000000 +0100
+++ mutt-1.5.20-my/hook.c       2010-06-25 10:49:14.000000000 +0200
@@ -70,7 +70,7 @@ int mutt_parse_hook (BUFFER *buf, BUFFER
     goto error;
   }
 
-  mutt_extract_token (&command, s, (data & (M_FOLDERHOOK | M_SENDHOOK | 
M_SEND2HOOK | M_ACCOUNTHOOK | M_REPLYHOOK)) ?  M_TOKEN_SPACE : 0);
+  mutt_extract_token (&command, s, (data & (M_FOLDERHOOK | M_SENDHOOK | 
M_SEND2HOOK | M_ACCOUNTHOOK | M_REPLYHOOK | M_RECEIVEHOOK)) ?  M_TOKEN_SPACE : 
0);
 
   if (!command.data)
   {
@@ -154,10 +154,10 @@ int mutt_parse_hook (BUFFER *buf, BUFFER
       break;
   }
 
-  if (data & (M_SENDHOOK | M_SEND2HOOK | M_SAVEHOOK | M_FCCHOOK | 
M_MESSAGEHOOK | M_REPLYHOOK))
+  if (data & (M_SENDHOOK | M_SEND2HOOK | M_SAVEHOOK | M_FCCHOOK | 
M_MESSAGEHOOK | M_REPLYHOOK | M_RECEIVEHOOK))
   {
     if ((pat = mutt_pattern_comp (pattern.data,
-          (data & (M_SENDHOOK | M_SEND2HOOK | M_FCCHOOK)) ? 0 : M_FULL_MSG,
+          (data & (M_SENDHOOK | M_SEND2HOOK | M_FCCHOOK | M_RECEIVEHOOK)) ? 0 
: M_FULL_MSG,
                                  err)) == NULL)
       goto error;
   }
diff -rupN mutt-1.5.20/init.h mutt-1.5.20-my/init.h
--- mutt-1.5.20/init.h  2009-06-13 23:35:21.000000000 +0200
+++ mutt-1.5.20-my/init.h       2010-06-25 10:42:10.000000000 +0200
@@ -3504,5 +3504,7 @@ struct command_t Commands[] = {
   { "unscore",         mutt_parse_unscore,     0 },
   { "unset",           parse_set,              M_SET_UNSET },
   { "unsubscribe",     parse_unsubscribe,      0 },
+  { "receive-hook",    mutt_parse_hook,        M_RECEIVEHOOK },
+  { "system",          mutt_parse_system,      0 },
   { NULL,              NULL,                   0 }
 };
diff -rupN mutt-1.5.20/mutt.h mutt-1.5.20-my/mutt.h
--- mutt-1.5.20/mutt.h  2009-06-13 00:15:42.000000000 +0200
+++ mutt-1.5.20-my/mutt.h       2010-06-25 09:27:33.000000000 +0200
@@ -146,6 +146,7 @@ typedef enum
 #define M_ACCOUNTHOOK  (1<<9)
 #define M_REPLYHOOK    (1<<10)
 #define M_SEND2HOOK     (1<<11)
+#define M_RECEIVEHOOK   (1<<12)
 
 /* tree characters for linearize_tree and print_enriched_string */
 #define M_TREE_LLCORNER                1
diff -rupN mutt-1.5.20/protos.h mutt-1.5.20-my/protos.h
--- mutt-1.5.20/protos.h        2009-06-13 01:38:52.000000000 +0200
+++ mutt-1.5.20-my/protos.h     2010-06-25 09:58:40.000000000 +0200
@@ -51,6 +51,8 @@ void mutt_free_opts (void);
 #define mutt_system(x) _mutt_system(x,0)
 int _mutt_system (const char *, int);
 
+int mutt_parse_system (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER 
*err);
+
 #define mutt_next_thread(x) _mutt_aside_thread(x,1,0)
 #define mutt_previous_thread(x) _mutt_aside_thread(x,0,0)
 #define mutt_next_subthread(x) _mutt_aside_thread(x,1,1)
diff -rupN mutt-1.5.20/system.c mutt-1.5.20-my/system.c
--- mutt-1.5.20/system.c        2008-11-11 20:55:47.000000000 +0100
+++ mutt-1.5.20-my/system.c     2010-06-25 10:27:08.000000000 +0200
@@ -139,3 +139,14 @@ int _mutt_system (const char *cmd, int f
 
   return (rc);
 }
+
+/* system command-name */
+int mutt_parse_system (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
+{
+  if (s->dptr != NULL)
+  {
+    mutt_system(s->dptr);
+    s->dptr += strlen(s->dptr);
+  }
+  return 0;
+}