NeoMutt  2022-04-29-215-gc12b98
Teaching an old dog new tricks
DOXYGEN
hook.c File Reference

Parse and execute user-defined hooks. More...

#include "config.h"
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "alias/lib.h"
#include "mutt.h"
#include "hook.h"
#include "attach/lib.h"
#include "index/lib.h"
#include "ncrypt/lib.h"
#include "pattern/lib.h"
#include "command_parse.h"
#include "format_flags.h"
#include "hdrline.h"
#include "init.h"
#include "mutt_commands.h"
#include "mutt_globals.h"
#include "muttlib.h"
#include "mx.h"
#include "compmbox/lib.h"
+ Include dependency graph for hook.c:

Go to the source code of this file.

Data Structures

struct  Hook
 A list of user hooks. More...
 

Functions

 TAILQ_HEAD (HookList, Hook)
 
enum CommandResult mutt_parse_charset_iconv_hook (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse 'charset-hook' and 'iconv-hook' commands - Implements Command::parse() -. More...
 
enum CommandResult mutt_parse_hook (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'hook' family of commands - Implements Command::parse() -. More...
 
static void delete_hook (struct Hook *h)
 Delete a Hook. More...
 
void mutt_delete_hooks (HookFlags type)
 Delete matching hooks. More...
 
static void idxfmt_hashelem_free (int type, void *obj, intptr_t data)
 Delete an index-format-hook from the Hash Table - Implements hash_hdata_free_t -. More...
 
static void delete_idxfmt_hooks (void)
 Delete all the index-format-hooks. More...
 
enum CommandResult mutt_parse_idxfmt_hook (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'index-format-hook' command - Implements Command::parse() -. More...
 
static HookFlags mutt_get_hook_type (const char *name)
 Find a hook by name. More...
 
enum CommandResult mutt_parse_unhook (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unhook' command - Implements Command::parse() -. More...
 
void mutt_folder_hook (const char *path, const char *desc)
 Perform a folder hook. More...
 
char * mutt_find_hook (HookFlags type, const char *pat)
 Find a matching hook. More...
 
void mutt_message_hook (struct Mailbox *m, struct Email *e, HookFlags type)
 Perform a message hook. More...
 
static int addr_hook (char *path, size_t pathlen, HookFlags type, struct Mailbox *m, struct Email *e)
 Perform an address hook (get a path) More...
 
void mutt_default_save (char *path, size_t pathlen, struct Email *e)
 Find the default save path for an email. More...
 
void mutt_select_fcc (struct Buffer *path, struct Email *e)
 Select the FCC path for an email. More...
 
static void list_hook (struct ListHead *matches, const char *match, HookFlags hook)
 Find hook strings matching. More...
 
void mutt_crypt_hook (struct ListHead *list, struct Address *addr)
 Find crypto hooks for an Address. More...
 
void mutt_account_hook (const char *url)
 Perform an account hook. More...
 
void mutt_timeout_hook (void)
 Execute any timeout hooks. More...
 
void mutt_startup_shutdown_hook (HookFlags type)
 Execute any startup/shutdown hooks. More...
 
const char * mutt_idxfmt_hook (const char *name, struct Mailbox *m, struct Email *e)
 Get index-format-hook format string. More...
 

Variables

static struct HookList Hooks = TAILQ_HEAD_INITIALIZER(Hooks)
 
static struct HashTableIdxFmtHooks = NULL
 
static HookFlags current_hook_type = MUTT_HOOK_NO_FLAGS
 

Detailed Description

Parse and execute user-defined hooks.

Authors
  • Michael R. Elkins, and others
  • Pietro Cerutti
  • Oliver Bandel

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file hook.c.

Function Documentation

◆ TAILQ_HEAD()

TAILQ_HEAD ( HookList  ,
Hook   
)

◆ delete_hook()

static void delete_hook ( struct Hook h)
static

Delete a Hook.

Parameters
hHook to delete

Definition at line 347 of file hook.c.

348{
349 FREE(&h->command);
350 FREE(&h->source_file);
351 FREE(&h->regex.pattern);
352 if (h->regex.regex)
353 {
354 regfree(h->regex.regex);
355 FREE(&h->regex.regex);
356 }
358 FREE(&h);
359}
void mutt_pattern_free(struct PatternList **pat)
Free a Pattern.
Definition: compile.c:1038
#define FREE(x)
Definition: memory.h:43
struct PatternList * pattern
Used for fcc,save,send-hook.
Definition: hook.c:70
struct Regex regex
Regular expression.
Definition: hook.c:67
char * command
Filename, command or pattern to execute.
Definition: hook.c:68
char * source_file
Used for relative-directory source.
Definition: hook.c:69
char * pattern
printable version
Definition: regex3.h:90
regex_t * regex
compiled expression
Definition: regex3.h:91
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_delete_hooks()

void mutt_delete_hooks ( HookFlags  type)

Delete matching hooks.

Parameters
typeHook type to delete, see HookFlags

If 0 is passed, all the hooks will be deleted.

Definition at line 367 of file hook.c.

368{
369 struct Hook *h = NULL;
370 struct Hook *tmp = NULL;
371
372 TAILQ_FOREACH_SAFE(h, &Hooks, entries, tmp)
373 {
374 if ((type == MUTT_HOOK_NO_FLAGS) || (type == h->type))
375 {
376 TAILQ_REMOVE(&Hooks, h, entries);
377 delete_hook(h);
378 }
379 }
380}
static struct HookList Hooks
Definition: hook.c:75
static void delete_hook(struct Hook *h)
Delete a Hook.
Definition: hook.c:347
#define MUTT_HOOK_NO_FLAGS
No flags are set.
Definition: hook.h:37
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:735
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
A list of user hooks.
Definition: hook.c:65
HookFlags type
Hook type.
Definition: hook.c:66
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete_idxfmt_hooks()

static void delete_idxfmt_hooks ( void  )
static

Delete all the index-format-hooks.

Definition at line 403 of file hook.c.

404{
406}
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:457
static struct HashTable * IdxFmtHooks
Definition: hook.c:77
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_get_hook_type()

static HookFlags mutt_get_hook_type ( const char *  name)
static

Find a hook by name.

Parameters
nameName to find
Return values
numHook ID, e.g. MUTT_FOLDER_HOOK
MUTT_HOOK_NO_FLAGSError, no matching hook

Definition at line 521 of file hook.c.

522{
523 struct Command *c = NULL;
524 for (size_t i = 0, size = mutt_commands_array(&c); i < size; i++)
525 {
526 if (((c[i].parse == mutt_parse_hook) || (c[i].parse == mutt_parse_idxfmt_hook)) &&
528 {
529 return c[i].data;
530 }
531 }
532 return MUTT_HOOK_NO_FLAGS;
533}
enum CommandResult mutt_parse_idxfmt_hook(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'index-format-hook' command - Implements Command::parse() -.
Definition: hook.c:411
enum CommandResult mutt_parse_hook(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Parse the 'hook' family of commands - Implements Command::parse() -.
Definition: hook.c:128
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:819
size_t mutt_commands_array(struct Command **first)
Get Commands array.
enum CommandResult(* parse)(struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
Definition: command.h:63
intptr_t data
Data or flags to pass to the command.
Definition: command.h:65
const char * name
Name of the command.
Definition: command.h:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_folder_hook()

void mutt_folder_hook ( const char *  path,
const char *  desc 
)

Perform a folder hook.

Parameters
pathPath to potentially match
descDescription to potentially match

Definition at line 589 of file hook.c.

590{
591 if (!path && !desc)
592 return;
593
594 struct Hook *hook = NULL;
595 struct Buffer *err = mutt_buffer_pool_get();
596
598
599 TAILQ_FOREACH(hook, &Hooks, entries)
600 {
601 if (!hook->command)
602 continue;
603
604 if (!(hook->type & MUTT_FOLDER_HOOK))
605 continue;
606
607 const char *match = NULL;
608 if (mutt_regex_match(&hook->regex, path))
609 match = path;
610 else if (mutt_regex_match(&hook->regex, desc))
611 match = desc;
612
613 if (match)
614 {
615 mutt_debug(LL_DEBUG1, "folder-hook '%s' matches '%s'\n", hook->regex.pattern, match);
616 mutt_debug(LL_DEBUG5, " %s\n", hook->command);
618 {
619 mutt_error("%s", mutt_buffer_string(err));
620 break;
621 }
622 }
623 }
625
627}
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition: command.h:35
enum CommandResult mutt_parse_rc_line_cwd(const char *line, char *cwd, struct Buffer *err)
Parse and run a muttrc line in a relative directory.
#define mutt_error(...)
Definition: logging.h:87
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
static HookFlags current_hook_type
Definition: hook.c:78
#define MUTT_FOLDER_HOOK
folder-hook: when entering a mailbox
Definition: hook.h:38
@ LL_DEBUG5
Log at debug level 5.
Definition: logging.h:44
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
bool mutt_regex_match(const struct Regex *regex, const char *str)
Shorthand to mutt_regex_capture()
Definition: regex.c:631
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
String manipulation buffer.
Definition: buffer.h:34
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_find_hook()

char * mutt_find_hook ( HookFlags  type,
const char *  pat 
)

Find a matching hook.

Parameters
typeHook type, see HookFlags
patPattern to match
Return values
ptrCommand string
Note
The returned string must not be freed.

Definition at line 637 of file hook.c.

638{
639 struct Hook *tmp = NULL;
640
641 TAILQ_FOREACH(tmp, &Hooks, entries)
642 {
643 if (tmp->type & type)
644 {
645 if (mutt_regex_match(&tmp->regex, pat))
646 return tmp->command;
647 }
648 }
649 return NULL;
650}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_message_hook()

void mutt_message_hook ( struct Mailbox m,
struct Email e,
HookFlags  type 
)

Perform a message hook.

Parameters
mMailbox
eEmail
typeHook type, see HookFlags

Definition at line 658 of file hook.c.

659{
660 struct Hook *hook = NULL;
661 struct PatternCache cache = { 0 };
662 struct Buffer *err = mutt_buffer_pool_get();
663
664 current_hook_type = type;
665
666 TAILQ_FOREACH(hook, &Hooks, entries)
667 {
668 if (!hook->command)
669 continue;
670
671 if (hook->type & type)
672 {
673 if ((mutt_pattern_exec(SLIST_FIRST(hook->pattern), 0, m, e, &cache) > 0) ^
674 hook->regex.pat_not)
675 {
677 {
678 mutt_error("%s", mutt_buffer_string(err));
681
682 return;
683 }
684 /* Executing arbitrary commands could affect the pattern results,
685 * so the cache has to be wiped */
686 memset(&cache, 0, sizeof(cache));
687 }
688 }
689 }
691
693}
bool mutt_pattern_exec(struct Pattern *pat, PatternExecFlags flags, struct Mailbox *m, struct Email *e, struct PatternCache *cache)
Match a pattern against an email header.
Definition: exec.c:1107
#define SLIST_FIRST(head)
Definition: queue.h:229
Cache commonly-used patterns.
Definition: lib.h:110
bool pat_not
do not match
Definition: regex3.h:92
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addr_hook()

static int addr_hook ( char *  path,
size_t  pathlen,
HookFlags  type,
struct Mailbox m,
struct Email e 
)
static

Perform an address hook (get a path)

Parameters
pathBuffer for path
pathlenLength of buffer
typeHook type, see HookFlags
mMailbox
eEmail
Return values
0Success
-1Failure

Definition at line 705 of file hook.c.

707{
708 struct Hook *hook = NULL;
709 struct PatternCache cache = { 0 };
710
711 /* determine if a matching hook exists */
712 TAILQ_FOREACH(hook, &Hooks, entries)
713 {
714 if (!hook->command)
715 continue;
716
717 if (hook->type & type)
718 {
719 if ((mutt_pattern_exec(SLIST_FIRST(hook->pattern), 0, m, e, &cache) > 0) ^
720 hook->regex.pat_not)
721 {
722 mutt_make_string(path, pathlen, 0, hook->command, m, -1, e, MUTT_FORMAT_PLAIN, NULL);
723 return 0;
724 }
725 }
726 }
727
728 return -1;
729}
#define MUTT_FORMAT_PLAIN
Do not prepend DISP_TO, DISP_CC ...
Definition: format_flags.h:38
void mutt_make_string(char *buf, size_t buflen, int cols, const char *s, struct Mailbox *m, int inpgr, struct Email *e, MuttFormatFlags flags, const char *progress)
Create formatted strings using mailbox expandos.
Definition: hdrline.c:1405
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_default_save()

void mutt_default_save ( char *  path,
size_t  pathlen,
struct Email e 
)

Find the default save path for an email.

Parameters
pathBuffer for the path
pathlenLength of buffer
eEmail

Definition at line 737 of file hook.c.

738{
739 *path = '\0';
740 struct Mailbox *m_cur = get_current_mailbox();
741 if (addr_hook(path, pathlen, MUTT_SAVE_HOOK, m_cur, e) == 0)
742 return;
743
744 struct Envelope *env = e->env;
745 const struct Address *from = TAILQ_FIRST(&env->from);
746 const struct Address *reply_to = TAILQ_FIRST(&env->reply_to);
747 const struct Address *to = TAILQ_FIRST(&env->to);
748 const struct Address *cc = TAILQ_FIRST(&env->cc);
749 const struct Address *addr = NULL;
750 bool from_me = mutt_addr_is_user(from);
751
752 if (!from_me && reply_to && reply_to->mailbox)
753 addr = reply_to;
754 else if (!from_me && from && from->mailbox)
755 addr = from;
756 else if (to && to->mailbox)
757 addr = to;
758 else if (cc && cc->mailbox)
759 addr = cc;
760 else
761 addr = NULL;
762 if (addr)
763 {
764 struct Buffer *tmp = mutt_buffer_pool_get();
765 mutt_safe_path(tmp, addr);
766 snprintf(path, pathlen, "=%s", mutt_buffer_string(tmp));
768 }
769}
bool mutt_addr_is_user(const struct Address *addr)
Does the address belong to the user.
Definition: alias.c:574
static int addr_hook(char *path, size_t pathlen, HookFlags type, struct Mailbox *m, struct Email *e)
Perform an address hook (get a path)
Definition: hook.c:705
#define MUTT_SAVE_HOOK
save-hook: set a default folder when saving an email
Definition: hook.h:42
struct Mailbox * get_current_mailbox(void)
Get the current Mailbox.
Definition: index.c:624
void mutt_safe_path(struct Buffer *dest, const struct Address *a)
Make a safe filename from an email address.
Definition: muttlib.c:758
#define TAILQ_FIRST(head)
Definition: queue.h:723
An email address.
Definition: address.h:36
char * mailbox
Mailbox and host address.
Definition: address.h:38
struct Envelope * env
Envelope information.
Definition: email.h:66
The header of an Email.
Definition: envelope.h:57
struct AddressList to
Email's 'To' list.
Definition: envelope.h:60
struct AddressList reply_to
Email's 'reply-to'.
Definition: envelope.h:64
struct AddressList cc
Email's 'Cc' list.
Definition: envelope.h:61
struct AddressList from
Email's 'From' list.
Definition: envelope.h:59
A mailbox.
Definition: mailbox.h:79
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_select_fcc()

void mutt_select_fcc ( struct Buffer path,
struct Email e 
)

Select the FCC path for an email.

Parameters
pathBuffer for the path
eEmail

Definition at line 776 of file hook.c.

777{
779
780 if (addr_hook(path->data, path->dsize, MUTT_FCC_HOOK, NULL, e) != 0)
781 {
782 const struct Address *to = TAILQ_FIRST(&e->env->to);
783 const struct Address *cc = TAILQ_FIRST(&e->env->cc);
784 const struct Address *bcc = TAILQ_FIRST(&e->env->bcc);
785 const bool c_save_name = cs_subset_bool(NeoMutt->sub, "save_name");
786 const bool c_force_name = cs_subset_bool(NeoMutt->sub, "force_name");
787 const char *const c_record = cs_subset_string(NeoMutt->sub, "record");
788 if ((c_save_name || c_force_name) && (to || cc || bcc))
789 {
790 const struct Address *addr = to ? to : (cc ? cc : bcc);
791 struct Buffer *buf = mutt_buffer_pool_get();
792 mutt_safe_path(buf, addr);
793 const char *const c_folder = cs_subset_string(NeoMutt->sub, "folder");
796 if (!c_force_name && (mx_access(mutt_buffer_string(path), W_OK) != 0))
797 mutt_buffer_strcpy(path, c_record);
798 }
799 else
800 mutt_buffer_strcpy(path, c_record);
801 }
802 else
804
806}
void mutt_buffer_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
Definition: buffer.c:275
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:327
void mutt_buffer_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition: buffer.c:189
size_t mutt_buffer_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
Definition: buffer.c:389
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
#define MUTT_FCC_HOOK
fcc-hook: to save outgoing email
Definition: hook.h:41
#define PATH_MAX
Definition: mutt.h:40
void mutt_buffer_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
Definition: muttlib.c:599
int mx_access(const char *path, int flags)
Wrapper for access, checks permissions on a given mailbox.
Definition: mx.c:184
#define NONULL(x)
Definition: string2.h:37
size_t dsize
Length of data.
Definition: buffer.h:37
char * data
Pointer to data.
Definition: buffer.h:35
struct AddressList bcc
Email's 'Bcc' list.
Definition: envelope.h:62
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ list_hook()

static void list_hook ( struct ListHead *  matches,
const char *  match,
HookFlags  hook 
)
static

Find hook strings matching.

Parameters
[out]matchesList of hook strings
[in]matchString to match
[in]hookHook type, see HookFlags

Definition at line 814 of file hook.c.

815{
816 struct Hook *tmp = NULL;
817
818 TAILQ_FOREACH(tmp, &Hooks, entries)
819 {
820 if ((tmp->type & hook) && mutt_regex_match(&tmp->regex, match))
821 {
823 }
824 }
825}
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:64
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:250
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_crypt_hook()

void mutt_crypt_hook ( struct ListHead *  list,
struct Address addr 
)

Find crypto hooks for an Address.

Parameters
[out]listList of keys
[in]addrAddress to match

The crypt-hook associates keys with addresses.

Definition at line 834 of file hook.c.

835{
836 list_hook(list, addr->mailbox, MUTT_CRYPT_HOOK);
837}
static void list_hook(struct ListHead *matches, const char *match, HookFlags hook)
Find hook strings matching.
Definition: hook.c:814
#define MUTT_CRYPT_HOOK
crypt-hook: automatically select a PGP/SMIME key
Definition: hook.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_account_hook()

void mutt_account_hook ( const char *  url)

Perform an account hook.

Parameters
urlAccount URL to match

Definition at line 843 of file hook.c.

844{
845 /* parsing commands with URLs in an account hook can cause a recursive
846 * call. We just skip processing if this occurs. Typically such commands
847 * belong in a folder-hook -- perhaps we should warn the user. */
848 static bool inhook = false;
849 if (inhook)
850 return;
851
852 struct Hook *hook = NULL;
853 struct Buffer *err = mutt_buffer_pool_get();
854
855 TAILQ_FOREACH(hook, &Hooks, entries)
856 {
857 if (!(hook->command && (hook->type & MUTT_ACCOUNT_HOOK)))
858 continue;
859
860 if (mutt_regex_match(&hook->regex, url))
861 {
862 inhook = true;
863 mutt_debug(LL_DEBUG1, "account-hook '%s' matches '%s'\n", hook->regex.pattern, url);
864 mutt_debug(LL_DEBUG5, " %s\n", hook->command);
865
867 {
868 mutt_error("%s", mutt_buffer_string(err));
870
871 inhook = false;
872 goto done;
873 }
874
875 inhook = false;
876 }
877 }
878done:
880}
#define MUTT_ACCOUNT_HOOK
account-hook: when changing between accounts
Definition: hook.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_timeout_hook()

void mutt_timeout_hook ( void  )

Execute any timeout hooks.

The user can configure hooks to be run on timeout. This function finds all the matching hooks and executes them.

Definition at line 888 of file hook.c.

889{
890 struct Hook *hook = NULL;
891 struct Buffer err;
892 char buf[256] = { 0 };
893
894 mutt_buffer_init(&err);
895 err.data = buf;
896 err.dsize = sizeof(buf);
897
898 TAILQ_FOREACH(hook, &Hooks, entries)
899 {
900 if (!(hook->command && (hook->type & MUTT_TIMEOUT_HOOK)))
901 continue;
902
903 if (mutt_parse_rc_line_cwd(hook->command, hook->source_file, &err) == MUTT_CMD_ERROR)
904 {
905 mutt_error("%s", err.data);
906 mutt_buffer_reset(&err);
907
908 /* The hooks should be independent of each other, so even though this on
909 * failed, we'll carry on with the others. */
910 }
911 }
912
913 /* Delete temporary attachment files */
915}
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:52
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:85
#define MUTT_TIMEOUT_HOOK
timeout-hook: run a command periodically
Definition: hook.h:56
void mutt_unlink_temp_attachments(void)
Delete all temporary attachments.
Definition: mutt_attach.c:1300
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_startup_shutdown_hook()

void mutt_startup_shutdown_hook ( HookFlags  type)

Execute any startup/shutdown hooks.

Parameters
typeHook type: MUTT_STARTUP_HOOK or MUTT_SHUTDOWN_HOOK

The user can configure hooks to be run on startup/shutdown. This function finds all the matching hooks and executes them.

Definition at line 924 of file hook.c.

925{
926 struct Hook *hook = NULL;
927 struct Buffer err = mutt_buffer_make(0);
928 char buf[256] = { 0 };
929
930 err.data = buf;
931 err.dsize = sizeof(buf);
932
933 TAILQ_FOREACH(hook, &Hooks, entries)
934 {
935 if (!(hook->command && (hook->type & type)))
936 continue;
937
938 if (mutt_parse_rc_line_cwd(hook->command, hook->source_file, &err) == MUTT_CMD_ERROR)
939 {
940 mutt_error("%s", err.data);
941 mutt_buffer_reset(&err);
942 }
943 }
944}
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:67
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_idxfmt_hook()

const char * mutt_idxfmt_hook ( const char *  name,
struct Mailbox m,
struct Email e 
)

Get index-format-hook format string.

Parameters
nameHook name
mMailbox
eEmail
Return values
ptrprintf(3)-like format string
NULLNo matching hook

Definition at line 954 of file hook.c.

955{
956 if (!IdxFmtHooks)
957 return NULL;
958
959 struct HookList *hl = mutt_hash_find(IdxFmtHooks, name);
960 if (!hl)
961 return NULL;
962
964
965 struct PatternCache cache = { 0 };
966 const char *fmtstring = NULL;
967 struct Hook *hook = NULL;
968
969 TAILQ_FOREACH(hook, hl, entries)
970 {
971 struct Pattern *pat = SLIST_FIRST(hook->pattern);
972 if ((mutt_pattern_exec(pat, 0, m, e, &cache) > 0) ^ hook->regex.pat_not)
973 {
974 fmtstring = hook->command;
975 break;
976 }
977 }
978
980
981 return fmtstring;
982}
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
Definition: hash.c:362
#define MUTT_IDXFMTHOOK
index-format-hook: customise the format of the index
Definition: hook.h:55
A simple (non-regex) pattern.
Definition: lib.h:70
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ Hooks

struct HookList Hooks = TAILQ_HEAD_INITIALIZER(Hooks)
static

Definition at line 75 of file hook.c.

◆ IdxFmtHooks

struct HashTable* IdxFmtHooks = NULL
static

Definition at line 77 of file hook.c.

◆ current_hook_type

HookFlags current_hook_type = MUTT_HOOK_NO_FLAGS
static

Definition at line 78 of file hook.c.