From: Thomas Roessler Date: Tue, 7 Dec 2004 19:50:04 +0000 (+0000) Subject: Add send2-hook and fix alternates handling. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f663d1b1261bc030f7ffff053eee008b82ed139b;p=neomutt Add send2-hook and fix alternates handling. --- diff --git a/compose.c b/compose.c index 861641bf1..e0febb812 100644 --- a/compose.c +++ b/compose.c @@ -527,16 +527,20 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ break; case OP_COMPOSE_EDIT_FROM: menu->redraw = edit_address_list (HDR_FROM, &msg->env->from); + mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_EDIT_TO: menu->redraw = edit_address_list (HDR_TO, &msg->env->to); - break; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; case OP_COMPOSE_EDIT_BCC: menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc); + mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_EDIT_CC: menu->redraw = edit_address_list (HDR_CC, &msg->env->cc); - break; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; case OP_COMPOSE_EDIT_SUBJECT: if (msg->env->subject) strfcpy (buf, msg->env->subject, sizeof (buf)); @@ -550,9 +554,11 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ if (msg->env->subject) mutt_paddstr (W, msg->env->subject); } - break; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; case OP_COMPOSE_EDIT_REPLY_TO: menu->redraw = edit_address_list (HDR_REPLYTO, &msg->env->reply_to); + mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_EDIT_FCC: strfcpy (buf, fcc, sizeof (buf)); @@ -565,13 +571,15 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ fccSet = 1; } MAYBE_REDRAW (menu->redraw); - break; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; case OP_COMPOSE_EDIT_MESSAGE: if (Editor && (mutt_strcmp ("builtin", Editor) != 0) && !option (OPTEDITHDRS)) { mutt_edit_file (Editor, msg->content->filename); mutt_update_encoding (msg->content); menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; + mutt_message_hook (NULL, msg, M_SEND2HOOK); break; } /* fall through */ @@ -611,7 +619,8 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ menu->max = idxlen; } - menu->redraw = REDRAW_FULL; + menu->redraw = REDRAW_FULL; + mutt_message_hook (NULL, msg, M_SEND2HOOK); break; @@ -642,7 +651,8 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ unset_option(OPTNEEDREDRAW); } - break; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; case OP_COMPOSE_ATTACH_FILE: @@ -688,7 +698,8 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ menu->redraw |= REDRAW_INDEX | REDRAW_STATUS; } - break; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; case OP_COMPOSE_ATTACH_MESSAGE: { @@ -794,7 +805,8 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ Sort = oldSort; SortAux = oldSortAux; } - break; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; case OP_DELETE: CHECK_COUNT; @@ -813,7 +825,8 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ msg->content = idx[0]->content; menu->redraw |= REDRAW_STATUS; - break; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; #define CURRENT idx[menu->current]->content @@ -831,6 +844,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ else mutt_message (_("The current attachment will be converted.")); menu->redraw = REDRAW_CURRENT; + mutt_message_hook (NULL, msg, M_SEND2HOOK); break; } #undef CURRENT @@ -847,7 +861,8 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ mutt_str_replace (&idx[menu->current]->content->description, buf); menu->redraw = REDRAW_CURRENT; } - break; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; case OP_COMPOSE_UPDATE_ENCODING: CHECK_COUNT; @@ -866,6 +881,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ mutt_update_encoding(idx[menu->current]->content); menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; } + mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_TOGGLE_DISPOSITION: @@ -884,7 +900,8 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ menu->redraw = REDRAW_CURRENT; } - break; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; case OP_COMPOSE_EDIT_ENCODING: CHECK_COUNT; @@ -902,9 +919,14 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ else mutt_error _("Invalid encoding."); } - break; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; case OP_COMPOSE_SEND_MESSAGE: + + /* Note: We don't invoke send2-hook here, since we want to leave + * users an opportunity to change settings from the ":" prompt. + */ if(check_attachments(idx, idxlen) != 0) { @@ -936,6 +958,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ mutt_edit_file (NONULL(Editor), idx[menu->current]->content->filename); mutt_update_encoding (idx[menu->current]->content); menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; + mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_TOGGLE_UNLINK: @@ -951,6 +974,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ menu->current++; # endif menu->redraw = REDRAW_INDEX; + /* No send2hook since this doesn't change the message. */ break; case OP_COMPOSE_GET_ATTACHMENT: @@ -968,6 +992,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ else if (mutt_get_tmp_attachment(idx[menu->current]->content) == 0) menu->redraw = REDRAW_CURRENT; + /* No send2hook since this doesn't change the message. */ break; case OP_COMPOSE_RENAME_FILE: @@ -994,7 +1019,8 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ mutt_stamp_attachment(idx[menu->current]->content); } - break; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; case OP_COMPOSE_NEW_MIME: { @@ -1061,7 +1087,8 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ menu->redraw = REDRAW_FULL; } } - break; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; case OP_COMPOSE_EDIT_MIME: CHECK_COUNT; @@ -1070,24 +1097,28 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ mutt_update_encoding (idx[menu->current]->content); menu->redraw = REDRAW_FULL; } - break; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; case OP_VIEW_ATTACH: case OP_DISPLAY_HEADERS: CHECK_COUNT; mutt_attach_display_loop (menu, op, NULL, NULL, NULL, &idx, &idxlen, NULL, 0); menu->redraw = REDRAW_FULL; + /* no send2hook, since this doesn't modify the message */ break; case OP_SAVE: CHECK_COUNT; mutt_save_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, NULL, menu); MAYBE_REDRAW (menu->redraw); + /* no send2hook, since this doesn't modify the message */ break; case OP_PRINT: CHECK_COUNT; mutt_print_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content); + /* no send2hook, since this doesn't modify the message */ break; case OP_PIPE: @@ -1095,8 +1126,9 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ CHECK_COUNT; mutt_pipe_attachment_list (NULL, menu->tagprefix, menu->tagprefix ? msg->content : idx[menu->current]->content, op == OP_FILTER); if (op == OP_FILTER) /* cte might have changed */ - menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT; + menu->redraw = menu->tagprefix ? REDRAW_FULL : REDRAW_CURRENT; menu->redraw |= REDRAW_STATUS; + mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_EXIT: @@ -1191,7 +1223,8 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ } msg->security = crypt_pgp_send_menu (msg, &menu->redraw); redraw_crypt_lines (msg); - break; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; case OP_FORGET_PASSPHRASE: @@ -1216,13 +1249,15 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ } msg->security = crypt_smime_send_menu(msg, &menu->redraw); redraw_crypt_lines (msg); - break; + mutt_message_hook (NULL, msg, M_SEND2HOOK); + break; #ifdef MIXMASTER case OP_COMPOSE_MIX: mix_make_chain (&msg->chain, &menu->redraw); + mutt_message_hook (NULL, msg, M_SEND2HOOK); break; #endif diff --git a/hook.c b/hook.c index d7931c02d..740ff4620 100644 --- a/hook.c +++ b/hook.c @@ -66,7 +66,7 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) goto error; } - mutt_extract_token (&command, s, (data & (M_FOLDERHOOK | M_SENDHOOK | M_ACCOUNTHOOK | M_REPLYHOOK)) ? M_TOKEN_SPACE : 0); + mutt_extract_token (&command, s, (data & (M_FOLDERHOOK | M_SENDHOOK | M_SEND2HOOK | M_ACCOUNTHOOK | M_REPLYHOOK)) ? M_TOKEN_SPACE : 0); if (!command.data) { @@ -117,7 +117,7 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) ptr->rx.not == not && !mutt_strcmp (pattern.data, ptr->rx.pattern)) { - if (data & (M_FOLDERHOOK | M_SENDHOOK | M_MESSAGEHOOK | M_ACCOUNTHOOK | M_REPLYHOOK)) + if (data & (M_FOLDERHOOK | M_SENDHOOK | M_SEND2HOOK | M_MESSAGEHOOK | M_ACCOUNTHOOK | M_REPLYHOOK)) { /* these hooks allow multiple commands with the same * pattern, so if we've already seen this pattern/command pair, just @@ -146,10 +146,10 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) break; } - if (data & (M_SENDHOOK | M_SAVEHOOK | M_FCCHOOK | M_MESSAGEHOOK | M_REPLYHOOK)) + if (data & (M_SENDHOOK | M_SEND2HOOK | M_SAVEHOOK | M_FCCHOOK | M_MESSAGEHOOK | M_REPLYHOOK)) { if ((pat = mutt_pattern_comp (pattern.data, - (data & (M_SENDHOOK | M_FCCHOOK)) ? 0 : M_FULL_MSG, + (data & (M_SENDHOOK | M_SEND2HOOK | M_FCCHOOK)) ? 0 : M_FULL_MSG, err)) == NULL) goto error; } diff --git a/init.c b/init.c index 2a66a2962..7ebfac449 100644 --- a/init.c +++ b/init.c @@ -611,6 +611,28 @@ static int parse_rx_unlist (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER * return 0; } +static void _alternates_clean (void) +{ + int i; + if (Context && Context->msgcount) + { + for (i = 0; i < Context->msgcount; i++) + Context->hdrs[i]->recip_valid = 0; + } +} + +static int parse_alternates (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) +{ + _alternates_clean(); + return parse_rx_list (buf, s, data, err); +} + +static int parse_unalternates (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) +{ + _alternates_clean(); + return parse_rx_unlist (buf, s, data, err); +} + static int parse_spam_list (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) { BUFFER templ; @@ -1066,9 +1088,7 @@ static void mutt_restore_default (struct option_t *p) pp->rx = safe_calloc (1, sizeof (regex_t)); pp->pattern = safe_strdup ((char *) p->init); - if (mutt_strcmp (p->option, "alternates") == 0) - flags |= REG_ICASE; - else if (mutt_strcmp (p->option, "mask") != 0) + if (mutt_strcmp (p->option, "mask") != 0) flags |= mutt_which_case ((const char *) p->init); if (mutt_strcmp (p->option, "mask") == 0 && *s == '!') { @@ -1280,8 +1300,7 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err) break; } - if (option(OPTATTACHMSG) && (!mutt_strcmp(MuttVars[idx].option, "alternates") - || !mutt_strcmp(MuttVars[idx].option, "reply_regexp"))) + if (option(OPTATTACHMSG) && !mutt_strcmp(MuttVars[idx].option, "reply_regexp")) { snprintf (err->data, err->dsize, "Operation not permitted when in attach-message mode."); r = -1; @@ -1297,11 +1316,8 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err) { int not = 0; - /* $alternates is case-insensitive, - $mask is case-sensitive */ - if (mutt_strcmp (MuttVars[idx].option, "alternates") == 0) - flags |= REG_ICASE; - else if (mutt_strcmp (MuttVars[idx].option, "mask") != 0) + /* $mask is case-sensitive */ + if (mutt_strcmp (MuttVars[idx].option, "mask") != 0) flags |= mutt_which_case (tmp->data); p = tmp->data; @@ -1356,15 +1372,6 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err) } #undef CUR_ENV } - - if(Context && Context->msgcount && - mutt_strcmp(MuttVars[idx].option, "alternates") == 0) - { - int i; - - for(i = 0; i < Context->msgcount; i++) - Context->hdrs[i]->recip_valid = 0; - } } } else if (DTYPE(MuttVars[idx].type) == DT_MAGIC) diff --git a/init.h b/init.h index 8aa118e2e..105713447 100644 --- a/init.h +++ b/init.h @@ -2824,6 +2824,9 @@ static int parse_my_hdr (BUFFER *, BUFFER *, unsigned long, BUFFER *); static int parse_unmy_hdr (BUFFER *, BUFFER *, unsigned long, BUFFER *); static int parse_subscribe (BUFFER *, BUFFER *, unsigned long, BUFFER *); +static int parse_alternates (BUFFER *, BUFFER *, unsigned long, BUFFER *); +static int parse_unalternates (BUFFER *, BUFFER *, unsigned long, BUFFER *); + struct command_t { char *name; @@ -2832,8 +2835,8 @@ struct command_t }; struct command_t Commands[] = { - { "alternates", parse_rx_list, UL &Alternates }, - { "unalternates", parse_rx_unlist, UL &Alternates }, + { "alternates", parse_alternates, UL &Alternates }, + { "unalternates", parse_unalternates, UL &Alternates }, #ifdef USE_SOCKET { "account-hook", mutt_parse_hook, M_ACCOUNTHOOK }, #endif @@ -2873,6 +2876,7 @@ struct command_t Commands[] = { { "save-hook", mutt_parse_hook, M_SAVEHOOK }, { "score", mutt_parse_score, 0 }, { "send-hook", mutt_parse_hook, M_SENDHOOK }, + { "send2-hook", mutt_parse_hook, M_SEND2HOOK }, { "set", parse_set, 0 }, { "source", parse_source, 0 }, { "spam", parse_spam_list, M_SPAM }, diff --git a/mutt.h b/mutt.h index 97cc66d46..fedb250b5 100644 --- a/mutt.h +++ b/mutt.h @@ -160,6 +160,7 @@ typedef enum #define M_CRYPTHOOK (1<<8) #define M_ACCOUNTHOOK (1<<9) #define M_REPLYHOOK (1<<10) +#define M_SEND2HOOK (1<<11) /* tree characters for linearize_tree and print_enriched_string */ #define M_TREE_LLCORNER 1 diff --git a/send.c b/send.c index 7fb9b5e6c..0cde51289 100644 --- a/send.c +++ b/send.c @@ -1320,6 +1320,14 @@ ci_send_message (int flags, /* send mode */ if (!(msg->security & (APPLICATION_SMIME|APPLICATION_PGP))) msg->security = 0; } + + /* + * This hook is even called for postponed messages, and can, e.g., be + * used for setting the editor, the sendmail path, or the + * envelope sender. + */ + mutt_message_hook (NULL, msg, M_SEND2HOOK); + /* wait until now to set the real name portion of our return address so that $realname can be set in a send-hook */ if (msg->env->from && !msg->env->from->personal