Subject says it all (I think). There is one hook, compose-hook, to be invoked right before send.c::send_message_setup() in send.c::mutt_send_message(), that I'd like to be able to use, but I have no idea which arguments mutt_message_hook() will receive that early in the sequence.
From 963497984cdeaee19187fb18fadc657b50d85cfd Mon Sep 17 00:00:00 2001 From: Mono DHS <mono...@arcor.de> Date: Sat, 25 Jul 2020 16:03:54 +0200 Subject: [PATCH] Introduce message disposition hooks for elaborate state management in Mutt.
--- doc/manual.xml.head | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++-- hook.c | 10 +++-- init.h | 8 +++- mutt.h | 4 ++ send.c | 12 ++++- 5 files changed, 152 insertions(+), 9 deletions(-) diff --git a/doc/manual.xml.head b/doc/manual.xml.head index 5276953059e453592c2832db5abed4ec6a500395..9cda87fdcba09bed3e27bb76298839f39966d30b 100644 --- a/doc/manual.xml.head +++ b/doc/manual.xml.head @@ -4001,6 +4001,10 @@ use separate fcc and save hooks in that case. <anchor id="reply-hook"/> <anchor id="send2-hook"/> +<anchor id="sent-hook"/> +<anchor id="aborted-hook"/> +<anchor id="postponed-hook"/> +<anchor id="backgrounded-hook"/> <para>Usage:</para> @@ -4028,6 +4032,38 @@ use separate fcc and save hooks in that case. <arg choice="plain"> <replaceable class="parameter">command</replaceable> </arg> + +<command>sent-hook</command> +<arg choice="plain"> +<replaceable class="parameter">[!]pattern</replaceable> +</arg> +<arg choice="plain"> +<replaceable class="parameter">command</replaceable> +</arg> + +<command>aborted-hook</command> +<arg choice="plain"> +<replaceable class="parameter">[!]pattern</replaceable> +</arg> +<arg choice="plain"> +<replaceable class="parameter">command</replaceable> +</arg> + +<command>postponed-hook</command> +<arg choice="plain"> +<replaceable class="parameter">[!]pattern</replaceable> +</arg> +<arg choice="plain"> +<replaceable class="parameter">command</replaceable> +</arg> + +<command>backgrounded-hook</command> +<arg choice="plain"> +<replaceable class="parameter">[!]pattern</replaceable> +</arg> +<arg choice="plain"> +<replaceable class="parameter">command</replaceable> +</arg> </cmdsynopsis> <para> @@ -4068,8 +4104,20 @@ variable depending on the message's sender address. </para> <para> -For each type of <command>send-hook</command> or -<command>reply-hook</command>, when multiple matches occur, commands are +The message disposition hooks +<command>sent-hook</command>, +<command>aborted-hook</command>, +<command>postponed-hook</command>, and +<command>backgrounded-hook</command> +are matched every time a message is successfully sent, +composition of a message is aborted or an error occurred therein, +postponed, or backgrounded, respectively. +</para> + +<para> +For each type of <command>send-hook</command>, +<command>reply-hook</command>, or +message disposition hook, when multiple matches occur, commands are executed in the order they are specified in the <literal>.muttrc</literal> (for that type of hook). </para> @@ -6303,6 +6351,30 @@ option/command. See: </para> </listitem> +<listitem> +<para> +<link linkend="sent-hook"><command>sent-hook</command></link> +</para> +</listitem> + +<listitem> +<para> +<link linkend="aborted-hook"><command>aborted-hook</command></link> +</para> +</listitem> + +<listitem> +<para> +<link linkend="postponed-hook"><command>postponed-hook</command></link> +</para> +</listitem> + +<listitem> +<para> +<link linkend="backgrounded-hook"><command>backgrounded-hook</command></link> +</para> +</listitem> + </itemizedlist> for specific details on each type of <emphasis>hook</emphasis> available. @@ -6342,7 +6414,8 @@ From: header is changed to <literal><c@c.c></literal>. Hooks that act upon messages (<command>message-hook</command>, <command>reply-hook</command>, <command>send-hook</command>, <command>send2-hook</command>, <command>save-hook</command>, -<command>fcc-hook</command>, <command>index-format-hook</command>) +<command>fcc-hook</command>, <command>index-format-hook</command>, +and <link linkend="sent-hook">the message disposition hooks</link>) are evaluated in a slightly different manner. For the other types of hooks, a <link linkend="regexp">regular expression</link> is sufficient. But in dealing with messages a finer @@ -10668,6 +10741,18 @@ The following are the commands understood by Mutt: <listitem> <cmdsynopsis> +<command><link linkend="aborted-hook">aborted-hook</link></command> +<arg choice="plain"> +<replaceable class="parameter">[!]pattern</replaceable> +</arg> +<arg choice="plain"> +<replaceable class="parameter">command</replaceable> +</arg> +</cmdsynopsis> +</listitem> + +<listitem> +<cmdsynopsis> <command><link linkend="account-hook">account-hook</link></command> <arg choice="plain"> <replaceable>regexp</replaceable> @@ -10812,6 +10897,18 @@ The following are the commands understood by Mutt: <listitem> <cmdsynopsis> +<command><link linkend="backgrounded-hook">backgrounded-hook</link></command> +<arg choice="plain"> +<replaceable class="parameter">[!]pattern</replaceable> +</arg> +<arg choice="plain"> +<replaceable class="parameter">command</replaceable> +</arg> +</cmdsynopsis> +</listitem> + +<listitem> +<cmdsynopsis> <command><link linkend="bind">bind</link></command> <arg choice="plain"> <replaceable class="parameter">map</replaceable> @@ -11360,6 +11457,18 @@ The following are the commands understood by Mutt: <listitem> <cmdsynopsis> +<command><link linkend="postponed-hook">postponed-hook</link></command> +<arg choice="plain"> +<replaceable class="parameter">[!]pattern</replaceable> +</arg> +<arg choice="plain"> +<replaceable class="parameter">command</replaceable> +</arg> +</cmdsynopsis> +</listitem> + +<listitem> +<cmdsynopsis> <command><link linkend="push">push</link></command> <arg choice="plain"> <replaceable class="parameter">string</replaceable> @@ -11439,6 +11548,18 @@ The following are the commands understood by Mutt: <listitem> <cmdsynopsis> +<command><link linkend="sent-hook">sent-hook</link></command> +<arg choice="plain"> +<replaceable class="parameter">[!]pattern</replaceable> +</arg> +<arg choice="plain"> +<replaceable class="parameter">command</replaceable> +</arg> +</cmdsynopsis> +</listitem> + +<listitem> +<cmdsynopsis> <command><link linkend="set">set</link></command> <group choice="req"> <arg choice="plain"> diff --git a/hook.c b/hook.c index c3640a89571d7d59444f022467e8c8849a0206bb..39ceaa4db2c4b01f40dba6156d6e8a8fb1a16c8d 100644 --- a/hook.c +++ b/hook.c @@ -48,6 +48,10 @@ static HASH *IdxFmtHooks = NULL; static int current_hook_type = 0; +/* Combine all message disposition hooks for the parsing to follow. */ +#define MUTT_MD_HOOKS (MUTT_SENTHOOK | MUTT_ABORTEDHOOK | \ + MUTT_POSTPONEDHOOK | MUTT_BACKGROUNDEDHOOK) + int mutt_parse_hook (BUFFER *buf, BUFFER *s, union pointer_long_t udata, BUFFER *err) { HOOK *ptr; @@ -75,7 +79,7 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, union pointer_long_t udata, BUFFER goto cleanup; } - mutt_extract_token (command, s, (data & (MUTT_FOLDERHOOK | MUTT_SENDHOOK | MUTT_SEND2HOOK | MUTT_ACCOUNTHOOK | MUTT_REPLYHOOK)) ? MUTT_TOKEN_SPACE : 0); + mutt_extract_token (command, s, (data & (MUTT_FOLDERHOOK | MUTT_SENDHOOK | MUTT_SEND2HOOK | MUTT_ACCOUNTHOOK | MUTT_REPLYHOOK | MUTT_MD_HOOKS)) ? MUTT_TOKEN_SPACE : 0); if (!mutt_buffer_len (command)) { @@ -154,7 +158,7 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, union pointer_long_t udata, BUFFER ptr->rx.not == not && !mutt_strcmp (mutt_b2s (pattern), ptr->rx.pattern)) { - if (data & (MUTT_FOLDERHOOK | MUTT_SENDHOOK | MUTT_SEND2HOOK | MUTT_MESSAGEHOOK | MUTT_ACCOUNTHOOK | MUTT_REPLYHOOK | MUTT_CRYPTHOOK)) + if (data & (MUTT_FOLDERHOOK | MUTT_SENDHOOK | MUTT_SEND2HOOK | MUTT_MESSAGEHOOK | MUTT_ACCOUNTHOOK | MUTT_REPLYHOOK | MUTT_CRYPTHOOK | MUTT_MD_HOOKS)) { /* these hooks allow multiple commands with the same * pattern, so if we've already seen this pattern/command pair, just @@ -182,7 +186,7 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, union pointer_long_t udata, BUFFER break; } - if (data & (MUTT_SENDHOOK | MUTT_SEND2HOOK | MUTT_SAVEHOOK | MUTT_FCCHOOK | MUTT_MESSAGEHOOK | MUTT_REPLYHOOK)) + if (data & (MUTT_SENDHOOK | MUTT_SEND2HOOK | MUTT_SAVEHOOK | MUTT_FCCHOOK | MUTT_MESSAGEHOOK | MUTT_REPLYHOOK | MUTT_MD_HOOKS)) { int comp_flags; diff --git a/init.h b/init.h index 6cbc30a3ca4423a053b69427cb6e906e33618d60..1c8e3d15874ce193deb530cf75c06abd2fcd2714 100644 --- a/init.h +++ b/init.h @@ -855,8 +855,8 @@ struct option_t MuttVars[] = { /* ** .pp ** This variable controls how ``$message-hook'', ``$reply-hook'', ``$send-hook'', - ** ``$send2-hook'', ``$save-hook'', and ``$fcc-hook'' will - ** be interpreted if they are specified with only a simple regexp, + ** ``$send2-hook'', ``$save-hook'', ``$fcc-hook'', and the message disposition + ** hooks will be interpreted if they are specified with only a simple regexp, ** instead of a matching pattern. The hooks are expanded when they are ** declared, so a hook will be interpreted according to the value of this ** variable at the time the hook is declared. @@ -4614,6 +4614,7 @@ struct command_t }; const struct command_t Commands[] = { + { "aborted-hook", mutt_parse_hook, {.l=MUTT_ABORTEDHOOK} }, { "alternates", parse_alternates, {.l=0} }, { "unalternates", parse_unalternates, {.l=0} }, #ifdef USE_SOCKET @@ -4624,6 +4625,7 @@ const struct command_t Commands[] = { { "unattachments", parse_unattachments, {.l=0} }, { "auto_view", parse_list, {.p=&AutoViewList} }, { "alternative_order", parse_list, {.p=&AlternativeOrderList} }, + { "backgrounded-hook", mutt_parse_hook, {.l=MUTT_BACKGROUNDEDHOOK} }, { "bind", mutt_parse_bind, {.l=0} }, { "charset-hook", mutt_parse_hook, {.l=MUTT_CHARSETHOOK} }, #ifdef HAVE_COLOR @@ -4662,6 +4664,7 @@ const struct command_t Commands[] = { { "my_hdr", parse_my_hdr, {.l=0} }, { "pgp-hook", mutt_parse_hook, {.l=MUTT_CRYPTHOOK} }, { "crypt-hook", mutt_parse_hook, {.l=MUTT_CRYPTHOOK} }, + { "postponed-hook", mutt_parse_hook, {.l=MUTT_POSTPONEDHOOK} }, { "push", mutt_parse_push, {.l=0} }, { "reply-hook", mutt_parse_hook, {.l=MUTT_REPLYHOOK} }, { "reset", parse_set, {.l=MUTT_SET_RESET} }, @@ -4669,6 +4672,7 @@ const struct command_t Commands[] = { { "score", mutt_parse_score, {.l=0} }, { "send-hook", mutt_parse_hook, {.l=MUTT_SENDHOOK} }, { "send2-hook", mutt_parse_hook, {.l=MUTT_SEND2HOOK} }, + { "sent-hook", mutt_parse_hook, {.l=MUTT_SENTHOOK} }, { "set", parse_set, {.l=0} }, { "setenv", parse_setenv, {.l=0} }, #ifdef USE_SIDEBAR diff --git a/mutt.h b/mutt.h index 4413739ff0748215807e8a7d3e9d803bdeabd26e..0c9dccd55c2583475aa064487bbee1e9291612d6 100644 --- a/mutt.h +++ b/mutt.h @@ -184,6 +184,10 @@ typedef enum #define MUTT_CLOSEHOOK (1<<14) #endif /* USE_COMPRESSED */ #define MUTT_IDXFMTHOOK (1<<15) +#define MUTT_SENTHOOK (1<<16) +#define MUTT_ABORTEDHOOK (1<<17) +#define MUTT_POSTPONEDHOOK (1<<18) +#define MUTT_BACKGROUNDEDHOOK (1<<19) /* tree characters for linearize_tree and print_enriched_string */ #define MUTT_TREE_LLCORNER 1 diff --git a/send.c b/send.c index 44e34feaaa3adc0a4e8bdbef9fe3bffc85cbf474..380d478156e1f38e06019fcab42590737c46a0c6 100644 --- a/send.c +++ b/send.c @@ -2750,7 +2750,8 @@ mutt_send_message (int flags, /* send mode */ if (send_message_setup (sctx, tempfile, ctx) < 0) { send_ctx_free (&sctx); - return -1; + rv = -1; + goto dispatch_hooks; } rv = mutt_send_message_resume (&sctx); @@ -2760,6 +2761,15 @@ mutt_send_message (int flags, /* send mode */ sctx->is_backgrounded = 1; } +dispatch_hooks: + + switch (rv) { + case 0: mutt_message_hook (NULL, msg, MUTT_SENTHOOK); break; + case 1: mutt_message_hook (NULL, msg, MUTT_POSTPONEDHOOK); break; + case 2: mutt_message_hook (NULL, msg, MUTT_BACKGROUNDEDHOOK); break; + default: mutt_message_hook (NULL, msg, MUTT_ABORTEDHOOK); + } + return rv; } -- 2.11.0
signature.asc
Description: PGP signature