2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2002 Michael R. Elkins <me@mutt.org>, and others
5 * This file is part of mutt-ng, see http://www.muttng.org/.
6 * It's licensed under the GNU General Public License,
7 * please see the file GPL in the top level source directory.
10 #include <lib-lib/lib-lib.h>
11 #include <lib-lua/lib-lua.h>
12 #include <lib-ui/lib-ui.h>
13 #include <lib-mx/mx.h>
14 #include <lib-mx/compress.h>
20 typedef struct hook_t {
21 int type; /* hook type */
22 rx_t rx; /* regular expression */
23 char *command; /* filename, command or pattern to execute */
24 pattern_t *pattern; /* used for fcc,save,send-hook */
28 DO_INIT(hook_t, hook);
29 static inline void hook_wipe(hook_t *hk) {
30 p_delete(&hk->command);
31 pattern_list_wipe(&hk->pattern);
34 DO_DELETE(hook_t, hook);
35 DO_SLIST(hook_t, hook, hook_delete);
37 static hook_t *Hooks = NULL;
38 static unsigned long current_hook_type = 0;
40 /* Deletes all hooks of type ``type'', or all defined hooks if ``type'' is 0 */
41 void mutt_folder_hook (char *path)
43 lua_State *L = luaM_getruntime();
44 lua_getglobal(L, "mod_core"); /* push mod_core 1 */
45 lua_getfield(L, -1, "folder_hook"); /* push folder_hook() 2 */
46 if (lua_isfunction(L, -1)) {
47 lua_pushstring(L, LastFolder);
48 lua_pushstring(L, CurrentFolder);
49 if (lua_pcall(L, 2, 0, 0)) {
57 void mutt_message_hook (CONTEXT * ctx, HEADER * hdr, int type)
63 current_hook_type = type;
66 err.dsize = sizeof (buf);
68 for (hook = Hooks; hook; hook = hook->next) {
72 if (hook->type & type)
73 if ((mutt_pattern_exec (hook->pattern, 0, ctx, hdr) > 0) ^ hook->rx.neg)
74 if (mutt_parse_rc_line (hook->command, &token, &err) != 0) {
75 mutt_error ("%s", err.data);
79 p_delete(&token.data);
80 current_hook_type = 0;
83 void mutt_default_save (char *path, ssize_t pathlen, HEADER * hdr)
85 char tmp[_POSIX_PATH_MAX];
87 ENVELOPE *env = hdr->env;
88 int fromMe = mutt_addr_is_user (env->from);
90 if (!fromMe && env->reply_to && env->reply_to->mailbox)
92 else if (!fromMe && env->from && env->from->mailbox)
94 else if (env->to && env->to->mailbox)
96 else if (env->cc && env->cc->mailbox)
101 mutt_safe_path (tmp, sizeof (tmp), adr);
102 snprintf (path, pathlen, "=%s", tmp);
108 void mutt_select_fcc (char *path, ssize_t pathlen, HEADER * hdr)
110 m_strcpy(path, pathlen, NONULL(MAlias.record));
111 mutt_pretty_mailbox(path);