From 704338030db69ca691ce1b9914aba6dc4205f373 Mon Sep 17 00:00:00 2001
From: Brendan Cully <brendan@kublai.com>
Date: Tue, 13 Jan 2009 06:51:42 -0800
Subject: [PATCH] Do not allow a command in an account-hook to trigger another
 account-hook. Recent changes in the IMAP path canonifier mean that
 account-hooks that set variables to URLs (eg folder, spoolfile) can trigger a
 recursive account-hook. Now we just bail out of account-hook early if we are
 called recursively, but perhaps we should warn the user to use a folder-hook
 instead. Thanks to Kyle Wheeler for finding this one.

---
 hook.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/hook.c b/hook.c
index 8df5781b..d71cdf7d 100644
--- a/hook.c
+++ b/hook.c
@@ -460,11 +460,19 @@ char *mutt_crypt_hook (ADDRESS *adr)
 #ifdef USE_SOCKET
 void mutt_account_hook (const char* url)
 {
+  /* parsing commands with URLs in an account hook can cause a recursive
+   * call. We just skip processing if this occurs. Typically such commands
+   * belong in a folder-hook -- perhaps we should warn the user. */
+  static int inhook = 0;
+
   HOOK* hook;
   BUFFER token;
   BUFFER err;
   char buf[STRING];
 
+  if (inhook)
+    return;
+
   err.data = buf;
   err.dsize = sizeof (buf);
   memset (&token, 0, sizeof (token));
@@ -476,14 +484,19 @@ void mutt_account_hook (const char* url)
 
     if ((regexec (hook->rx.rx, url, 0, NULL, 0) == 0) ^ hook->rx.not)
     {
+      inhook = 1;
+
       if (mutt_parse_rc_line (hook->command, &token, &err) == -1)
       {
 	FREE (&token.data);
 	mutt_error ("%s", err.data);
 	mutt_sleep (1);
 
+        inhook = 0;
 	return;
       }
+
+      inhook = 0;
     }
   }
 
-- 
2.40.0