Re: [PATCH 1/4] Add the option "--reply-to" to notmuch reply.
authorJani Nikula <jani@nikula.org>
Sun, 8 Jan 2012 12:47:33 +0000 (14:47 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:41:45 +0000 (09:41 -0800)
a5/3429b667d64e41d3838a85c985a0e4440df2ea [new file with mode: 0644]

diff --git a/a5/3429b667d64e41d3838a85c985a0e4440df2ea b/a5/3429b667d64e41d3838a85c985a0e4440df2ea
new file mode 100644 (file)
index 0000000..df1f603
--- /dev/null
@@ -0,0 +1,217 @@
+Return-Path: <jani@nikula.org>\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 4D9CB407817\r
+       for <notmuch@notmuchmail.org>; Sun,  8 Jan 2012 04:47:40 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[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 BCjkc0-9fkzw for <notmuch@notmuchmail.org>;\r
+       Sun,  8 Jan 2012 04:47:39 -0800 (PST)\r
+Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com\r
+ [74.125.83.53])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ C40FF409F31   for <notmuch@notmuchmail.org>; Sun,  8 Jan 2012 04:47:38 -0800\r
+ (PST)\r
+Received: by eekd41 with SMTP id d41so2303792eek.26\r
+       for <notmuch@notmuchmail.org>; Sun, 08 Jan 2012 04:47:37 -0800 (PST)\r
+Received: by 10.213.29.2 with SMTP id o2mr694257ebc.54.1326026857459;\r
+       Sun, 08 Jan 2012 04:47:37 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
+       [80.220.92.23])\r
+       by mx.google.com with ESMTPS id a60sm276271993eeb.4.2012.01.08.04.47.35\r
+       (version=SSLv3 cipher=OTHER); Sun, 08 Jan 2012 04:47:36 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Mark Walters <markwalters1009@gmail.com>, notmuch@notmuchmail.org,\r
+       david@tethera.net\r
+Subject: Re: [PATCH 1/4] Add the option "--reply-to" to notmuch reply.\r
+In-Reply-To: <1325856857-15969-1-git-send-email-markwalters1009@gmail.com>\r
+References: <8739btdkir.fsf@qmul.ac.uk>\r
+       <1325856857-15969-1-git-send-email-markwalters1009@gmail.com>\r
+User-Agent: Notmuch/0.10.2+182~g93862a2 (http://notmuchmail.org) Emacs/23.3.1\r
+       (i686-pc-linux-gnu)\r
+Date: Sun, 08 Jan 2012 14:47:33 +0200\r
+Message-ID: <871urafjiy.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\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: Sun, 08 Jan 2012 12:47:40 -0000\r
+\r
+On Fri,  6 Jan 2012 13:34:14 +0000, Mark Walters <markwalters1009@gmail.com> wrote:\r
+>     Possible values for this option are "sender" which replies just to\r
+>     sender and "all" (the default).\r
+> \r
+>     More precisely reply to sender follows these rules:\r
+>     reply only to sender unless it was the user\r
+>     reply only to all people on the "to" line unless they were all the user\r
+>     reply to all people on the "cc" line\r
+> \r
+>     Implementation details\r
+> \r
+>     We continue parsing addresses beyond the ones we reply to because\r
+>     we want to make sure the from address is correct. (At the very least it\r
+>     is the same as it would be if we replied to all.)\r
+> \r
+>     We overload the message variable in add_recipients_for_address_list so\r
+>     if it is NULL we parse the address (looking for the users address)\r
+>     but do not add to the message recipients list\r
+> \r
+>     We add the variable reply_to_all to the function chain to keep track\r
+>     of whether we should reply to everyone.\r
+> ---\r
+>  notmuch-reply.c |   48 +++++++++++++++++++++++++++++++++++++-----------\r
+>  1 files changed, 37 insertions(+), 11 deletions(-)\r
+> \r
+> diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+> index f8d5f64..9a77fe6 100644\r
+> --- a/notmuch-reply.c\r
+> +++ b/notmuch-reply.c\r
+> @@ -212,7 +212,8 @@ add_recipients_for_address_list (GMimeMessage *message,\r
+>              if (ret == NULL)\r
+>                  ret = addr;\r
+>          } else {\r
+> -            g_mime_message_add_recipient (message, type, name, addr);\r
+> +             if (message)\r
+> +                  g_mime_message_add_recipient (message, type, name, addr);\r
+>          }\r
+>      }\r
+>      }\r
+> @@ -292,7 +293,8 @@ reply_to_header_is_redundant (notmuch_message_t *message)\r
+>  static const char *\r
+>  add_recipients_from_message (GMimeMessage *reply,\r
+>                           notmuch_config_t *config,\r
+> -                         notmuch_message_t *message)\r
+> +                         notmuch_message_t *message,\r
+> +                         int reply_to_all)\r
+>  {\r
+>      struct {\r
+>      const char *header;\r
+> @@ -332,9 +334,20 @@ add_recipients_from_message (GMimeMessage *reply,\r
+>          recipients = notmuch_message_get_header (message,\r
+>                                                   reply_to_map[i].fallback);\r
+>  \r
+> -    addr = add_recipients_for_string (reply, config,\r
+> -                                      reply_to_map[i].recipient_type,\r
+> -                                      recipients);\r
+> +\r
+> +    /* We add the addresses if we are replying to all or we have not yet found\r
+> +     * a non-user address. We have to keep parsing to make sure we do find the\r
+> +     * correct from address for the user, but we pass a NULL message\r
+> +     */\r
+> +    if ((reply_to_all) || (g_mime_message_get_all_recipients (reply) == NULL))\r
+\r
+Looking into this, it occurred to me g_mime_message_get_all_recipients()\r
+allocates a new InternetAddressList when the return value is\r
+non-NULL. Thus this leaks memory. OTOH allocating and deallocating for\r
+this purpose seems suboptimal. I'll think this over.\r
+\r
+BR,\r
+Jani.\r
+\r
+\r
+\r
+> +        addr = add_recipients_for_string (reply, config,\r
+> +                                          reply_to_map[i].recipient_type,\r
+> +                                          recipients);\r
+> +    else\r
+> +         addr = add_recipients_for_string (NULL, config,\r
+> +                                           reply_to_map[i].recipient_type,\r
+> +                                           recipients);\r
+> +\r
+>      if (from_addr == NULL)\r
+>          from_addr = addr;\r
+>      }\r
+> @@ -480,7 +493,8 @@ static int\r
+>  notmuch_reply_format_default(void *ctx,\r
+>                           notmuch_config_t *config,\r
+>                           notmuch_query_t *query,\r
+> -                         notmuch_show_params_t *params)\r
+> +                         notmuch_show_params_t *params,\r
+> +                         int reply_to_all)\r
+>  {\r
+>      GMimeMessage *reply;\r
+>      notmuch_messages_t *messages;\r
+> @@ -509,7 +523,7 @@ notmuch_reply_format_default(void *ctx,\r
+>          g_mime_message_set_subject (reply, subject);\r
+>      }\r
+>  \r
+> -    from_addr = add_recipients_from_message (reply, config, message);\r
+> +    from_addr = add_recipients_from_message (reply, config, message, reply_to_all);\r
+>  \r
+>      if (from_addr == NULL)\r
+>          from_addr = guess_from_received_header (config, message);\r
+> @@ -558,7 +572,8 @@ static int\r
+>  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
+> +                              unused (notmuch_show_params_t *params),\r
+> +                              int reply_to_all)\r
+>  {\r
+>      GMimeMessage *reply;\r
+>      notmuch_messages_t *messages;\r
+> @@ -598,7 +613,7 @@ notmuch_reply_format_headers_only(void *ctx,\r
+>      g_mime_object_set_header (GMIME_OBJECT (reply),\r
+>                                "References", references);\r
+>  \r
+> -    (void)add_recipients_from_message (reply, config, message);\r
+> +    (void)add_recipients_from_message (reply, config, message, reply_to_all);\r
+>  \r
+>      reply_headers = g_mime_object_to_string (GMIME_OBJECT (reply));\r
+>      printf ("%s", reply_headers);\r
+> @@ -620,7 +635,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+>      notmuch_query_t *query;\r
+>      char *opt, *query_string;\r
+>      int i, ret = 0;\r
+> -    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params);\r
+> +    int reply_to_all = 1;\r
+> +    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, int reply_to_all);\r
+>      notmuch_show_params_t params;\r
+>  \r
+>      reply_format_func = notmuch_reply_format_default;\r
+> @@ -654,6 +670,16 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+>              g_object_unref (session);\r
+>              session = NULL;\r
+>          }\r
+> +    } else if (STRNCMP_LITERAL (argv[i], "--reply-to=") == 0) {\r
+> +        opt = argv[i] + sizeof ("--reply-to=") - 1;\r
+> +        if (strcmp (opt, "sender") == 0) {\r
+> +             reply_to_all = 0;\r
+> +        } else if (strcmp (opt, "all") == 0) {\r
+> +             reply_to_all = 1;\r
+> +        } else {\r
+> +             fprintf (stderr, "Invalid value for --reply-to: %s\n", opt);\r
+> +             return 1;\r
+> +        }\r
+>      } else {\r
+>          fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
+>          return 1;\r
+> @@ -689,7 +715,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+>      return 1;\r
+>      }\r
+>  \r
+> -    if (reply_format_func (ctx, config, query, &params) != 0)\r
+> +    if (reply_format_func (ctx, config, query, &params, reply_to_all) != 0)\r
+>      return 1;\r
+>  \r
+>      notmuch_query_destroy (query);\r
+> -- \r
+> 1.7.2.3\r
+> \r