--- /dev/null
+Return-Path: <markwalters1009@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 02A20431FBF\r
+ for <notmuch@notmuchmail.org>; Sat, 4 Feb 2012 09:08:29 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+ RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id cwDwq20dBPxd for <notmuch@notmuchmail.org>;\r
+ Sat, 4 Feb 2012 09:08:27 -0800 (PST)\r
+Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com\r
+ [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 24AA2431FC3\r
+ for <notmuch@notmuchmail.org>; Sat, 4 Feb 2012 09:08:25 -0800 (PST)\r
+Received: by mail-wi0-f181.google.com with SMTP id hi8so3640758wib.26\r
+ for <notmuch@notmuchmail.org>; Sat, 04 Feb 2012 09:08:25 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+ h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+ bh=6FgeDAOQkqBapGUGVdjGgyoHBM3DN9VZGdHUbIVkjAU=;\r
+ b=sf/QBsZD4qtJC6oQkw1HtzizYrvS35+l1+hvdVFQ0XX5yFCiMAtg1/SLYBNen3fFIZ\r
+ FnfbDWFlUKEtm77LigrC3l091uhlUY7PkzggYJsarb5ifO1DZmCXLxHOCSu2gvkX/YQs\r
+ G9GNUby6t7rBeoxiYUUPbmy3wmkzfceEnGCqA=\r
+Received: by 10.180.14.129 with SMTP id p1mr18213105wic.16.1328375304987;\r
+ Sat, 04 Feb 2012 09:08:24 -0800 (PST)\r
+Received: from localhost (94-192-233-223.zone6.bethere.co.uk.\r
+ [94.192.233.223]) by mx.google.com with ESMTPS id\r
+ cb8sm13984703wib.0.2012.02.04.09.08.23 (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Sat, 04 Feb 2012 09:08:24 -0800 (PST)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/2] cli: add --from option to reply to restrict guessing of\r
+ the From: header.\r
+Date: Sat, 4 Feb 2012 17:09:09 +0000\r
+Message-Id: <1328375350-10352-2-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.2.3\r
+In-Reply-To: <1328375350-10352-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1328375350-10352-1-git-send-email-markwalters1009@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 04 Feb 2012 17:08:29 -0000\r
+\r
+Add an option --from= to notmuch-reply.c to restrict guessing of the\r
+From: header. The existing logic looks as the main headers, then at\r
+the delivery headers, and finally defaults to the config file address.\r
+\r
+This patch allows the user to restrict which of these guesses are\r
+made. Currently the supported values are:\r
+ default|fallback-all current behaviour\r
+ fallback-received fallback to delivery headers but not config file\r
+ fallback-none only look at from/reply-to/to/cc/ headers\r
+ none From: header is always left empty\r
+\r
+If the code does not find an allowed address it outputs an empty From:\r
+line and the caller can decide how to respond.\r
+---\r
+ notmuch-reply.c | 39 ++++++++++++++++++++++++++++++---------\r
+ 1 files changed, 30 insertions(+), 9 deletions(-)\r
+\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index f55b1d2..f660749 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -24,6 +24,13 @@\r
+ #include "gmime-filter-reply.h"\r
+ #include "gmime-filter-headers.h"\r
+ \r
++enum {\r
++ FROM_FALLBACK_ALL,\r
++ FROM_FALLBACK_RECEIVED,\r
++ FROM_FALLBACK_NONE,\r
++ FROM_NONE\r
++};\r
++\r
+ static void\r
+ reply_headers_message_part (GMimeMessage *message);\r
+ \r
+@@ -510,7 +517,8 @@ notmuch_reply_format_default(void *ctx,\r
+ notmuch_config_t *config,\r
+ notmuch_query_t *query,\r
+ notmuch_show_params_t *params,\r
+- notmuch_bool_t reply_all)\r
++ notmuch_bool_t reply_all,\r
++ int from_guess)\r
+ {\r
+ GMimeMessage *reply;\r
+ notmuch_messages_t *messages;\r
+@@ -542,15 +550,19 @@ notmuch_reply_format_default(void *ctx,\r
+ from_addr = add_recipients_from_message (reply, config, message,\r
+ reply_all);\r
+ \r
+- if (from_addr == NULL)\r
++ if ((from_addr == NULL) && (from_guess <= FROM_FALLBACK_RECEIVED))\r
+ from_addr = guess_from_received_header (config, message);\r
+ \r
+- if (from_addr == NULL)\r
++ if ((from_addr == NULL) && (from_guess <= FROM_FALLBACK_ALL ))\r
+ from_addr = notmuch_config_get_user_primary_email (config);\r
+ \r
+- from_addr = talloc_asprintf (ctx, "%s <%s>",\r
+- notmuch_config_get_user_name (config),\r
+- from_addr);\r
++ if ((from_addr != NULL) || (from_guess = FROM_NONE)) {\r
++ from_addr = talloc_asprintf (ctx, "%s <%s>",\r
++ notmuch_config_get_user_name (config),\r
++ from_addr);\r
++ } else {\r
++ from_addr = talloc_strdup (ctx, "");\r
++ }\r
+ g_mime_object_set_header (GMIME_OBJECT (reply),\r
+ "From", from_addr);\r
+ \r
+@@ -590,7 +602,8 @@ notmuch_reply_format_headers_only(void *ctx,\r
+ notmuch_config_t *config,\r
+ notmuch_query_t *query,\r
+ unused (notmuch_show_params_t *params),\r
+- notmuch_bool_t reply_all)\r
++ notmuch_bool_t reply_all,\r
++ unused (int from_guess))\r
+ {\r
+ GMimeMessage *reply;\r
+ notmuch_messages_t *messages;\r
+@@ -657,10 +670,11 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+ notmuch_query_t *query;\r
+ char *query_string;\r
+ int opt_index, ret = 0;\r
+- int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all);\r
++ 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);\r
+ notmuch_show_params_t params = { .part = -1 };\r
+ int format = FORMAT_DEFAULT;\r
+ int reply_all = TRUE;\r
++ int from_guess = FROM_FALLBACK_ALL;\r
+ notmuch_bool_t decrypt = FALSE;\r
+ \r
+ notmuch_opt_desc_t options[] = {\r
+@@ -672,6 +686,13 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+ (notmuch_keyword_t []){ { "all", TRUE },\r
+ { "sender", FALSE },\r
+ { 0, 0 } } },\r
++ { NOTMUCH_OPT_KEYWORD, &from_guess, "from", 'F',\r
++ (notmuch_keyword_t []){ { "default", FROM_FALLBACK_ALL },\r
++ { "fallback-all", FROM_FALLBACK_ALL },\r
++ { "fallback-received", FROM_FALLBACK_RECEIVED },\r
++ { "fallback-none", FROM_FALLBACK_NONE },\r
++ { "none", FROM_NONE },\r
++ { 0, 0 } } },\r
+ { NOTMUCH_OPT_BOOLEAN, &decrypt, "decrypt", 'd', 0 },\r
+ { 0, 0, 0, 0, 0 }\r
+ };\r
+@@ -732,7 +753,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+ return 1;\r
+ }\r
+ \r
+- if (reply_format_func (ctx, config, query, ¶ms, reply_all) != 0)\r
++ if (reply_format_func (ctx, config, query, ¶ms, reply_all, from_guess) != 0)\r
+ return 1;\r
+ \r
+ notmuch_query_destroy (query);\r
+-- \r
+1.7.2.3\r
+\r