[PATCH 4/4] Update NEWS for user.other_name
[notmuch-archives.git] / f2 / 6705dab9cfcce7e367a8c48db2e45fd70d4f4e
1 Return-Path: <awg@lagos.xvx.ca>\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 olra.theworths.org (Postfix) with ESMTP id B6A51431FD6\r
6         for <notmuch@notmuchmail.org>; Tue, 21 Feb 2012 22:46:48 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id k2iBzwk5M00Q for <notmuch@notmuchmail.org>;\r
16         Tue, 21 Feb 2012 22:46:46 -0800 (PST)\r
17 Received: from idcmail-mo2no.shaw.ca (idcmail-mo2no.shaw.ca [64.59.134.9])\r
18         by olra.theworths.org (Postfix) with ESMTP id D6F18431FC0\r
19         for <notmuch@notmuchmail.org>; Tue, 21 Feb 2012 22:46:45 -0800 (PST)\r
20 Received: from lb7f8hsrpno-svcs.dcs.int.inet (HELO pd7ml2no-ssvc.prod.shaw.ca)\r
21         ([10.0.144.222])\r
22         by pd7mo1no-svcs.prod.shaw.ca with ESMTP; 21 Feb 2012 23:46:45 -0700\r
23 X-Cloudmark-SP-Filtered: true\r
24 X-Cloudmark-SP-Result: v=1.1 cv=GZn8e3lTBEeJrlGK3+GUWyR5aYe1SJcDn5uEERMe9yQ=\r
25         c=1 sm=1\r
26         a=tXneHAB9HJoA:10 a=BLceEmwcHowA:10 a=yQp6g8lIsgqumF79BAsFDg==:17\r
27         a=bz-zy3QpAAAA:8 a=zj4l01KfgLfMms7IjnsA:9 a=tvKH82Il3pz4rfUQjx0A:7\r
28         a=NFWI-YhVVZsA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117\r
29 Received: from unknown (HELO lagos.xvx.ca) ([96.52.216.56])\r
30         by pd7ml2no-dmz.prod.shaw.ca with ESMTP; 21 Feb 2012 23:46:45 -0700\r
31 Received: by lagos.xvx.ca (Postfix, from userid 1000)\r
32         id BF63B8095C4E; Tue, 21 Feb 2012 23:46:44 -0700 (MST)\r
33 From: Adam Wolfe Gordon <awg+notmuch@xvx.ca>\r
34 To: notmuch@notmuchmail.org\r
35 Subject: [PATCH v6 05/10] reply: Add a JSON reply format.\r
36 Date: Tue, 21 Feb 2012 23:46:34 -0700\r
37 Message-Id: <1329893199-21630-6-git-send-email-awg+notmuch@xvx.ca>\r
38 X-Mailer: git-send-email 1.7.5.4\r
39 In-Reply-To: <1329893199-21630-1-git-send-email-awg+notmuch@xvx.ca>\r
40 References: <1329893199-21630-1-git-send-email-awg+notmuch@xvx.ca>\r
41 X-BeenThere: notmuch@notmuchmail.org\r
42 X-Mailman-Version: 2.1.13\r
43 Precedence: list\r
44 List-Id: "Use and development of the notmuch mail system."\r
45         <notmuch.notmuchmail.org>\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
49 List-Post: <mailto:notmuch@notmuchmail.org>\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
53 X-List-Received-Date: Wed, 22 Feb 2012 06:46:49 -0000\r
54 \r
55 This new JSON format for replies includes headers generated for a\r
56 reply message as well as the headers of the original message.  Using\r
57 this data, a client can intelligently create a reply. For example, the\r
58 emacs client will be able to create replies with quoted HTML parts by\r
59 parsing the HTML parts.\r
60 ---\r
61  notmuch-client.h |   10 ++++++++--\r
62  notmuch-reply.c  |   49 +++++++++++++++++++++++++++++++++++++++++++++++++\r
63  notmuch-show.c   |   30 ++++++++++++++++++++++--------\r
64  test/multipart   |    1 -\r
65  4 files changed, 79 insertions(+), 11 deletions(-)\r
66 \r
67 diff --git a/notmuch-client.h b/notmuch-client.h\r
68 index f4a62cc..ef4eaba 100644\r
69 --- a/notmuch-client.h\r
70 +++ b/notmuch-client.h\r
71 @@ -62,13 +62,13 @@\r
72  #define STRINGIFY(s) STRINGIFY_(s)\r
73  #define STRINGIFY_(s) #s\r
74  \r
75 -struct mime_node;\r
76 +typedef struct mime_node mime_node_t;\r
77  struct notmuch_show_params;\r
78  \r
79  typedef struct notmuch_show_format {\r
80      const char *message_set_start;\r
81      void (*part) (const void *ctx,\r
82 -                 struct mime_node *node, int indent,\r
83 +                 mime_node_t *node, int indent,\r
84                   const struct notmuch_show_params *params);\r
85      const char *message_start;\r
86      void (*message) (const void *ctx,\r
87 @@ -191,6 +191,12 @@ show_message_body (notmuch_message_t *message,\r
88  notmuch_status_t\r
89  show_one_part (const char *filename, int part);\r
90  \r
91 +void\r
92 +format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first);\r
93 +\r
94 +void\r
95 +format_headers_json (const void *ctx, GMimeMessage *message, notmuch_bool_t reply);\r
96 +\r
97  char *\r
98  json_quote_chararray (const void *ctx, const char *str, const size_t len);\r
99  \r
100 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
101 index 177e6ca..017c6ae 100644\r
102 --- a/notmuch-reply.c\r
103 +++ b/notmuch-reply.c\r
104 @@ -601,6 +601,51 @@ notmuch_reply_format_default(void *ctx,\r
105      return 0;\r
106  }\r
107  \r
108 +static int\r
109 +notmuch_reply_format_json(void *ctx,\r
110 +                         notmuch_config_t *config,\r
111 +                         notmuch_query_t *query,\r
112 +                         notmuch_show_params_t *params,\r
113 +                         notmuch_bool_t reply_all)\r
114 +{\r
115 +    GMimeMessage *reply;\r
116 +    notmuch_messages_t *messages;\r
117 +    notmuch_message_t *message;\r
118 +    mime_node_t *node;\r
119 +\r
120 +    if (notmuch_query_count_messages (query) != 1) {\r
121 +       fprintf (stderr, "Error: search term did not match precisely one message.\n");\r
122 +       return 1;\r
123 +    }\r
124 +\r
125 +    messages = notmuch_query_search_messages (query);\r
126 +    message = notmuch_messages_get (messages);\r
127 +    if (mime_node_open (ctx, message, params->cryptoctx, params->decrypt,\r
128 +                       &node) != NOTMUCH_STATUS_SUCCESS)\r
129 +       return 1;\r
130 +\r
131 +    reply = create_reply_message (ctx, config, message, reply_all);\r
132 +    if (!reply)\r
133 +       return 1;\r
134 +\r
135 +    /* The headers of the reply message we've created */\r
136 +    printf ("{\"reply-headers\": ");\r
137 +    format_headers_json (ctx, reply, TRUE);\r
138 +    g_object_unref (G_OBJECT (reply));\r
139 +    reply = NULL;\r
140 +\r
141 +    /* Start the original */\r
142 +    printf (", \"original\": ");\r
143 +\r
144 +    format_part_json (ctx, node, TRUE);\r
145 +\r
146 +    /* End */\r
147 +    printf ("}\n");\r
148 +    notmuch_message_destroy (message);\r
149 +\r
150 +    return 0;\r
151 +}\r
152 +\r
153  /* This format is currently tuned for a git send-email --notmuch hook */\r
154  static int\r
155  notmuch_reply_format_headers_only(void *ctx,\r
156 @@ -663,6 +708,7 @@ notmuch_reply_format_headers_only(void *ctx,\r
157  \r
158  enum {\r
159      FORMAT_DEFAULT,\r
160 +    FORMAT_JSON,\r
161      FORMAT_HEADERS_ONLY,\r
162  };\r
163  \r
164 @@ -682,6 +728,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
165      notmuch_opt_desc_t options[] = {\r
166         { NOTMUCH_OPT_KEYWORD, &format, "format", 'f',\r
167           (notmuch_keyword_t []){ { "default", FORMAT_DEFAULT },\r
168 +                                 { "json", FORMAT_JSON },\r
169                                   { "headers-only", FORMAT_HEADERS_ONLY },\r
170                                   { 0, 0 } } },\r
171         { NOTMUCH_OPT_KEYWORD, &reply_all, "reply-to", 'r',\r
172 @@ -700,6 +747,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
173  \r
174      if (format == FORMAT_HEADERS_ONLY)\r
175         reply_format_func = notmuch_reply_format_headers_only;\r
176 +    else if (format == FORMAT_JSON)\r
177 +       reply_format_func = notmuch_reply_format_json;\r
178      else\r
179         reply_format_func = notmuch_reply_format_default;\r
180  \r
181 diff --git a/notmuch-show.c b/notmuch-show.c\r
182 index 6a171a4..2126d78 100644\r
183 --- a/notmuch-show.c\r
184 +++ b/notmuch-show.c\r
185 @@ -290,8 +290,8 @@ format_headers_message_part_text (GMimeMessage *message)\r
186      printf ("Date: %s\n", g_mime_message_get_date_as_string (message));\r
187  }\r
188  \r
189 -static void\r
190 -format_headers_json (const void *ctx, GMimeMessage *message)\r
191 +void\r
192 +format_headers_json (const void *ctx, GMimeMessage *message, notmuch_bool_t reply)\r
193  {\r
194      void *local = talloc_new (ctx);\r
195      InternetAddressList *recipients;\r
196 @@ -315,9 +315,23 @@ format_headers_json (const void *ctx, GMimeMessage *message)\r
197         printf (", %s: %s",\r
198                 json_quote_str (local, "Cc"),\r
199                 json_quote_str (local, recipients_string));\r
200 -    printf (", %s: %s}",\r
201 -           json_quote_str (local, "Date"),\r
202 -           json_quote_str (local, g_mime_message_get_date_as_string (message)));\r
203 +\r
204 +    if (!reply)\r
205 +       printf (", %s: %s",\r
206 +               json_quote_str (local, "Date"),\r
207 +               json_quote_str (local, g_mime_message_get_date_as_string (message)));\r
208 +\r
209 +    if (reply) {\r
210 +       printf (", %s: %s",\r
211 +               json_quote_str (local, "In-reply-to"),\r
212 +               json_quote_str (local, g_mime_object_get_header (GMIME_OBJECT (message), "In-reply-to")));\r
213 +\r
214 +       printf (", %s: %s",\r
215 +               json_quote_str (local, "References"),\r
216 +               json_quote_str (local, g_mime_object_get_header (GMIME_OBJECT (message), "References")));\r
217 +    }\r
218 +\r
219 +    printf ("}");\r
220  \r
221      talloc_free (local);\r
222  }\r
223 @@ -652,7 +666,7 @@ format_part_text (const void *ctx, mime_node_t *node,\r
224      printf ("\f%s}\n", part_type);\r
225  }\r
226  \r
227 -static void\r
228 +void\r
229  format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)\r
230  {\r
231      /* Any changes to the JSON format should be reflected in the file\r
232 @@ -663,7 +677,7 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)\r
233         format_message_json (ctx, node->envelope_file);\r
234  \r
235         printf ("\"headers\": ");\r
236 -       format_headers_json (ctx, GMIME_MESSAGE (node->part));\r
237 +       format_headers_json (ctx, GMIME_MESSAGE (node->part), FALSE);\r
238  \r
239         printf (", \"body\": [");\r
240         format_part_json (ctx, mime_node_child (node, 0), first);\r
241 @@ -737,7 +751,7 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)\r
242      } else if (GMIME_IS_MESSAGE (node->part)) {\r
243         printf (", \"content\": [{");\r
244         printf ("\"headers\": ");\r
245 -       format_headers_json (local, GMIME_MESSAGE (node->part));\r
246 +       format_headers_json (local, GMIME_MESSAGE (node->part), FALSE);\r
247  \r
248         printf (", \"body\": [");\r
249         terminator = "]}]";\r
250 diff --git a/test/multipart b/test/multipart\r
251 index f102294..e7abcc2 100755\r
252 --- a/test/multipart\r
253 +++ b/test/multipart\r
254 @@ -590,7 +590,6 @@ EOF\r
255  test_expect_equal_file OUTPUT EXPECTED\r
256  \r
257  test_begin_subtest "'notmuch reply' to a multipart message with json format"\r
258 -test_subtest_known_broken\r
259  notmuch reply --format=json 'id:87liy5ap00.fsf@yoom.home.cworth.org' | notmuch_json_show_sanitize >OUTPUT\r
260  cat <<EOF >EXPECTED\r
261  {"reply-headers": {"Subject": "Re: Multipart message",\r
262 -- \r
263 1.7.5.4\r
264 \r