[PATCH v2 1/3] Adds the option "--reply-to=" to notmuch reply.
authorMark Walters <markwalters1009@gmail.com>
Thu, 26 May 2011 23:31:55 +0000 (00:31 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:38:24 +0000 (09:38 -0800)
20/99c3badc1348e10ae8ef1d0dfc13ae01e85e7f [new file with mode: 0644]

diff --git a/20/99c3badc1348e10ae8ef1d0dfc13ae01e85e7f b/20/99c3badc1348e10ae8ef1d0dfc13ae01e85e7f
new file mode 100644 (file)
index 0000000..50855c0
--- /dev/null
@@ -0,0 +1,213 @@
+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 1CDD2429E25\r
+       for <notmuch@notmuchmail.org>; Thu, 26 May 2011 16:32:37 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 1.424\r
+X-Spam-Level: *\r
+X-Spam-Status: No, score=1.424 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=2.223, 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 S9jR3Ak2HU7I for <notmuch@notmuchmail.org>;\r
+       Thu, 26 May 2011 16:32:35 -0700 (PDT)\r
+Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com\r
+ [74.125.82.45])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ E9F30429E33   for <notmuch@notmuchmail.org>; Thu, 26 May 2011 16:32:34 -0700\r
+ (PDT)\r
+Received: by wwi36 with SMTP id 36so1070600wwi.2\r
+       for <notmuch@notmuchmail.org>; Thu, 26 May 2011 16:32:33 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+       h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer\r
+       :in-reply-to:references;\r
+       bh=xGtWyzzQPvm5A/tGXug/4AW5/fDDiXblQNMVBweZ5pk=;\r
+       b=nAGkFjKnPy3wZicovDtMxSwOd66r2o9N8fZR5fuVh35jET0FKf5j3Y4uWhlCkJZCjF\r
+       BKCpJ1449eS3NWLqX8S7huFcshWXfgiZmdu9QmIuh0AgRl4iOCHlTrjdn7tOr7dwNbwB\r
+       Iw1liQQ3x+elg5EgVVbpUOs+a040LeUiGb/ho=\r
+DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       b=pxXWt/sCSpABRRalM22oyy2H2EeWTg4wgjrtX4d9CeWoAMi+6rdhm02yqALyOumrcy\r
+       C6NaAMqqa5p2AHfjOvnfCuJnFJ/AqZ8CL+79qj9EssqPqS3r0EOntpvYE+fxX6zayUFo\r
+       erEaHgI7cKk2l40imqr9Y08AqlAt3zXnWSpLQ=\r
+Received: by 10.227.198.10 with SMTP id em10mr1385458wbb.108.1306452753667;\r
+       Thu, 26 May 2011 16:32:33 -0700 (PDT)\r
+Received: from localhost.localdomain (93-97-25-209.zone5.bethere.co.uk\r
+       [93.97.25.209])\r
+       by mx.google.com with ESMTPS id fw15sm804800wbb.27.2011.05.26.16.32.31\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Thu, 26 May 2011 16:32:32 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 1/3] Adds the option "--reply-to=" to notmuch reply.\r
+Date: Fri, 27 May 2011 00:31:55 +0100\r
+Message-Id: <1306452717-19934-2-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.2.5\r
+In-Reply-To: <87pqn5cg4g.fsf@yoom.home.cworth.org>\r
+References: <87pqn5cg4g.fsf@yoom.home.cworth.org>\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: Thu, 26 May 2011 23:32:37 -0000\r
+\r
+Possible values are "sender" which replies just to sender and\r
+"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
+Note 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 |   46 +++++++++++++++++++++++++++++++++++-----------\r
+ 1 files changed, 35 insertions(+), 11 deletions(-)\r
+\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index ab15650..98ae94a 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -191,7 +191,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
+@@ -271,7 +272,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
+@@ -311,9 +313,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
++          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
+@@ -453,7 +466,7 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message\r
+ }\r
\r
+ static int\r
+-notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query)\r
++notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_to_all)\r
+ {\r
+     GMimeMessage *reply;\r
+     notmuch_messages_t *messages;\r
+@@ -484,7 +497,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_\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
+@@ -531,7 +544,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_\r
\r
+ /* This format is currently tuned for a git send-email --notmuch hook */\r
+ static int\r
+-notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query)\r
++notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_to_all)\r
+ {\r
+     GMimeMessage *reply;\r
+     notmuch_messages_t *messages;\r
+@@ -571,7 +584,7 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q\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
+@@ -593,7 +606,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);\r
++    int reply_to_all = 1;\r
++    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_to_all);\r
\r
+     reply_format_func = notmuch_reply_format_default;\r
\r
+@@ -612,6 +626,16 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+               fprintf (stderr, "Invalid value for --format: %s\n", opt);\r
+               return 1;\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
+@@ -647,7 +671,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+       return 1;\r
+     }\r
\r
+-    if (reply_format_func (ctx, config, query) != 0)\r
++    if (reply_format_func (ctx, config, query, reply_to_all) != 0)\r
+       return 1;\r
\r
+     notmuch_query_destroy (query);\r
+-- \r
+1.7.2.5\r
+\r