]> granicus.if.org Git - neomutt/commitdiff
patch-bac-vvvacounthook-20010628.1
authorThomas Roessler <roessler@does-not-exist.org>
Fri, 29 Jun 2001 10:06:14 +0000 (10:06 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Fri, 29 Jun 2001 10:06:14 +0000 (10:06 +0000)
hook.c
imap/imap.c
init.h
mutt.h
mutt_socket.c
protos.h

diff --git a/hook.c b/hook.c
index 3e3588c7452e4ddc7aba8acdd50f6dd666d93cfa..01f2f3ecb6cd50c879fdfbd8bdd93c169d3f08d1 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -65,7 +65,7 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
     goto error;
   }
 
-  mutt_extract_token (&command, s, (data & (M_FOLDERHOOK | M_SENDHOOK)) ?  M_TOKEN_SPACE : 0);
+  mutt_extract_token (&command, s, (data & (M_FOLDERHOOK | M_SENDHOOK | M_ACCOUNTHOOK)) ?  M_TOKEN_SPACE : 0);
 
   if (!command.data)
   {
@@ -87,11 +87,8 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
     memset (&pattern, 0, sizeof (pattern));
     pattern.data = safe_strdup (path);
   }
-  else if (DefaultHook && !(data & M_CHARSETHOOK)
-#ifdef HAVE_PGP
-      && !(data & M_PGPHOOK)
-#endif /* HAVE_PGP */
-      )
+  else if (DefaultHook && (data & (M_FOLDERHOOK | M_MBOXHOOK | M_SENDHOOK |
+                                  M_FCCHOOK | M_SAVEHOOK | M_MESSAGEHOOK)))
   {
     char tmp[HUGE_STRING];
 
@@ -118,7 +115,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 & (M_FOLDERHOOK | M_SENDHOOK | M_MESSAGEHOOK))
+      if (data & (M_FOLDERHOOK | M_SENDHOOK | M_MESSAGEHOOK | M_ACCOUNTHOOK))
       {
        /* these hooks allow multiple commands with the same
         * pattern, so if we've already seen this pattern/command pair, just
@@ -450,3 +447,37 @@ char *mutt_pgp_hook (ADDRESS *adr)
   return _mutt_string_hook (adr->mailbox, M_PGPHOOK);
 }
 #endif /* HAVE_PGP */
+
+#ifdef USE_SOCKET
+void mutt_account_hook (const char* url)
+{
+  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 & M_ACCOUNTHOOK)))
+      continue;
+
+    if ((regexec (hook->rx.rx, url, 0, NULL, 0) == 0) ^ hook->rx.not)
+    {
+      if (mutt_parse_rc_line (hook->command, &token, &err) == -1)
+      {
+       FREE (&token.data);
+       mutt_error ("%s", err.data);
+       mutt_sleep (1);
+
+       return;
+      }
+    }
+  }
+
+  FREE (&token.data);
+}
+#endif
index d9e5a40e2ff55b48baba9dd568cfc39df3fb9778..cfb65efa97676a469be0ccf24170f7c5d3ccf1bc 100644 (file)
@@ -650,7 +650,7 @@ int imap_open_mailbox (CONTEXT* ctx)
   ctx->hdrs = safe_malloc (count * sizeof (HEADER *));
   ctx->v2r = safe_malloc (count * sizeof (int));
   ctx->msgcount = 0;
-  if (imap_read_headers (idata, 0, count - 1) < 0)
+  if (count && (imap_read_headers (idata, 0, count-1) < 0))
   {
     mutt_error _("Error opening mailbox");
     mutt_sleep (1);
diff --git a/init.h b/init.h
index d2bf0ee966776d2ffd56a502cfa52a603172affc..9031f7fd090a900337069aa3133a9b05f5f2c0dd 100644 (file)
--- a/init.h
+++ b/init.h
@@ -2365,6 +2365,9 @@ struct command_t
 };
 
 struct command_t Commands[] = {
+#ifdef USE_SOCKET
+  { "account-hook",     mutt_parse_hook,        M_ACCOUNTHOOK },
+#endif
   { "alias",           parse_alias,            0 },
   { "auto_view",       parse_list,             UL &AutoViewList },
   { "alternative_order",       parse_list,     UL &AlternativeOrderList},
diff --git a/mutt.h b/mutt.h
index 6329ec9f6ec02e72840ad9fd1361ee637f5b89f5..dcf25df9b5549215bcc324e9744328620b842d47 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -142,6 +142,7 @@ typedef enum
 #ifdef HAVE_PGP
 #define M_PGPHOOK      (1<<8)
 #endif
+#define M_ACCOUNTHOOK  (1<<9)
 
 /* tree characters for linearize_tree and print_enriched_string */
 #define M_TREE_LLCORNER                1
index ff1e7f81a4dadfd6db4be464215961db2182fae6..05a5183c4c8d7bcaa153874e2eb6530c7aa4a3df 100644 (file)
@@ -223,6 +223,14 @@ void mutt_socket_free (CONNECTION* conn)
 CONNECTION* mutt_conn_find (const CONNECTION* start, const ACCOUNT* account)
 {
   CONNECTION* conn;
+  ciss_url_t url;
+  char hook[LONG_STRING];
+
+  /* account isn't actually modified, since url isn't either */
+  mutt_account_tourl ((ACCOUNT*) account, &url);
+  url.path = NULL;
+  url_ciss_tostring (&url, hook, sizeof (hook));
+  mutt_account_hook (hook);
 
   conn = start ? start->next : Connections;
   while (conn)
index 3e0e4e1c310fb8ea5ac97de77139a117e46caa69..d8718bdfa0705025828e0607365b066805bfd001 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -137,6 +137,7 @@ char *mutt_make_date (char *, size_t);
 
 const char *mutt_fqdn(short);
 
+void mutt_account_hook (const char* url);
 void mutt_adv_mktemp (char *, size_t);
 void mutt_alias_menu (char *, size_t, ALIAS *);
 void mutt_allow_interrupt (int);