NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
hook.h File Reference

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

#include "config.h"
#include <stdint.h>
#include <stdio.h>
#include "mutt_commands.h"
+ Include dependency graph for hook.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MUTT_HOOK_NO_FLAGS   0
 No flags are set. More...
 
#define MUTT_FOLDER_HOOK   (1 << 0)
 folder-hook: when entering a mailbox More...
 
#define MUTT_MBOX_HOOK   (1 << 1)
 mbox-hook: move messages after reading them More...
 
#define MUTT_SEND_HOOK   (1 << 2)
 send-hook: when composing a new email More...
 
#define MUTT_FCC_HOOK   (1 << 3)
 fcc-hook: to save outgoing email More...
 
#define MUTT_SAVE_HOOK   (1 << 4)
 save-hook: set a default folder when saving an email More...
 
#define MUTT_CHARSET_HOOK   (1 << 5)
 charset-hook: create a charset alias for malformed emails More...
 
#define MUTT_ICONV_HOOK   (1 << 6)
 iconv-hook: create a system charset alias More...
 
#define MUTT_MESSAGE_HOOK   (1 << 7)
 message-hook: run before displaying a message More...
 
#define MUTT_CRYPT_HOOK   (1 << 8)
 crypt-hook: automatically select a PGP/SMIME key More...
 
#define MUTT_ACCOUNT_HOOK   (1 << 9)
 account-hook: when changing between accounts More...
 
#define MUTT_REPLY_HOOK   (1 << 10)
 reply-hook: when replying to an email More...
 
#define MUTT_SEND2_HOOK   (1 << 11)
 send2-hook: when changing fields in the compose menu More...
 
#define MUTT_OPEN_HOOK   (1 << 12)
 open-hook: to read a compressed mailbox More...
 
#define MUTT_APPEND_HOOK   (1 << 13)
 append-hook: append to a compressed mailbox More...
 
#define MUTT_CLOSE_HOOK   (1 << 14)
 close-hook: write to a compressed mailbox More...
 
#define MUTT_IDXFMTHOOK   (1 << 15)
 index-format-hook: customise the format of the index More...
 
#define MUTT_TIMEOUT_HOOK   (1 << 16)
 timeout-hook: run a command periodically More...
 
#define MUTT_STARTUP_HOOK   (1 << 17)
 startup-hook: run when starting NeoMutt More...
 
#define MUTT_SHUTDOWN_HOOK   (1 << 18)
 shutdown-hook: run when leaving NeoMutt More...
 
#define MUTT_GLOBAL_HOOK   (1 << 19)
 Hooks which don't take a regex. More...
 

Typedefs

typedef uint32_t HookFlags
 Flags for mutt_parse_hook(), e.g. MUTT_FOLDER_HOOK. More...
 

Functions

void mutt_account_hook (const char *url)
 Perform an account hook. More...
 
void mutt_crypt_hook (struct ListHead *list, struct Address *addr)
 Find crypto hooks for an Address. More...
 
void mutt_default_save (char *path, size_t pathlen, struct Email *e)
 Find the default save path for an email. More...
 
void mutt_delete_hooks (HookFlags type)
 Delete matching hooks. More...
 
char * mutt_find_hook (HookFlags type, const char *pat)
 Find a matching hook. More...
 
void mutt_folder_hook (const char *path, const char *desc)
 Perform a folder hook. More...
 
const char * mutt_idxfmt_hook (const char *name, struct Mailbox *m, struct Email *e)
 Get index-format-hook format string. More...
 
void mutt_message_hook (struct Mailbox *m, struct Email *e, HookFlags type)
 Perform a message hook. 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...
 
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() -This is used by 'account-hook', 'append-hook' and many more. 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_select_fcc (struct Buffer *path, struct Email *e)
 Select the FCC path for an email. More...
 
void mutt_startup_shutdown_hook (HookFlags type)
 Execute any startup/shutdown hooks. More...
 
void mutt_timeout_hook (void)
 Execute any timeout hooks. More...
 

Detailed Description

Parse and execute user-defined hooks.

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 hook.h.

Macro Definition Documentation

◆ MUTT_HOOK_NO_FLAGS

#define MUTT_HOOK_NO_FLAGS   0

No flags are set.

Definition at line 38 of file hook.h.

◆ MUTT_FOLDER_HOOK

#define MUTT_FOLDER_HOOK   (1 << 0)

folder-hook: when entering a mailbox

Definition at line 39 of file hook.h.

◆ MUTT_MBOX_HOOK

#define MUTT_MBOX_HOOK   (1 << 1)

mbox-hook: move messages after reading them

Definition at line 40 of file hook.h.

◆ MUTT_SEND_HOOK

#define MUTT_SEND_HOOK   (1 << 2)

send-hook: when composing a new email

Definition at line 41 of file hook.h.

◆ MUTT_FCC_HOOK

#define MUTT_FCC_HOOK   (1 << 3)

fcc-hook: to save outgoing email

Definition at line 42 of file hook.h.

◆ MUTT_SAVE_HOOK

#define MUTT_SAVE_HOOK   (1 << 4)

save-hook: set a default folder when saving an email

Definition at line 43 of file hook.h.

◆ MUTT_CHARSET_HOOK

#define MUTT_CHARSET_HOOK   (1 << 5)

charset-hook: create a charset alias for malformed emails

Definition at line 44 of file hook.h.

◆ MUTT_ICONV_HOOK

#define MUTT_ICONV_HOOK   (1 << 6)

iconv-hook: create a system charset alias

Definition at line 45 of file hook.h.

◆ MUTT_MESSAGE_HOOK

#define MUTT_MESSAGE_HOOK   (1 << 7)

message-hook: run before displaying a message

Definition at line 46 of file hook.h.

◆ MUTT_CRYPT_HOOK

#define MUTT_CRYPT_HOOK   (1 << 8)

crypt-hook: automatically select a PGP/SMIME key

Definition at line 47 of file hook.h.

◆ MUTT_ACCOUNT_HOOK

#define MUTT_ACCOUNT_HOOK   (1 << 9)

account-hook: when changing between accounts

Definition at line 48 of file hook.h.

◆ MUTT_REPLY_HOOK

#define MUTT_REPLY_HOOK   (1 << 10)

reply-hook: when replying to an email

Definition at line 49 of file hook.h.

◆ MUTT_SEND2_HOOK

#define MUTT_SEND2_HOOK   (1 << 11)

send2-hook: when changing fields in the compose menu

Definition at line 50 of file hook.h.

◆ MUTT_OPEN_HOOK

#define MUTT_OPEN_HOOK   (1 << 12)

open-hook: to read a compressed mailbox

Definition at line 52 of file hook.h.

◆ MUTT_APPEND_HOOK

#define MUTT_APPEND_HOOK   (1 << 13)

append-hook: append to a compressed mailbox

Definition at line 53 of file hook.h.

◆ MUTT_CLOSE_HOOK

#define MUTT_CLOSE_HOOK   (1 << 14)

close-hook: write to a compressed mailbox

Definition at line 54 of file hook.h.

◆ MUTT_IDXFMTHOOK

#define MUTT_IDXFMTHOOK   (1 << 15)

index-format-hook: customise the format of the index

Definition at line 56 of file hook.h.

◆ MUTT_TIMEOUT_HOOK

#define MUTT_TIMEOUT_HOOK   (1 << 16)

timeout-hook: run a command periodically

Definition at line 57 of file hook.h.

◆ MUTT_STARTUP_HOOK

#define MUTT_STARTUP_HOOK   (1 << 17)

startup-hook: run when starting NeoMutt

Definition at line 58 of file hook.h.

◆ MUTT_SHUTDOWN_HOOK

#define MUTT_SHUTDOWN_HOOK   (1 << 18)

shutdown-hook: run when leaving NeoMutt

Definition at line 59 of file hook.h.

◆ MUTT_GLOBAL_HOOK

#define MUTT_GLOBAL_HOOK   (1 << 19)

Hooks which don't take a regex.

Definition at line 60 of file hook.h.

Typedef Documentation

◆ HookFlags

typedef uint32_t HookFlags

Flags for mutt_parse_hook(), e.g. MUTT_FOLDER_HOOK.

Definition at line 35 of file hook.h.

Function Documentation

◆ mutt_account_hook()

void mutt_account_hook ( const char *  url)

Perform an account hook.

Parameters
urlAccount URL to match

Definition at line 782 of file hook.c.

783 {
784  /* parsing commands with URLs in an account hook can cause a recursive
785  * call. We just skip processing if this occurs. Typically such commands
786  * belong in a folder-hook -- perhaps we should warn the user. */
787  static bool inhook = false;
788  if (inhook)
789  return;
790 
791  struct Hook *hook = NULL;
792  struct Buffer *err = mutt_buffer_pool_get();
793 
794  TAILQ_FOREACH(hook, &Hooks, entries)
795  {
796  if (!(hook->command && (hook->type & MUTT_ACCOUNT_HOOK)))
797  continue;
798 
799  if (mutt_regex_match(&hook->regex, url))
800  {
801  inhook = true;
802  mutt_debug(LL_DEBUG1, "account-hook '%s' matches '%s'\n", hook->regex.pattern, url);
803  mutt_debug(LL_DEBUG5, " %s\n", hook->command);
804 
805  if (mutt_parse_rc_line(hook->command, err) == MUTT_CMD_ERROR)
806  {
807  mutt_error("%s", mutt_buffer_string(err));
809 
810  inhook = false;
811  goto done;
812  }
813 
814  inhook = false;
815  }
816  }
817 done:
819 }
static struct HookList Hooks
Definition: hook.c:72
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
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
#define mutt_error(...)
Definition: logging.h:88
HookFlags type
Hook type.
Definition: hook.c:64
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
String manipulation buffer.
Definition: buffer.h:33
A list of user hooks.
Definition: hook.c:62
enum CommandResult mutt_parse_rc_line(const char *line, struct Buffer *err)
Parse a line of user config.
Definition: init.c:1039
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
char * command
Filename, command or pattern to execute.
Definition: hook.c:66
struct Regex regex
Regular expression.
Definition: hook.c:65
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
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:613
char * pattern
printable version
Definition: regex3.h:91
Log at debug level 5.
Definition: logging.h:44
#define MUTT_ACCOUNT_HOOK
account-hook: when changing between accounts
Definition: hook.h:48
+ 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 773 of file hook.c.

774 {
775  list_hook(list, addr->mailbox, MUTT_CRYPT_HOOK);
776 }
char * mailbox
Mailbox and host address.
Definition: address.h:38
static void list_hook(struct ListHead *matches, const char *match, HookFlags hook)
Find hook strings matching.
Definition: hook.c:753
#define MUTT_CRYPT_HOOK
crypt-hook: automatically select a PGP/SMIME key
Definition: hook.h:47
+ 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 677 of file hook.c.

678 {
679  *path = '\0';
680  if (addr_hook(path, pathlen, MUTT_SAVE_HOOK, ctx_mailbox(Context), e) == 0)
681  return;
682 
683  struct Envelope *env = e->env;
684  const struct Address *from = TAILQ_FIRST(&env->from);
685  const struct Address *reply_to = TAILQ_FIRST(&env->reply_to);
686  const struct Address *to = TAILQ_FIRST(&env->to);
687  const struct Address *cc = TAILQ_FIRST(&env->cc);
688  const struct Address *addr = NULL;
689  bool from_me = mutt_addr_is_user(from);
690 
691  if (!from_me && reply_to && reply_to->mailbox)
692  addr = reply_to;
693  else if (!from_me && from && from->mailbox)
694  addr = from;
695  else if (to && to->mailbox)
696  addr = to;
697  else if (cc && cc->mailbox)
698  addr = cc;
699  else
700  addr = NULL;
701  if (addr)
702  {
703  struct Buffer *tmp = mutt_buffer_pool_get();
704  mutt_safe_path(tmp, addr);
705  snprintf(path, pathlen, "=%s", mutt_buffer_string(tmp));
707  }
708 }
The "current" mailbox.
Definition: context.h:37
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define TAILQ_FIRST(head)
Definition: queue.h:723
struct Mailbox * ctx_mailbox(struct Context *ctx)
wrapper to get the mailbox in a Context, or NULL
Definition: context.c:444
struct AddressList reply_to
Email&#39;s &#39;reply-to&#39;.
Definition: envelope.h:62
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
String manipulation buffer.
Definition: buffer.h:33
An email address.
Definition: address.h:35
char * mailbox
Mailbox and host address.
Definition: address.h:38
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
struct AddressList from
Email&#39;s &#39;From&#39; list.
Definition: envelope.h:57
struct Envelope * env
Envelope information.
Definition: email.h:90
struct AddressList cc
Email&#39;s &#39;Cc&#39; list.
Definition: envelope.h:59
void mutt_safe_path(struct Buffer *dest, const struct Address *a)
Make a safe filename from an email address.
Definition: muttlib.c:761
#define MUTT_SAVE_HOOK
save-hook: set a default folder when saving an email
Definition: hook.h:43
bool mutt_addr_is_user(const struct Address *addr)
Does the address belong to the user.
Definition: alias.c:562
struct AddressList to
Email&#39;s &#39;To&#39; list.
Definition: envelope.h:58
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:645
The header of an Email.
Definition: envelope.h:54
+ 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 328 of file hook.c.

329 {
330  struct Hook *h = NULL;
331  struct Hook *tmp = NULL;
332 
333  TAILQ_FOREACH_SAFE(h, &Hooks, entries, tmp)
334  {
335  if ((type == MUTT_HOOK_NO_FLAGS) || (type == h->type))
336  {
337  TAILQ_REMOVE(&Hooks, h, entries);
338  delete_hook(h);
339  }
340  }
341 }
static struct HookList Hooks
Definition: hook.c:72
HookFlags type
Hook type.
Definition: hook.c:64
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:735
A list of user hooks.
Definition: hook.c:62
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
#define MUTT_HOOK_NO_FLAGS
No flags are set.
Definition: hook.h:38
static void delete_hook(struct Hook *h)
Delete a Hook.
Definition: hook.c:309
+ 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 577 of file hook.c.

578 {
579  struct Hook *tmp = NULL;
580 
581  TAILQ_FOREACH(tmp, &Hooks, entries)
582  {
583  if (tmp->type & type)
584  {
585  if (mutt_regex_match(&tmp->regex, pat))
586  return tmp->command;
587  }
588  }
589  return NULL;
590 }
static struct HookList Hooks
Definition: hook.c:72
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
HookFlags type
Hook type.
Definition: hook.c:64
A list of user hooks.
Definition: hook.c:62
char * command
Filename, command or pattern to execute.
Definition: hook.c:66
struct Regex regex
Regular expression.
Definition: hook.c:65
bool mutt_regex_match(const struct Regex *regex, const char *str)
Shorthand to mutt_regex_capture()
Definition: regex.c:613
+ 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 529 of file hook.c.

530 {
531  if (!path && !desc)
532  return;
533 
534  struct Hook *hook = NULL;
535  struct Buffer *err = mutt_buffer_pool_get();
536 
538 
539  TAILQ_FOREACH(hook, &Hooks, entries)
540  {
541  if (!hook->command)
542  continue;
543 
544  if (!(hook->type & MUTT_FOLDER_HOOK))
545  continue;
546 
547  const char *match = NULL;
548  if (mutt_regex_match(&hook->regex, path))
549  match = path;
550  else if (mutt_regex_match(&hook->regex, desc))
551  match = desc;
552 
553  if (match)
554  {
555  mutt_debug(LL_DEBUG1, "folder-hook '%s' matches '%s'\n", hook->regex.pattern, match);
556  mutt_debug(LL_DEBUG5, " %s\n", hook->command);
557  if (mutt_parse_rc_line(hook->command, err) == MUTT_CMD_ERROR)
558  {
559  mutt_error("%s", mutt_buffer_string(err));
560  break;
561  }
562  }
563  }
565 
567 }
static struct HookList Hooks
Definition: hook.c:72
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
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
#define mutt_error(...)
Definition: logging.h:88
HookFlags type
Hook type.
Definition: hook.c:64
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
static HookFlags current_hook_type
Definition: hook.c:75
String manipulation buffer.
Definition: buffer.h:33
A list of user hooks.
Definition: hook.c:62
enum CommandResult mutt_parse_rc_line(const char *line, struct Buffer *err)
Parse a line of user config.
Definition: init.c:1039
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
char * command
Filename, command or pattern to execute.
Definition: hook.c:66
struct Regex regex
Regular expression.
Definition: hook.c:65
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
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:613
#define MUTT_HOOK_NO_FLAGS
No flags are set.
Definition: hook.h:38
char * pattern
printable version
Definition: regex3.h:91
Log at debug level 5.
Definition: logging.h:44
#define MUTT_FOLDER_HOOK
folder-hook: when entering a mailbox
Definition: hook.h:39
+ 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 893 of file hook.c.

894 {
895  if (!IdxFmtHooks)
896  return NULL;
897 
898  struct HookList *hl = mutt_hash_find(IdxFmtHooks, name);
899  if (!hl)
900  return NULL;
901 
903 
904  struct PatternCache cache = { 0 };
905  const char *fmtstring = NULL;
906  struct Hook *hook = NULL;
907 
908  TAILQ_FOREACH(hook, hl, entries)
909  {
910  struct Pattern *pat = SLIST_FIRST(hook->pattern);
911  if ((mutt_pattern_exec(pat, 0, m, e, &cache) > 0) ^ hook->regex.pat_not)
912  {
913  fmtstring = hook->command;
914  break;
915  }
916  }
917 
919 
920  return fmtstring;
921 }
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:354
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
static HookFlags current_hook_type
Definition: hook.c:75
bool pat_not
do not match
Definition: regex3.h:93
A list of user hooks.
Definition: hook.c:62
#define MUTT_IDXFMTHOOK
index-format-hook: customise the format of the index
Definition: hook.h:56
A simple (non-regex) pattern.
Definition: lib.h:68
char * command
Filename, command or pattern to execute.
Definition: hook.c:66
struct Regex regex
Regular expression.
Definition: hook.c:65
#define SLIST_FIRST(head)
Definition: queue.h:229
int 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:1097
static struct HashTable * IdxFmtHooks
Definition: hook.c:74
#define MUTT_HOOK_NO_FLAGS
No flags are set.
Definition: hook.h:38
Cache commonly-used patterns.
Definition: lib.h:105
struct PatternList * pattern
Used for fcc,save,send-hook.
Definition: hook.c:67
+ 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 Context
eEmail
typeHook type, see HookFlags

Definition at line 598 of file hook.c.

599 {
600  struct Hook *hook = NULL;
601  struct PatternCache cache = { 0 };
602  struct Buffer *err = mutt_buffer_pool_get();
603 
604  current_hook_type = type;
605 
606  TAILQ_FOREACH(hook, &Hooks, entries)
607  {
608  if (!hook->command)
609  continue;
610 
611  if (hook->type & type)
612  {
613  if ((mutt_pattern_exec(SLIST_FIRST(hook->pattern), 0, m, e, &cache) > 0) ^
614  hook->regex.pat_not)
615  {
616  if (mutt_parse_rc_line(hook->command, err) == MUTT_CMD_ERROR)
617  {
618  mutt_error("%s", mutt_buffer_string(err));
621 
622  return;
623  }
624  /* Executing arbitrary commands could affect the pattern results,
625  * so the cache has to be wiped */
626  memset(&cache, 0, sizeof(cache));
627  }
628  }
629  }
631 
633 }
static struct HookList Hooks
Definition: hook.c:72
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
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
#define mutt_error(...)
Definition: logging.h:88
HookFlags type
Hook type.
Definition: hook.c:64
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
static HookFlags current_hook_type
Definition: hook.c:75
String manipulation buffer.
Definition: buffer.h:33
bool pat_not
do not match
Definition: regex3.h:93
A list of user hooks.
Definition: hook.c:62
enum CommandResult mutt_parse_rc_line(const char *line, struct Buffer *err)
Parse a line of user config.
Definition: init.c:1039
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
char * command
Filename, command or pattern to execute.
Definition: hook.c:66
struct Regex regex
Regular expression.
Definition: hook.c:65
#define SLIST_FIRST(head)
Definition: queue.h:229
int 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:1097
#define MUTT_HOOK_NO_FLAGS
No flags are set.
Definition: hook.h:38
Cache commonly-used patterns.
Definition: lib.h:105
struct PatternList * pattern
Used for fcc,save,send-hook.
Definition: hook.c:67
+ 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 715 of file hook.c.

716 {
718 
719  if (addr_hook(path->data, path->dsize, MUTT_FCC_HOOK, NULL, e) != 0)
720  {
721  const struct Address *to = TAILQ_FIRST(&e->env->to);
722  const struct Address *cc = TAILQ_FIRST(&e->env->cc);
723  const struct Address *bcc = TAILQ_FIRST(&e->env->bcc);
724  const bool c_save_name = cs_subset_bool(NeoMutt->sub, "save_name");
725  const bool c_force_name = cs_subset_bool(NeoMutt->sub, "force_name");
726  const char *const c_record = cs_subset_string(NeoMutt->sub, "record");
727  if ((c_save_name || c_force_name) && (to || cc || bcc))
728  {
729  const struct Address *addr = to ? to : (cc ? cc : bcc);
730  struct Buffer *buf = mutt_buffer_pool_get();
731  mutt_safe_path(buf, addr);
732  const char *const c_folder = cs_subset_string(NeoMutt->sub, "folder");
733  mutt_buffer_concat_path(path, NONULL(c_folder), mutt_buffer_string(buf));
735  if (!c_force_name && (mx_access(mutt_buffer_string(path), W_OK) != 0))
736  mutt_buffer_strcpy(path, c_record);
737  }
738  else
739  mutt_buffer_strcpy(path, c_record);
740  }
741  else
742  mutt_buffer_fix_dptr(path);
743 
745 }
#define NONULL(x)
Definition: string2.h:37
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define TAILQ_FIRST(head)
Definition: queue.h:723
struct AddressList bcc
Email&#39;s &#39;Bcc&#39; list.
Definition: envelope.h:60
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
String manipulation buffer.
Definition: buffer.h:33
An email address.
Definition: address.h:35
Container for Accounts, Notifications.
Definition: neomutt.h:36
void mutt_buffer_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using &#39;~&#39; or &#39;=&#39;.
Definition: muttlib.c:603
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
size_t dsize
Length of data.
Definition: buffer.h:37
struct Envelope * env
Envelope information.
Definition: email.h:90
struct AddressList cc
Email&#39;s &#39;Cc&#39; list.
Definition: envelope.h:59
void mutt_buffer_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition: buffer.c:181
void mutt_safe_path(struct Buffer *dest, const struct Address *a)
Make a safe filename from an email address.
Definition: muttlib.c:761
#define PATH_MAX
Definition: mutt.h:40
char * data
Pointer to data.
Definition: buffer.h:35
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
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:374
int mx_access(const char *path, int flags)
Wrapper for access, checks permissions on a given mailbox.
Definition: mx.c:184
struct AddressList to
Email&#39;s &#39;To&#39; list.
Definition: envelope.h:58
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
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:645
#define MUTT_FCC_HOOK
fcc-hook: to save outgoing email
Definition: hook.h:42
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:265
+ 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 863 of file hook.c.

864 {
865  struct Hook *hook = NULL;
866  struct Buffer err = mutt_buffer_make(0);
867  char buf[256];
868 
869  err.data = buf;
870  err.dsize = sizeof(buf);
871 
872  TAILQ_FOREACH(hook, &Hooks, entries)
873  {
874  if (!(hook->command && (hook->type & type)))
875  continue;
876 
877  if (mutt_parse_rc_line(hook->command, &err) == MUTT_CMD_ERROR)
878  {
879  mutt_error("%s", err.data);
880  mutt_buffer_reset(&err);
881  }
882  }
883 }
static struct HookList Hooks
Definition: hook.c:72
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
#define mutt_error(...)
Definition: logging.h:88
HookFlags type
Hook type.
Definition: hook.c:64
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
String manipulation buffer.
Definition: buffer.h:33
A list of user hooks.
Definition: hook.c:62
enum CommandResult mutt_parse_rc_line(const char *line, struct Buffer *err)
Parse a line of user config.
Definition: init.c:1039
char * command
Filename, command or pattern to execute.
Definition: hook.c:66
size_t dsize
Length of data.
Definition: buffer.h:37
char * data
Pointer to data.
Definition: buffer.h:35
+ 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 827 of file hook.c.

828 {
829  struct Hook *hook = NULL;
830  struct Buffer err;
831  char buf[256];
832 
833  mutt_buffer_init(&err);
834  err.data = buf;
835  err.dsize = sizeof(buf);
836 
837  TAILQ_FOREACH(hook, &Hooks, entries)
838  {
839  if (!(hook->command && (hook->type & MUTT_TIMEOUT_HOOK)))
840  continue;
841 
842  if (mutt_parse_rc_line(hook->command, &err) == MUTT_CMD_ERROR)
843  {
844  mutt_error("%s", err.data);
845  mutt_buffer_reset(&err);
846 
847  /* The hooks should be independent of each other, so even though this on
848  * failed, we'll carry on with the others. */
849  }
850  }
851 
852  /* Delete temporary attachment files */
854 }
static struct HookList Hooks
Definition: hook.c:72
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
#define mutt_error(...)
Definition: logging.h:88
HookFlags type
Hook type.
Definition: hook.c:64
String manipulation buffer.
Definition: buffer.h:33
A list of user hooks.
Definition: hook.c:62
enum CommandResult mutt_parse_rc_line(const char *line, struct Buffer *err)
Parse a line of user config.
Definition: init.c:1039
void mutt_unlink_temp_attachments(void)
Delete all temporary attachments.
Definition: mutt_attach.c:1275
char * command
Filename, command or pattern to execute.
Definition: hook.c:66
#define MUTT_TIMEOUT_HOOK
timeout-hook: run a command periodically
Definition: hook.h:57
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function: