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>
21 typedef struct hook_t {
22 int type; /* hook type */
23 rx_t rx; /* regular expression */
24 char *command; /* filename, command or pattern to execute */
25 pattern_t *pattern; /* used for fcc,save,send-hook */
29 DO_INIT(hook_t, hook);
30 static inline void hook_wipe(hook_t *hk) {
31 p_delete(&hk->command);
32 pattern_list_wipe(&hk->pattern);
35 DO_DELETE(hook_t, hook);
36 DO_SLIST(hook_t, hook, hook_delete);
38 static hook_t *Hooks = NULL;
39 static unsigned long current_hook_type = 0;
42 void mutt_message_hook (CONTEXT * ctx, HEADER * hdr, int type)
49 current_hook_type = type;
52 err.dsize = sizeof (buf);
54 for (hook = Hooks; hook; hook = hook->next) {
58 if (hook->type & type)
59 if ((mutt_pattern_exec (hook->pattern, 0, ctx, hdr) > 0) ^ hook->rx.neg)
60 if (mutt_parse_rc_line (hook->command, &token, &err) != 0) {
61 mutt_error ("%s", err.data);
65 p_delete(&token.data);
66 current_hook_type = 0;
70 /* Deletes all hooks of type ``type'', or all defined hooks if ``type'' is 0 */
71 void mutt_folder_hook (char *path)
73 lua_State *L = luaM_getruntime();
74 lua_getglobal(L, "mod_core"); /* push mod_core 1 */
75 lua_getfield(L, -1, "folder_hook"); /* push folder_hook() 2 */
76 if (lua_isfunction(L, -1)) {
77 lua_pushstring(L, LastFolder);
78 lua_pushstring(L, CurrentFolder);
79 if (lua_pcall(L, 2, 0, 0)) {
87 void mutt_default_save (char *path, ssize_t pathlen, HEADER * hdr)
89 char tmp[_POSIX_PATH_MAX];
91 ENVELOPE *env = hdr->env;
92 int fromMe = mutt_addr_is_user (env->from);
94 if (!fromMe && env->reply_to && env->reply_to->mailbox)
96 else if (!fromMe && env->from && env->from->mailbox)
98 else if (env->to && env->to->mailbox)
100 else if (env->cc && env->cc->mailbox)
105 mutt_safe_path (tmp, sizeof (tmp), adr);
106 snprintf (path, pathlen, "=%s", tmp);