]> granicus.if.org Git - neomutt/commitdiff
feature: timeout
authorRichard Russon <rich@flatcap.org>
Thu, 5 May 2016 23:24:10 +0000 (00:24 +0100)
committerRichard Russon <rich@flatcap.org>
Thu, 18 Aug 2016 19:48:27 +0000 (20:48 +0100)
curs_main.c
hook.c
init.h
mutt.h
protos.h

index 8e0f52ad837eadbee37601851c2626956f4e9e01..17502573973269826b9bfd888ce604d8607fe6de 100644 (file)
@@ -696,8 +696,10 @@ int mutt_index_menu (void)
 
       dprint(4, (debugfile, "mutt_index_menu[%d]: Got op %d\n", __LINE__, op));
 
-      if (op == -1)
+      if (op == -1) {
+        mutt_timeout_hook();
        continue; /* either user abort or timeout */
+      }
 
       mutt_curs_set (1);
 
diff --git a/hook.c b/hook.c
index 1b906c33ece2820c8c352e521733652637f523fd..1c3a3da9d8ef63f138550636969e5f7c760afb71 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -142,7 +142,7 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
        ptr->rx.not == not &&
        !mutt_strcmp (pattern.data, ptr->rx.pattern))
     {
-      if (data & (MUTT_FOLDERHOOK | MUTT_SENDHOOK | MUTT_SEND2HOOK | MUTT_MESSAGEHOOK | MUTT_ACCOUNTHOOK | MUTT_REPLYHOOK | MUTT_CRYPTHOOK))
+      if (data & (MUTT_FOLDERHOOK | MUTT_SENDHOOK | MUTT_SEND2HOOK | MUTT_MESSAGEHOOK | MUTT_ACCOUNTHOOK | MUTT_REPLYHOOK | MUTT_CRYPTHOOK | MUTT_TIMEOUTHOOK))
       {
        /* these hooks allow multiple commands with the same
         * pattern, so if we've already seen this pattern/command pair, just
@@ -542,3 +542,32 @@ void mutt_account_hook (const char* url)
   FREE (&err.data);
 }
 #endif
+
+void mutt_timeout_hook (void)
+{
+  HOOK *hook;
+  BUFFER token;
+  BUFFER err;
+  char buf[STRING];
+
+  err.data = buf;
+  err.dsize = sizeof (buf);
+  memset (&token, 0, sizeof (token));
+
+  for (hook = Hooks; hook; hook = hook->next)
+  {
+    if (!(hook->command && (hook->type & MUTT_TIMEOUTHOOK)))
+      continue;
+
+    if (mutt_parse_rc_line (hook->command, &token, &err) == -1)
+    {
+      FREE (&token.data);
+      mutt_error ("%s", err.data);
+      mutt_sleep (1);
+
+      /* The hooks should be independent of each other, so even though this on
+       * failed, we'll carry on with the others. */
+    }
+  }
+}
+
diff --git a/init.h b/init.h
index 3f3f96d9dd57e3d12e609bd9e3c01f8cc3fd7d93..54e3575d50752b2e0bbd4a02aea275a32824758e 100644 (file)
--- a/init.h
+++ b/init.h
@@ -3933,6 +3933,7 @@ const struct command_t Commands[] = {
   { "spam",            parse_spam_list,        MUTT_SPAM },
   { "nospam",          parse_spam_list,        MUTT_NOSPAM },
   { "subscribe",       parse_subscribe,        0 },
+  { "timeout-hook",    mutt_parse_hook,        MUTT_TIMEOUTHOOK },
   { "toggle",          parse_set,              MUTT_SET_INV },
   { "unalias",         parse_unalias,          0 },
   { "unalternative_order",parse_unlist,                UL &AlternativeOrderList },
diff --git a/mutt.h b/mutt.h
index 2cf55b102640049fc25711e381550be4677208ad..c97ab3caf6331398b274effbe7ae09acbb4b80bb 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -141,6 +141,7 @@ typedef enum
 #define MUTT_ACCOUNTHOOK (1<<9)
 #define MUTT_REPLYHOOK   (1<<10)
 #define MUTT_SEND2HOOK   (1<<11)
+#define MUTT_TIMEOUTHOOK (1<<12)
 
 /* tree characters for linearize_tree and print_enriched_string */
 #define MUTT_TREE_LLCORNER      1
index 19d640032ae1da433f17215d5b46439a66c7781d..e27a5c6d554bad54ae22061005563327696cfef2 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -149,6 +149,7 @@ const char *mutt_get_name (ADDRESS *);
 char *mutt_get_parameter (const char *, PARAMETER *);
 LIST *mutt_crypt_hook (ADDRESS *);
 char *mutt_make_date (char *, size_t);
+void mutt_timeout_hook (void);
 
 const char *mutt_make_version (void);