[PATCH v2 1/4] cli: add --from option to reply to restrict guessing of the From:...
authorMark Walters <markwalters1009@gmail.com>
Sat, 4 Feb 2012 20:45:14 +0000 (20:45 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:44:06 +0000 (09:44 -0800)
8d/2c2ffa950015b920d34c092f40d1897c822796 [new file with mode: 0644]

diff --git a/8d/2c2ffa950015b920d34c092f40d1897c822796 b/8d/2c2ffa950015b920d34c092f40d1897c822796
new file mode 100644 (file)
index 0000000..7cfc490
--- /dev/null
@@ -0,0 +1,185 @@
+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 CA3A8431FBD\r
+       for <notmuch@notmuchmail.org>; Sat,  4 Feb 2012 12:44:33 -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 ErtsBMtWHQDC for <notmuch@notmuchmail.org>;\r
+       Sat,  4 Feb 2012 12:44:32 -0800 (PST)\r
+Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
+       [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id C9CF6431FC4\r
+       for <notmuch@notmuchmail.org>; Sat,  4 Feb 2012 12:44:31 -0800 (PST)\r
+Received: by werb10 with SMTP id b10so4024656wer.26\r
+       for <notmuch@notmuchmail.org>; Sat, 04 Feb 2012 12:44:30 -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=tHqp/y/ke/09cnIWldd9x5kTfRMd4pkPtT9WlXCfRP0=;\r
+       b=EP4WIL8MeypiuqjWBb4YsNngBjgOvLOspXMsOCX8+gYvAfJiNqiiDjplL4BWybCc3y\r
+       WXPQs0WvHdHAzsJEXRNDR/VxYUogdk0jg3R4Ezy9kbePVp6mL7u+LL+mc04RUok6uAjQ\r
+       e6qkfjYMkgkaaLnVlvmt9RARRW5SjdQOLkGGU=\r
+Received: by 10.216.132.148 with SMTP id o20mr1132792wei.33.1328388270696;\r
+       Sat, 04 Feb 2012 12:44:30 -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
+ y1sm30164139wiw.6.2012.02.04.12.44.29 (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sat, 04 Feb 2012 12:44:30 -0800 (PST)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 1/4] cli: add --from option to reply to restrict guessing\r
+       of the From: header.\r
+Date: Sat,  4 Feb 2012 20:45:14 +0000\r
+Message-Id: <1328388317-20161-2-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.2.3\r
+In-Reply-To: <1328388317-20161-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1328388317-20161-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 20:44:34 -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 |   45 ++++++++++++++++++++++++++++++++++++---------\r
+ 1 files changed, 36 insertions(+), 9 deletions(-)\r
+\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index f55b1d2..8c73cb7 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -24,6 +24,15 @@\r
+ #include "gmime-filter-reply.h"\r
+ #include "gmime-filter-headers.h"\r
+ \r
++/* The order here matters as we use '<' when deciding how to behave. */\r
++enum {\r
++    FROM_FALLBACK_ALL,\r
++    FROM_FALLBACK_RECEIVED,\r
++    FROM_FALLBACK_NONE,\r
++    FROM_NONE,\r
++    FROM_PRIMARY\r
++};\r
++\r
+ static void\r
+ reply_headers_message_part (GMimeMessage *message);\r
+ \r
+@@ -510,7 +519,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_select)\r
+ {\r
+     GMimeMessage *reply;\r
+     notmuch_messages_t *messages;\r
+@@ -542,15 +552,22 @@ 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_select <= FROM_FALLBACK_RECEIVED)\r
+           from_addr = guess_from_received_header (config, message);\r
+ \r
+-      if (from_addr == NULL)\r
++      if ((from_addr == NULL && from_select <= FROM_FALLBACK_ALL) ||\r
++          from_select == FROM_PRIMARY)\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 we have an address and we want an address print\r
++       * it. Otherwise set an empty From: header. */\r
++      if (from_addr != NULL && from_select != 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 +607,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_select))\r
+ {\r
+     GMimeMessage *reply;\r
+     notmuch_messages_t *messages;\r
+@@ -657,10 +675,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_select);\r
+     notmuch_show_params_t params = { .part = -1 };\r
+     int format = FORMAT_DEFAULT;\r
+     int reply_all = TRUE;\r
++    int from_select = FROM_FALLBACK_ALL;\r
+     notmuch_bool_t decrypt = FALSE;\r
+ \r
+     notmuch_opt_desc_t options[] = {\r
+@@ -672,6 +691,14 @@ 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_select, "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
++                                { "primary", FROM_PRIMARY },\r
++                                { 0, 0 } } },\r
+       { NOTMUCH_OPT_BOOLEAN, &decrypt, "decrypt", 'd', 0 },\r
+       { 0, 0, 0, 0, 0 }\r
+     };\r
+@@ -732,7 +759,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+       return 1;\r
+     }\r
+ \r
+-    if (reply_format_func (ctx, config, query, &params, reply_all) != 0)\r
++    if (reply_format_func (ctx, config, query, &params, reply_all, from_select) != 0)\r
+       return 1;\r
+ \r
+     notmuch_query_destroy (query);\r
+-- \r
+1.7.2.3\r
+\r