Add an option --from= to notmuch-reply.c to restrict guessing of the From: header. The existing logic looks as the main headers, then at the delivery headers, and finally defaults to the config file address. This patch allows the user to restrict which of these guesses are made. Currently the supported values are: default|fallback-all current behaviour fallback-received fallback to delivery headers but not config file fallback-none only look at from/reply-to/to/cc/ headers none From: header is always left empty If the code does not find an allowed address it outputs an empty From: line and the caller can decide how to respond. --- notmuch-reply.c | 39 ++++++++++++++++++++++++++++++--------- 1 files changed, 30 insertions(+), 9 deletions(-) diff --git a/notmuch-reply.c b/notmuch-reply.c index f55b1d2..f660749 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -24,6 +24,13 @@ #include "gmime-filter-reply.h" #include "gmime-filter-headers.h" +enum { + FROM_FALLBACK_ALL, + FROM_FALLBACK_RECEIVED, + FROM_FALLBACK_NONE, + FROM_NONE +}; + static void reply_headers_message_part (GMimeMessage *message); @@ -510,7 +517,8 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, - notmuch_bool_t reply_all) + notmuch_bool_t reply_all, + int from_guess) { GMimeMessage *reply; notmuch_messages_t *messages; @@ -542,15 +550,19 @@ notmuch_reply_format_default(void *ctx, from_addr = add_recipients_from_message (reply, config, message, reply_all); - if (from_addr == NULL) + if ((from_addr == NULL) && (from_guess <= FROM_FALLBACK_RECEIVED)) from_addr = guess_from_received_header (config, message); - if (from_addr == NULL) + if ((from_addr == NULL) && (from_guess <= FROM_FALLBACK_ALL )) from_addr = notmuch_config_get_user_primary_email (config); - from_addr = talloc_asprintf (ctx, "%s <%s>", - notmuch_config_get_user_name (config), - from_addr); + if ((from_addr != NULL) || (from_guess = FROM_NONE)) { + from_addr = talloc_asprintf (ctx, "%s <%s>", + notmuch_config_get_user_name (config), + from_addr); + } else { + from_addr = talloc_strdup (ctx, ""); + } g_mime_object_set_header (GMIME_OBJECT (reply), "From", from_addr); @@ -590,7 +602,8 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query, unused (notmuch_show_params_t *params), - notmuch_bool_t reply_all) + notmuch_bool_t reply_all, + unused (int from_guess)) { GMimeMessage *reply; notmuch_messages_t *messages; @@ -657,10 +670,11 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) notmuch_query_t *query; char *query_string; int opt_index, ret = 0; - int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all); + int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all, int from_guess); notmuch_show_params_t params = { .part = -1 }; int format = FORMAT_DEFAULT; int reply_all = TRUE; + int from_guess = FROM_FALLBACK_ALL; notmuch_bool_t decrypt = FALSE; notmuch_opt_desc_t options[] = { @@ -672,6 +686,13 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) (notmuch_keyword_t []){ { "all", TRUE }, { "sender", FALSE }, { 0, 0 } } }, + { NOTMUCH_OPT_KEYWORD, &from_guess, "from", 'F', + (notmuch_keyword_t []){ { "default", FROM_FALLBACK_ALL }, + { "fallback-all", FROM_FALLBACK_ALL }, + { "fallback-received", FROM_FALLBACK_RECEIVED }, + { "fallback-none", FROM_FALLBACK_NONE }, + { "none", FROM_NONE }, + { 0, 0 } } }, { NOTMUCH_OPT_BOOLEAN, &decrypt, "decrypt", 'd', 0 }, { 0, 0, 0, 0, 0 } }; @@ -732,7 +753,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) return 1; } - if (reply_format_func (ctx, config, query, ¶ms, reply_all) != 0) + if (reply_format_func (ctx, config, query, ¶ms, reply_all, from_guess) != 0) return 1; notmuch_query_destroy (query); -- 1.7.2.3