[PATCH v2 05/14] cli/reply: reorganize create_reply_message()
[notmuch-archives.git] / 18 / 4fab97e3debfb20edfb7639f5bb90f8c61ba61
1 Return-Path: <jani@nikula.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5  by arlo.cworth.org (Postfix) with ESMTP id 886FE6DE39F9\r
6  for <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:39:30 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.573\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-0.573 tagged_above=-999 required=5 tests=[AWL=0.147,\r
13   DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7,\r
14  RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=disabled\r
15 Received: from arlo.cworth.org ([127.0.0.1])\r
16  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
17  with ESMTP id NQTTjdzCLUrp for <notmuch@notmuchmail.org>;\r
18  Sat, 13 Aug 2016 04:39:22 -0700 (PDT)\r
19 Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com\r
20  [74.125.82.65]) by arlo.cworth.org (Postfix) with ESMTPS id 4CEDE6DE38D1 for\r
21  <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:39:11 -0700 (PDT)\r
22 Received: by mail-wm0-f65.google.com with SMTP id i5so2016665wmg.2\r
23  for <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:39:11 -0700 (PDT)\r
24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25  d=nikula-org.20150623.gappssmtp.com; s=20150623;\r
26  h=from:to:cc:subject:date:message-id:in-reply-to:references\r
27  :in-reply-to:references;\r
28  bh=fbeShvw4M66SrxkIEgtBhkFxVPPUGacbY8QcRCVt1P8=;\r
29  b=D40EZr4nheHCp+XA042QJMLrpm/bjnHXiZh+5QgkIjxYZQ/CAUVRujJltzHoqNrUVM\r
30  +5hlNASWdIDDb/2k7cUX8loo8pdugb7odH5jiKRXyXhzAFWkVWlsUbtNtDjiCVg5mpyg\r
31  Lem6er+u6xqNWfFLl+PUnbQ7iiVu0Z0ebw+3GDNf8NfmTgvw+gvg0mfFSQ1kuOHntxqU\r
32  VdGYg6+Vkm12DMNJ6kBwrpvbWKMdhNSPohMHim5F85UOnMtntr2O2qeQFRIzknLTRFrI\r
33  D7pbcIYllFfWncyjeA3vCO4yrfW6E6YnOvGgEYc0kl3dySnoTvuwBtLlLQk6joNnfqGk\r
34  vgAA==\r
35 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
36  d=1e100.net; s=20130820;\r
37  h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
38  :references:in-reply-to:references;\r
39  bh=fbeShvw4M66SrxkIEgtBhkFxVPPUGacbY8QcRCVt1P8=;\r
40  b=B6OxzOgwdAfP93kCON8Ou8rrzwLWK5KEV1C/MoK435NCOEw5vjZ0bgITaXA5A30gAZ\r
41  9TrzRjB+FaCyH2MiqRVkEhdnzwBNatVYnC7AN81G4nmGC/jGtyHQ+r7TeTSyppbWR4Sg\r
42  zfj9/wCCA1eyfndA1oA0vYUl/Y1D/fzIUjbDUb/hP4E3FksxBlfcd5fSsnBc9/9Iq9tA\r
43  CryhQe21cCtnx8t6KRW8kq+Skxs9BkGz56W8mO7CRO1brHrIWo7pL4VJiLOSdpvYXsYB\r
44  TXlSn09cHAKg/lsNLGAsg8zWGwwnUAzxx3w8inZV7M9+9kL65lchUcaCY5XSycBeBUiu\r
45  v+HA==\r
46 X-Gm-Message-State:\r
47  AEkooutgaTA8K7L2TDA5IDumZ20jXLQCulLVJZaCBfJQD4JlGLu03L+6JbuwZMfc+Qw34Q==\r
48 X-Received: by 10.194.135.205 with SMTP id pu13mr24239190wjb.37.1471088349934;\r
49   Sat, 13 Aug 2016 04:39:09 -0700 (PDT)\r
50 Received: from localhost (mobile-access-bcee63-250.dhcp.inet.fi.\r
51  [188.238.99.250])\r
52  by smtp.gmail.com with ESMTPSA id p1sm11776270wjd.37.2016.08.13.04.39.09\r
53  (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
54  Sat, 13 Aug 2016 04:39:09 -0700 (PDT)\r
55 From: Jani Nikula <jani@nikula.org>\r
56 To: notmuch@notmuchmail.org\r
57 Cc: Daniel Kahn Gillmor <dkg@fifthhorseman.net>,\r
58         jani@nikula.org\r
59 Subject: [PATCH v2 05/14] cli/reply: reorganize create_reply_message()\r
60 Date: Sat, 13 Aug 2016 14:37:29 +0300\r
61 Message-Id:\r
62  <b56dcdd19ee572f1b895ba634644e0f3bfb69e11.1471088022.git.jani@nikula.org>\r
63 X-Mailer: git-send-email 2.1.4\r
64 In-Reply-To: <cover.1471088022.git.jani@nikula.org>\r
65 References: <cover.1471088022.git.jani@nikula.org>\r
66 In-Reply-To: <cover.1471088022.git.jani@nikula.org>\r
67 References: <cover.1471088022.git.jani@nikula.org>\r
68 X-BeenThere: notmuch@notmuchmail.org\r
69 X-Mailman-Version: 2.1.20\r
70 Precedence: list\r
71 List-Id: "Use and development of the notmuch mail system."\r
72  <notmuch.notmuchmail.org>\r
73 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
74  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
75 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
76 List-Post: <mailto:notmuch@notmuchmail.org>\r
77 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
78 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
79  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
80 X-List-Received-Date: Sat, 13 Aug 2016 11:39:30 -0000\r
81 \r
82 Again, in preparation for later unification, reorganize\r
83 create_reply_message() to be more similar to the open coded version in\r
84 the headers-only format reply code. Due to "pretty" header ordering,\r
85 there should be no change in output. There should be no functional\r
86 changes.\r
87 ---\r
88  notmuch-reply.c | 45 +++++++++++++++++++++------------------------\r
89  1 file changed, 21 insertions(+), 24 deletions(-)\r
90 \r
91 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
92 index 4b97ffa4f096..eb07405591fd 100644\r
93 --- a/notmuch-reply.c\r
94 +++ b/notmuch-reply.c\r
95 @@ -532,12 +532,20 @@ create_reply_message(void *ctx,\r
96         return NULL;\r
97      }\r
98  \r
99 -    subject = notmuch_message_get_header (message, "subject");\r
100 -    if (subject) {\r
101 -       if (strncasecmp (subject, "Re:", 3))\r
102 -           subject = talloc_asprintf (ctx, "Re: %s", subject);\r
103 -       g_mime_message_set_subject (reply, subject);\r
104 -    }\r
105 +    in_reply_to = talloc_asprintf (ctx, "<%s>",\r
106 +                                  notmuch_message_get_message_id (message));\r
107 +\r
108 +    g_mime_object_set_header (GMIME_OBJECT (reply), "In-Reply-To", in_reply_to);\r
109 +\r
110 +    orig_references = notmuch_message_get_header (message, "references");\r
111 +    if (!orig_references)\r
112 +       /* Treat errors like missing References headers. */\r
113 +       orig_references = "";\r
114 +    references = talloc_asprintf (ctx, "%s%s%s",\r
115 +                                 *orig_references ? orig_references : "",\r
116 +                                 *orig_references ? " " : "",\r
117 +                                 in_reply_to);\r
118 +    g_mime_object_set_header (GMIME_OBJECT (reply), "References", references);\r
119  \r
120      from_addr = add_recipients_from_message (reply, config,\r
121                                              message, reply_all);\r
122 @@ -572,25 +580,14 @@ create_reply_message(void *ctx,\r
123      from_addr = talloc_asprintf (ctx, "%s <%s>",\r
124                                  notmuch_config_get_user_name (config),\r
125                                  from_addr);\r
126 -    g_mime_object_set_header (GMIME_OBJECT (reply),\r
127 -                             "From", from_addr);\r
128 -\r
129 -    in_reply_to = talloc_asprintf (ctx, "<%s>",\r
130 -                                  notmuch_message_get_message_id (message));\r
131 -\r
132 -    g_mime_object_set_header (GMIME_OBJECT (reply),\r
133 -                             "In-Reply-To", in_reply_to);\r
134 +    g_mime_object_set_header (GMIME_OBJECT (reply), "From", from_addr);\r
135  \r
136 -    orig_references = notmuch_message_get_header (message, "references");\r
137 -    if (!orig_references)\r
138 -       /* Treat errors like missing References headers. */\r
139 -       orig_references = "";\r
140 -    references = talloc_asprintf (ctx, "%s%s%s",\r
141 -                                 *orig_references ? orig_references : "",\r
142 -                                 *orig_references ? " " : "",\r
143 -                                 in_reply_to);\r
144 -    g_mime_object_set_header (GMIME_OBJECT (reply),\r
145 -                             "References", references);\r
146 +    subject = notmuch_message_get_header (message, "subject");\r
147 +    if (subject) {\r
148 +       if (strncasecmp (subject, "Re:", 3))\r
149 +           subject = talloc_asprintf (ctx, "Re: %s", subject);\r
150 +       g_mime_message_set_subject (reply, subject);\r
151 +    }\r
152  \r
153      return reply;\r
154  }\r
155 -- \r
156 2.1.4\r
157 \r