[RFC PATCH 3/6] cli/reply: return internet address list from get header funcs
authorJani Nikula <jani@nikula.org>
Sun, 19 Jun 2016 20:15:31 +0000 (23:15 +0300)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 23:22:07 +0000 (16:22 -0700)
0a/75840581cdd776ec1f243fe53dd5590259fc62 [new file with mode: 0644]

diff --git a/0a/75840581cdd776ec1f243fe53dd5590259fc62 b/0a/75840581cdd776ec1f243fe53dd5590259fc62
new file mode 100644 (file)
index 0000000..2e2be90
--- /dev/null
@@ -0,0 +1,249 @@
+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 arlo.cworth.org (Postfix) with ESMTP id DBA936DE091F\r
+ for <notmuch@notmuchmail.org>; Sun, 19 Jun 2016 13:17:20 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.568\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.568 tagged_above=-999 required=5 tests=[AWL=0.152,\r
+  DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7,\r
+ RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id Kgy9ZBscP9r9 for <notmuch@notmuchmail.org>;\r
+ Sun, 19 Jun 2016 13:17:13 -0700 (PDT)\r
+Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com\r
+ [74.125.82.66]) by arlo.cworth.org (Postfix) with ESMTPS id AB9456DE01F9 for\r
+ <notmuch@notmuchmail.org>; Sun, 19 Jun 2016 13:17:06 -0700 (PDT)\r
+Received: by mail-wm0-f66.google.com with SMTP id c82so6633603wme.3\r
+ for <notmuch@notmuchmail.org>; Sun, 19 Jun 2016 13:17:06 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=nikula-org.20150623.gappssmtp.com; s=20150623;\r
+ h=from:to:cc:subject:date:message-id:in-reply-to:references\r
+ :in-reply-to:references;\r
+ bh=0Wi7c1OZnF7bwlFMEApf+3G2yvM9M/8CtF2wBYS6gLU=;\r
+ b=GKNO3g2dxWqwIzYmKcgv2Z77VjnJqOpK9jUAoZFB80ywugL5tc395kodLILmAXS1yV\r
+ qY62aKDaOuLOs12FWVlq7U77mYaSnklqXHY9Ng2z4k4JF5gjpSiuc7z8i3vXaOXCDQXY\r
+ +og/1y5aAa15bzEf1MAIhqdLrGJSBCcTsbkyzsiJjV1DT/uJ0WdNiJOahskOrNFbxJra\r
+ xZFoY0wjxzAmigdTKq6r4CB2Y/tsQvRGDLqMmhREgxwEGtFi2scVxO+Aal+RrnqjDx0T\r
+ +N137WX5Vn7dgoS363VlrFY9gkvmqiH+aEAI9/vfRoVmYIejZfUIguuuLippw1+M8poC\r
+ +sVw==\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
+ :references:in-reply-to:references;\r
+ bh=0Wi7c1OZnF7bwlFMEApf+3G2yvM9M/8CtF2wBYS6gLU=;\r
+ b=eYLymwi0ULsxXbQUtUrgevI+0Dsu2IElHn49KYs08iAE57drW2Y0/DHSyUiTucWars\r
+ chtuaJJF6GLjZlHij2s47TMa7k9C3ENqKtExnRVGZwI2P/he+FSYznAPRBX4nYkih7KL\r
+ WdDvhZGWoqEskuy89jOtRZ00IndRXkpqNDvstj093gNaOFuGxLPP8P9g5zOLApO8O5lv\r
+ MD0a1cxreWfRLOHuJCEshltutPoFnjZdfF2ihTVDZ/7JLAjIZWu5nYR44WOXVPGfl+uy\r
+ 8pVUS2FPkveMi08YPNhy+c9w/l6y1qzDX58HiNvX09f14z1Wa05yN6ZZxe2m9vB78bWJ\r
+ MKrA==\r
+X-Gm-Message-State:\r
+ ALyK8tJjugttvjfj+lmMaEJHt2Dj7omjYcFITkdW5k+A1epogUeYSWK6pgKTcvadi1EP0w==\r
+X-Received: by 10.28.54.147 with SMTP id y19mr7724156wmh.68.1466367425247;\r
+ Sun, 19 Jun 2016 13:17:05 -0700 (PDT)\r
+Received: from localhost (mobile-access-bcee4e-81.dhcp.inet.fi.\r
+ [188.238.78.81])\r
+ by smtp.gmail.com with ESMTPSA id kd7sm60038230wjc.33.2016.06.19.13.17.04\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Sun, 19 Jun 2016 13:17:04 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Jani Nikula <jani@nikula.org>,\r
+       notmuch@notmuchmail.org\r
+Cc: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
+Subject: [RFC PATCH 3/6] cli/reply: return internet address list from get\r
+ header funcs\r
+Date: Sun, 19 Jun 2016 23:15:31 +0300\r
+Message-Id:\r
+ <c4c94e14896bd50b1653dd54662bac7c5bfdd03a.1466366737.git.jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <cover.1466366737.git.jani@nikula.org>\r
+References: <cover.1466284726.git.jani@nikula.org>\r
+ <cover.1466366737.git.jani@nikula.org>\r
+In-Reply-To: <cover.1466366737.git.jani@nikula.org>\r
+References: <cover.1466366737.git.jani@nikula.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://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: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 19 Jun 2016 20:17:21 -0000\r
+\r
+Pass in GMimeMessage to simplify To/Cc/Bcc headers. We'll eventually\r
+remove the notmuch message passing altogether, but keep both for now\r
+to not make too big changes at once.\r
+\r
+Get rid of an intermediate function.\r
+\r
+The small annoyance is the ownership differences in the address lists.\r
+---\r
+ notmuch-reply.c | 73 ++++++++++++++++++++++++---------------------------------\r
+ 1 file changed, 30 insertions(+), 43 deletions(-)\r
+\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index d90f46f9bed3..98034485c546 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -227,31 +227,6 @@ scan_address_list (InternetAddressList *list,\r
+     return n;\r
+ }\r
\r
+-/* Scan addresses in 'recipients'.\r
+- *\r
+- * See the documentation of scan_address_list() above. This function\r
+- * does exactly the same, but converts 'recipients' to an\r
+- * InternetAddressList first.\r
+- */\r
+-static unsigned int\r
+-scan_address_string (const char *recipients,\r
+-                   notmuch_config_t *config,\r
+-                   GMimeMessage *message,\r
+-                   GMimeRecipientType type,\r
+-                   const char **user_from)\r
+-{\r
+-    InternetAddressList *list;\r
+-\r
+-    if (recipients == NULL)\r
+-      return 0;\r
+-\r
+-    list = internet_address_list_parse_string (recipients);\r
+-    if (list == NULL)\r
+-      return 0;\r
+-\r
+-    return scan_address_list (list, config, message, type, user_from);\r
+-}\r
+-\r
+ /* Does the address in the Reply-To header of 'message' already appear\r
+  * in either the 'To' or 'Cc' header of the message?\r
+  */\r
+@@ -287,11 +262,12 @@ reply_to_header_is_redundant (notmuch_message_t *message, const char *reply_to)\r
+     return 0;\r
+ }\r
\r
+-static const char *get_sender(notmuch_message_t *message)\r
++static InternetAddressList *get_sender(notmuch_message_t *message,\r
++                                     GMimeMessage *mime_message)\r
+ {\r
+     const char *reply_to;\r
\r
+-    reply_to = notmuch_message_get_header (message, "reply-to");\r
++    reply_to = g_mime_message_get_reply_to (mime_message);\r
+     if (reply_to && *reply_to) {\r
+         /*\r
+        * Some mailing lists munge the Reply-To header despite it\r
+@@ -307,25 +283,32 @@ static const char *get_sender(notmuch_message_t *message)\r
+        * will always appear in the reply if reply_all is true.\r
+        */\r
+       if (! reply_to_header_is_redundant (message, reply_to))\r
+-          return reply_to;\r
++          return internet_address_list_parse_string (reply_to);\r
+     }\r
\r
+-    return notmuch_message_get_header (message, "from");\r
++    return internet_address_list_parse_string (\r
++      g_mime_message_get_sender (mime_message));\r
+ }\r
\r
+-static const char *get_to(notmuch_message_t *message)\r
++static InternetAddressList *get_to(unused(notmuch_message_t *message),\r
++                                 GMimeMessage *mime_message)\r
+ {\r
+-    return notmuch_message_get_header (message, "to");\r
++    return g_mime_message_get_recipients (mime_message,\r
++                                        GMIME_RECIPIENT_TYPE_TO);\r
+ }\r
\r
+-static const char *get_cc(notmuch_message_t *message)\r
++static InternetAddressList *get_cc(unused(notmuch_message_t *message),\r
++                                 GMimeMessage *mime_message)\r
+ {\r
+-    return notmuch_message_get_header (message, "cc");\r
++    return g_mime_message_get_recipients (mime_message,\r
++                                        GMIME_RECIPIENT_TYPE_CC);\r
+ }\r
\r
+-static const char *get_bcc(notmuch_message_t *message)\r
++static InternetAddressList *get_bcc(unused(notmuch_message_t *message),\r
++                                  GMimeMessage *mime_message)\r
+ {\r
+-    return notmuch_message_get_header (message, "bcc");\r
++    return g_mime_message_get_recipients (mime_message,\r
++                                        GMIME_RECIPIENT_TYPE_BCC);\r
+ }\r
\r
+ /* Augment the recipients of 'reply' from the "Reply-to:", "From:",\r
+@@ -344,10 +327,12 @@ static const char *\r
+ add_recipients_from_message (GMimeMessage *reply,\r
+                            notmuch_config_t *config,\r
+                            notmuch_message_t *message,\r
++                           GMimeMessage *mime_message,\r
+                            notmuch_bool_t reply_all)\r
+ {\r
+     struct {\r
+-      const char * (*get_header)(notmuch_message_t *message);\r
++      InternetAddressList * (*get_header)(notmuch_message_t *message,\r
++                                          GMimeMessage *mime_message);\r
+       GMimeRecipientType recipient_type;\r
+     } reply_to_map[] = {\r
+       { get_sender,   GMIME_RECIPIENT_TYPE_TO },\r
+@@ -360,12 +345,12 @@ add_recipients_from_message (GMimeMessage *reply,\r
+     unsigned int n = 0;\r
\r
+     for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {\r
+-      const char *recipients;\r
++      InternetAddressList *recipients;\r
\r
+-      recipients = reply_to_map[i].get_header (message);\r
++      recipients = reply_to_map[i].get_header (message, mime_message);\r
\r
+-      n += scan_address_string (recipients, config, reply,\r
+-                                reply_to_map[i].recipient_type, &from_addr);\r
++      n += scan_address_list (recipients, config, reply,\r
++                              reply_to_map[i].recipient_type, &from_addr);\r
\r
+       if (!reply_all && n) {\r
+           /* Stop adding new recipients in reply-to-sender mode if\r
+@@ -536,6 +521,7 @@ static GMimeMessage *\r
+ create_reply_message(void *ctx,\r
+                    notmuch_config_t *config,\r
+                    notmuch_message_t *message,\r
++                   GMimeMessage *mime_message,\r
+                    notmuch_bool_t reply_all,\r
+                    notmuch_bool_t limited)\r
+ {\r
+@@ -566,8 +552,8 @@ create_reply_message(void *ctx,\r
\r
+     g_mime_object_set_header (GMIME_OBJECT (reply), "References", references);\r
\r
+-    from_addr = add_recipients_from_message (reply, config,\r
+-                                           message, reply_all);\r
++    from_addr = add_recipients_from_message (reply, config, message,\r
++                                           mime_message, reply_all);\r
\r
+     /* The above is all that is needed for limited headers. */\r
+     if (limited)\r
+@@ -666,7 +652,8 @@ static int do_reply(notmuch_config_t *config,\r
+       if (mime_node_open (config, message, &params->crypto, &node))\r
+           return 1;\r
\r
+-      reply = create_reply_message (config, config, message, reply_all,\r
++      reply = create_reply_message (config, config, message,\r
++                                    GMIME_MESSAGE (node->part), reply_all,\r
+                                     format == FORMAT_HEADERS_ONLY);\r
+       if (!reply)\r
+           return 1;\r
+-- \r
+2.1.4\r
+\r