Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id CA3A8431FBD for ; Sat, 4 Feb 2012 12:44:33 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0.201 X-Spam-Level: X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ErtsBMtWHQDC for ; Sat, 4 Feb 2012 12:44:32 -0800 (PST) Received: from mail-we0-f181.google.com (mail-we0-f181.google.com [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id C9CF6431FC4 for ; Sat, 4 Feb 2012 12:44:31 -0800 (PST) Received: by werb10 with SMTP id b10so4024656wer.26 for ; Sat, 04 Feb 2012 12:44:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=tHqp/y/ke/09cnIWldd9x5kTfRMd4pkPtT9WlXCfRP0=; b=EP4WIL8MeypiuqjWBb4YsNngBjgOvLOspXMsOCX8+gYvAfJiNqiiDjplL4BWybCc3y WXPQs0WvHdHAzsJEXRNDR/VxYUogdk0jg3R4Ezy9kbePVp6mL7u+LL+mc04RUok6uAjQ e6qkfjYMkgkaaLnVlvmt9RARRW5SjdQOLkGGU= Received: by 10.216.132.148 with SMTP id o20mr1132792wei.33.1328388270696; Sat, 04 Feb 2012 12:44:30 -0800 (PST) Received: from localhost (94-192-233-223.zone6.bethere.co.uk. [94.192.233.223]) by mx.google.com with ESMTPS id y1sm30164139wiw.6.2012.02.04.12.44.29 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 04 Feb 2012 12:44:30 -0800 (PST) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH v2 1/4] cli: add --from option to reply to restrict guessing of the From: header. Date: Sat, 4 Feb 2012 20:45:14 +0000 Message-Id: <1328388317-20161-2-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1328388317-20161-1-git-send-email-markwalters1009@gmail.com> References: <1328388317-20161-1-git-send-email-markwalters1009@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Feb 2012 20:44:34 -0000 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 | 45 ++++++++++++++++++++++++++++++++++++--------- 1 files changed, 36 insertions(+), 9 deletions(-) diff --git a/notmuch-reply.c b/notmuch-reply.c index f55b1d2..8c73cb7 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -24,6 +24,15 @@ #include "gmime-filter-reply.h" #include "gmime-filter-headers.h" +/* The order here matters as we use '<' when deciding how to behave. */ +enum { + FROM_FALLBACK_ALL, + FROM_FALLBACK_RECEIVED, + FROM_FALLBACK_NONE, + FROM_NONE, + FROM_PRIMARY +}; + static void reply_headers_message_part (GMimeMessage *message); @@ -510,7 +519,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_select) { GMimeMessage *reply; notmuch_messages_t *messages; @@ -542,15 +552,22 @@ 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_select <= FROM_FALLBACK_RECEIVED) from_addr = guess_from_received_header (config, message); - if (from_addr == NULL) + if ((from_addr == NULL && from_select <= FROM_FALLBACK_ALL) || + from_select == FROM_PRIMARY) 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 we have an address and we want an address print + * it. Otherwise set an empty From: header. */ + if (from_addr != NULL && from_select != 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 +607,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_select)) { GMimeMessage *reply; notmuch_messages_t *messages; @@ -657,10 +675,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_select); notmuch_show_params_t params = { .part = -1 }; int format = FORMAT_DEFAULT; int reply_all = TRUE; + int from_select = FROM_FALLBACK_ALL; notmuch_bool_t decrypt = FALSE; notmuch_opt_desc_t options[] = { @@ -672,6 +691,14 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) (notmuch_keyword_t []){ { "all", TRUE }, { "sender", FALSE }, { 0, 0 } } }, + { NOTMUCH_OPT_KEYWORD, &from_select, "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 }, + { "primary", FROM_PRIMARY }, + { 0, 0 } } }, { NOTMUCH_OPT_BOOLEAN, &decrypt, "decrypt", 'd', 0 }, { 0, 0, 0, 0, 0 } }; @@ -732,7 +759,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_select) != 0) return 1; notmuch_query_destroy (query); -- 1.7.2.3