NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
module.c File Reference

Definition of the Hooks Module. More...

#include "config.h"
#include <stdbool.h>
#include <stddef.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "exec.h"
#include "module_data.h"
#include "parse.h"
+ Include dependency graph for module.c:

Go to the source code of this file.

Functions

static bool hooks_init (struct NeoMutt *n)
 Initialise a Module - Implements Module::init()
 
static bool hooks_config_define_variables (struct NeoMutt *n, struct ConfigSet *cs)
 Define the Config Variables - Implements Module::config_define_variables()
 
static bool hooks_commands_register (struct NeoMutt *n, struct CommandArray *ca)
 Register NeoMutt Commands - Implements Module::commands_register()
 
static bool hooks_cleanup (struct NeoMutt *n, void *data)
 Clean up a Module - Implements Module::cleanup()
 

Variables

struct ConfigDef HooksVars []
 Config definitions for the Hooks library.
 
const struct Command HooksCommands []
 Hook Commands.
 
const struct Module ModuleHooks
 Module for the Hooks library.
 

Detailed Description

Definition of the Hooks Module.

Authors
  • Richard Russon

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 module.c.

Function Documentation

◆ hooks_init()

static bool hooks_init ( struct NeoMutt * n)
static

Initialise a Module - Implements Module::init()

Definition at line 45 of file module.c.

46{
47 struct HooksModuleData *mod_data = MUTT_MEM_CALLOC(1, struct HooksModuleData);
48 TAILQ_INIT(&mod_data->hooks);
50
51 mod_data->notify = notify_new();
52 notify_set_parent(mod_data->notify, n->notify);
53
54 return true;
55}
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
@ MODULE_ID_HOOKS
ModuleHooks, Hook Commands
Definition module_api.h:70
struct Notify * notify_new(void)
Create a new notifications handler.
Definition notify.c:62
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition notify.c:95
void neomutt_set_module_data(struct NeoMutt *n, enum ModuleId id, void *data)
Set the private data for a Module.
Definition neomutt.c:677
#define TAILQ_INIT(head)
Definition queue.h:822
Hooks private Module data.
Definition module_data.h:33
struct HookList hooks
All simple hooks, e.g. CMD_FOLDER_HOOK.
Definition module_data.h:35
struct Notify * notify
Notifications.
Definition module_data.h:34
struct Notify * notify
Notifications handler.
Definition neomutt.h:45
+ Here is the call graph for this function:

◆ hooks_config_define_variables()

static bool hooks_config_define_variables ( struct NeoMutt * n,
struct ConfigSet * cs )
static

Define the Config Variables - Implements Module::config_define_variables()

Definition at line 60 of file module.c.

61{
63}
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[])
Register a set of config items.
Definition set.c:290
struct ConfigDef HooksVars[]
Config definitions for the Hooks library.
Definition config.c:29
+ Here is the call graph for this function:

◆ hooks_commands_register()

static bool hooks_commands_register ( struct NeoMutt * n,
struct CommandArray * ca )
static

Register NeoMutt Commands - Implements Module::commands_register()

Definition at line 68 of file module.c.

69{
71}
bool commands_register(struct CommandArray *ca, const struct Command *cmds)
Add commands to Commands array.
Definition command.c:51
const struct Command HooksCommands[]
Hook Commands.
Definition commands.c:40
+ Here is the call graph for this function:

◆ hooks_cleanup()

static bool hooks_cleanup ( struct NeoMutt * n,
void * data )
static

Clean up a Module - Implements Module::cleanup()

Definition at line 76 of file module.c.

77{
78 struct HooksModuleData *mod_data = data;
79
80 notify_free(&mod_data->notify);
81
82 mutt_delete_hooks(&mod_data->hooks, CMD_NONE);
84
85 FREE(&mod_data);
86 return true;
87}
@ CMD_NONE
No Command.
Definition command.h:62
void mutt_delete_hooks(struct HookList *hooks, enum CommandId id)
Delete matching hooks.
Definition parse.c:1020
void delete_idxfmt_hooks(struct HashTable **idx_fmt_hooks)
Delete all the index-format-hooks.
Definition parse.c:1057
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition notify.c:75
struct HashTable * idx_fmt_hooks
All Index Format hooks.
Definition module_data.h:36
+ Here is the call graph for this function:

Variable Documentation

◆ HooksVars

struct ConfigDef HooksVars[]
extern

Config definitions for the Hooks library.

Definition at line 29 of file config.c.

29 {
30 // clang-format off
31 { "default_hook", DT_STRING, IP "~f %s !~P | (~P ~C %s)", 0, NULL,
32 "Pattern to use for hooks that only have a simple regex"
33 },
34 { "force_name", DT_BOOL, false, 0, NULL,
35 "Save outgoing mail in a folder of their name"
36 },
37 { "save_name", DT_BOOL, false, 0, NULL,
38 "Save outgoing message to mailbox of recipient's name if it exists"
39 },
40 { NULL },
41 // clang-format on
42};
#define IP
Definition set.h:55
@ DT_BOOL
boolean option
Definition types.h:32
@ DT_STRING
a string
Definition types.h:44

◆ HooksCommands

const struct Command HooksCommands[]
extern

Hook Commands.

Definition at line 40 of file commands.c.

40 {
41 // clang-format off
42 { "account-hook", CMD_ACCOUNT_HOOK, parse_regex_hook,
43 N_("Run a command when switching to a matching account"),
44 N_("account-hook <regex> <command>"),
45 "optionalfeatures.html#account-hook" },
46 { "charset-hook", CMD_CHARSET_HOOK, parse_charset_hook,
47 N_("Define charset alias for languages"),
48 N_("charset-hook <alias> <charset>"),
49 "configuration.html#charset-hook" },
50 { "crypt-hook", CMD_CRYPT_HOOK, parse_crypt_hook,
51 N_("Specify which keyid to use for recipients matching regex"),
52 N_("crypt-hook <regex> <keyid>"),
53 "configuration.html#crypt-hook" },
54 { "fcc-hook", CMD_FCC_HOOK, parse_mailbox_hook,
55 N_("Pattern rule to set the save location for outgoing mail"),
56 N_("fcc-hook <pattern> <mailbox>"),
57 "configuration.html#default-save-mailbox" },
58 { "fcc-save-hook", CMD_FCC_SAVE_HOOK, parse_mailbox_hook,
59 N_("Equivalent to both `fcc-hook` and `save-hook`"),
60 N_("fcc-save-hook <pattern> <mailbox>"),
61 "configuration.html#default-save-mailbox" },
62 { "folder-hook", CMD_FOLDER_HOOK, parse_folder_hook,
63 N_("Run a command upon entering a folder matching regex"),
64 N_("folder-hook [ -noregex ] <regex> <command>"),
65 "configuration.html#folder-hook" },
66 { "iconv-hook", CMD_ICONV_HOOK, parse_charset_hook,
67 N_("Define a system-specific alias for a character set"),
68 N_("iconv-hook <charset> <local-charset>"),
69 "configuration.html#charset-hook" },
70 { "index-format-hook", CMD_INDEX_FORMAT_HOOK, parse_index_hook,
71 N_("Create dynamic index format strings"),
72 N_("index-format-hook <name> [!]<pattern> <format-string>"),
73 "configuration.html#index-format-hook" },
74 { "mbox-hook", CMD_MBOX_HOOK, parse_mbox_hook,
75 N_("On leaving a mailbox, move read messages matching a regex"),
76 N_("mbox-hook [ -noregex ] <regex> <mailbox>"),
77 "configuration.html#mbox-hook" },
78 { "message-hook", CMD_MESSAGE_HOOK, parse_pattern_hook,
79 N_("Run a command when viewing a message matching patterns"),
80 N_("message-hook <pattern> <command>"),
81 "configuration.html#message-hook" },
82 { "reply-hook", CMD_REPLY_HOOK, parse_pattern_hook,
83 N_("Run a command when replying to messages matching a pattern"),
84 N_("reply-hook <pattern> <command>"),
85 "configuration.html#send-hook" },
86 { "save-hook", CMD_SAVE_HOOK, parse_mailbox_hook,
87 N_("Set default save folder for messages"),
88 N_("save-hook <pattern> <mailbox>"),
89 "configuration.html#default-save-mailbox" },
90 { "send-hook", CMD_SEND_HOOK, parse_pattern_hook,
91 N_("Run a command when sending a message, new or reply, matching a pattern"),
92 N_("send-hook <pattern> <command>"),
93 "configuration.html#send-hook" },
94 { "send2-hook", CMD_SEND2_HOOK, parse_pattern_hook,
95 N_("Run command whenever a composed message is edited"),
96 N_("send2-hook <pattern> <command>"),
97 "configuration.html#send-hook" },
98 { "shutdown-hook", CMD_SHUTDOWN_HOOK, parse_global_hook,
99 N_("Run a command before NeoMutt exits"),
100 N_("shutdown-hook <command>"),
101 "optionalfeatures.html#global-hooks" },
102 { "startup-hook", CMD_STARTUP_HOOK, parse_global_hook,
103 N_("Run a command when NeoMutt starts up"),
104 N_("startup-hook <command>"),
105 "optionalfeatures.html#global-hooks" },
106 { "timeout-hook", CMD_TIMEOUT_HOOK, parse_global_hook,
107 N_("Run a command after a specified timeout or idle period"),
108 N_("timeout-hook <command>"),
109 "optionalfeatures.html#global-hooks" },
110 { "unhook", CMD_UNHOOK, parse_unhook,
111 N_("Remove hooks of a given type"),
112 N_("unhook { * | <hook-type> }"),
113 "configuration.html#unhook" },
114
115 { "hooks", CMD_HOOKS, parse_hooks,
116 N_("Show a list of all the hooks"),
117 N_("hooks"),
118 "advancedusage.html#hooks" },
119
120 // Deprecated
121 { "pgp-hook", CMD_NONE, NULL, "crypt-hook", NULL, NULL, CF_SYNONYM },
122
123 { NULL, CMD_NONE, NULL, NULL, NULL, NULL, CF_NONE },
124 // clang-format on
125};
@ CF_SYNONYM
Command is a synonym for another command.
Definition command.h:50
@ CF_NONE
No flags are set.
Definition command.h:49
@ CMD_SEND_HOOK
:send-hook
Definition command.h:110
@ CMD_FCC_SAVE_HOOK
:fcc-save-hook
Definition command.h:79
@ CMD_ICONV_HOOK
:iconv-hook
Definition command.h:85
@ CMD_INDEX_FORMAT_HOOK
:index-format-hook
Definition command.h:89
@ CMD_SHUTDOWN_HOOK
:shutdown-hook
Definition command.h:113
@ CMD_FCC_HOOK
:fcc-hook
Definition command.h:78
@ CMD_MESSAGE_HOOK
:message-hook
Definition command.h:97
@ CMD_SEND2_HOOK
:send2-hook
Definition command.h:109
@ CMD_REPLY_HOOK
:reply-hook
Definition command.h:105
@ CMD_STARTUP_HOOK
:startup-hook
Definition command.h:118
@ CMD_CHARSET_HOOK
:charset-hook
Definition command.h:72
@ CMD_HOOKS
:hooks
Definition command.h:84
@ CMD_SAVE_HOOK
:save-hook
Definition command.h:107
@ CMD_TIMEOUT_HOOK
:timeout-hook
Definition command.h:124
@ CMD_ACCOUNT_HOOK
:account-hook
Definition command.h:63
@ CMD_CRYPT_HOOK
:crypt-hook
Definition command.h:75
@ CMD_MBOX_HOOK
:mbox-hook
Definition command.h:96
@ CMD_FOLDER_HOOK
:folder-hook
Definition command.h:81
@ CMD_UNHOOK
:unhook
Definition command.h:135
enum CommandResult parse_pattern_hook(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse pattern-based Hook commands - Implements Command::parse() -.
Definition parse.c:176
enum CommandResult parse_folder_hook(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse folder hook command - Implements Command::parse() -.
Definition parse.c:524
enum CommandResult parse_regex_hook(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse regex-based hook command - Implements Command::parse() -.
Definition parse.c:427
enum CommandResult parse_hooks(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'hooks' command - Implements Command::parse() -.
Definition dump.c:227
enum CommandResult parse_unhook(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the unhook command - Implements Command::parse() -.
Definition parse.c:1192
enum CommandResult parse_crypt_hook(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse crypt hook commands - Implements Command::parse() -.
Definition parse.c:665
enum CommandResult parse_mailbox_hook(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse mailbox pattern hook commands - Implements Command::parse() -.
Definition parse.c:348
enum CommandResult parse_charset_hook(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse charset Hook commands - Implements Command::parse() -.
Definition parse.c:56
enum CommandResult parse_mbox_hook(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse mbox hook command - Implements Command::parse() -.
Definition parse.c:762
enum CommandResult parse_global_hook(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse global Hook commands - Implements Command::parse() -.
Definition parse.c:110
enum CommandResult parse_index_hook(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the index format hook command - Implements Command::parse() -.
Definition parse.c:1068
#define N_(a)
Definition message.h:32

◆ ModuleHooks

const struct Module ModuleHooks
Initial value:
= {
"hooks",
NULL,
NULL,
NULL,
}
static bool hooks_commands_register(struct NeoMutt *n, struct CommandArray *ca)
Register NeoMutt Commands - Implements Module::commands_register()
Definition module.c:68
static bool hooks_cleanup(struct NeoMutt *n, void *data)
Clean up a Module - Implements Module::cleanup()
Definition module.c:76
static bool hooks_init(struct NeoMutt *n)
Initialise a Module - Implements Module::init()
Definition module.c:45
static bool hooks_config_define_variables(struct NeoMutt *n, struct ConfigSet *cs)
Define the Config Variables - Implements Module::config_define_variables()
Definition module.c:60

Module for the Hooks library.

Definition at line 92 of file module.c.

92 {
94 "hooks",
96 NULL, // config_define_types
99 NULL, // gui_init
100 NULL, // gui_cleanup
102};