From cdc72e1866ba8bd864119390eb542937d124f61f Mon Sep 17 00:00:00 2001 From: Guillaume Brogi Date: Tue, 24 Jan 2017 22:06:28 +0100 Subject: [PATCH] fix global hooks to not take a pattern Closes #329 Closes #330 --- hook.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/hook.c b/hook.c index 5c37cb55f..9230ead27 100644 --- a/hook.c +++ b/hook.c @@ -59,7 +59,7 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) mutt_buffer_init (&pattern); mutt_buffer_init (&command); - if (~data & MUTT_GLOBALHOOK) + if (~data & MUTT_GLOBALHOOK) /* NOT a global hook */ { if (*s->dptr == '!') { @@ -76,10 +76,6 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) goto error; } } - else - { - mutt_extract_token (&pattern, s, 0); - } mutt_extract_token (&command, s, (data & (MUTT_FOLDERHOOK | MUTT_SENDHOOK | MUTT_SEND2HOOK | MUTT_ACCOUNTHOOK | MUTT_REPLYHOOK)) ? MUTT_TOKEN_SPACE : 0); @@ -128,7 +124,8 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) } } #endif - else if (DefaultHook && !(data & (MUTT_CHARSETHOOK | MUTT_ICONVHOOK | MUTT_ACCOUNTHOOK)) + else if (DefaultHook && (~data & MUTT_GLOBALHOOK) && + !(data & (MUTT_CHARSETHOOK | MUTT_ICONVHOOK | MUTT_ACCOUNTHOOK)) && (!WithCrypto || !(data & MUTT_CRYPTHOOK)) ) { @@ -157,7 +154,16 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) /* check to make sure that a matching hook doesn't already exist */ for (ptr = Hooks; ptr; ptr = ptr->next) { - if (ptr->type == data && + if (data & MUTT_GLOBALHOOK) + { + /* Ignore duplicate global hooks */ + if (mutt_strcmp (ptr->command, command.data) == 0) + { + FREE (&command.data); + return 0; + } + } + else if (ptr->type == data && ptr->rx.not == not && !mutt_strcmp (pattern.data, ptr->rx.pattern)) { @@ -197,7 +203,7 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) err)) == NULL) goto error; } - else + else if (~data & MUTT_GLOBALHOOK) /* NOT a global hook */ { /* Hooks not allowing full patterns: Check syntax of regexp */ rx = safe_malloc (sizeof (regex_t)); @@ -229,7 +235,8 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) return 0; error: - FREE (&pattern.data); + if (~data & MUTT_GLOBALHOOK) /* NOT a global hook */ + FREE (&pattern.data); FREE (&command.data); return (-1); } -- 2.40.0