Re: [PATCH v7 1/3] Add support for structured output formatters.
[notmuch-archives.git] / da / b69a04f7162721cce45726c7642520e62092e2
1 Return-Path: <dmitry.kurochkin@gmail.com>\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 29B88429E2A\r
6         for <notmuch@notmuchmail.org>; Sat, 28 May 2011 15:03:29 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.799\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id ErF1iPfad7MK for <notmuch@notmuchmail.org>;\r
17         Sat, 28 May 2011 15:03:27 -0700 (PDT)\r
18 Received: from mail-fx0-f53.google.com (mail-fx0-f53.google.com\r
19         [209.85.161.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 14E0D429E27\r
22         for <notmuch@notmuchmail.org>; Sat, 28 May 2011 15:03:26 -0700 (PDT)\r
23 Received: by fxm8 with SMTP id 8so2108915fxm.26\r
24         for <notmuch@notmuchmail.org>; Sat, 28 May 2011 15:03:25 -0700 (PDT)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
26         h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer;\r
27         bh=5C1tbto9X7nitmA1TngreZgvSoscbeBg0DZf0UpY9Tk=;\r
28         b=sGs/NHuYfl7kuaJLrqQornqwEIlcjosXMc4IfgagA7G6LjtKddzPIhq+i6uRAXId0y\r
29         NV/w4xyxXUYkQAdy+xao08AfSgpi2+1FjndWK+owJ8A+i2wdULtaFsPHECi40kuD/RPx\r
30         ffCMX09nIM8Fp5UXM1kd3T1iBqveyDsZpyTKs=\r
31 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;\r
32         h=from:to:cc:subject:date:message-id:x-mailer;\r
33         b=H2ib3hWIsmb1k1KGc+UYmntMTynh35n4bHP0o2ywAbjvcI6W3ztNK9Yo0qNH66auHh\r
34         fnD52B1lyM119qtntSAkGh1Yp9kjUgVJSAGSIz3j99afOo2jiMqksuScvM86GbXR2CUd\r
35         gAmRM80618I3daUnpQ4lWilANZaYkez66D6xM=\r
36 Received: by 10.223.59.92 with SMTP id k28mr276653fah.27.1306620205560;\r
37         Sat, 28 May 2011 15:03:25 -0700 (PDT)\r
38 Received: from localhost ([91.144.186.21])\r
39         by mx.google.com with ESMTPS id c1sm276644faa.37.2011.05.28.15.03.24\r
40         (version=TLSv1/SSLv3 cipher=OTHER);\r
41         Sat, 28 May 2011 15:03:24 -0700 (PDT)\r
42 From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH 1/2] Add part filename and content-id in notmuch show output\r
45         if available.\r
46 Date: Sun, 29 May 2011 02:03:47 +0400\r
47 Message-Id: <1306620228-24351-1-git-send-email-dmitry.kurochkin@gmail.com>\r
48 X-Mailer: git-send-email 1.7.5.3\r
49 X-BeenThere: notmuch@notmuchmail.org\r
50 X-Mailman-Version: 2.1.13\r
51 Precedence: list\r
52 List-Id: "Use and development of the notmuch mail system."\r
53         <notmuch.notmuchmail.org>\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
57 List-Post: <mailto:notmuch@notmuchmail.org>\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
61 X-List-Received-Date: Sat, 28 May 2011 22:03:29 -0000\r
62 \r
63 Before the change, notmuch show output had filename only for\r
64 parts with "Content-Disposition: attachment".  But parts with\r
65 inline disposition may have filename as well.\r
66 \r
67 The patch makes notmuch show always output filename if available,\r
68 independent of Content-Disposition.  Both JSON and text output\r
69 formats are changed.\r
70 \r
71 Also, the patch adds Content-id to text output format of notmuch\r
72 show.\r
73 \r
74 The main goal of these changes is to have filenames on Emacs\r
75 buttons for inline attachments.  In particular, this is very\r
76 helpful for inline patches.\r
77 \r
78 Note: text format changes may require updates in clients that use\r
79 it.  The changes are:\r
80 \r
81 * text part header format changed from:\r
82 \r
83     ^Lpart{ ID: 2, Content-type: text/x-diff\r
84 \r
85   to:\r
86 \r
87     ^Lpart{ ID: 2, Filename: cool-feature.patch, Content-type: text/x-diff\r
88 \r
89 * attachment format changed from:\r
90 \r
91     ^Lattachment{ ID: 4, Content-type: application/octet-stream\r
92     Attachment: data.tar.bz2 (application/octet-stream)\r
93     Non-text part: application/octet-stream\r
94     ^Lattachment}\r
95 \r
96   to:\r
97 \r
98     ^Lattachment{ ID: 4, Filename: data.tar.bz2, Content-type: application/octet-stream\r
99     Non-text part: application/octet-stream\r
100     ^Lattachment}\r
101 ---\r
102  notmuch-show.c |   24 ++++++++++++------------\r
103  1 files changed, 12 insertions(+), 12 deletions(-)\r
104 \r
105 diff --git a/notmuch-show.c b/notmuch-show.c\r
106 index e90f07e..8f275d7 100644\r
107 --- a/notmuch-show.c\r
108 +++ b/notmuch-show.c\r
109 @@ -445,20 +445,22 @@ format_part_start_text (GMimeObject *part, int *part_count)\r
110  static void\r
111  format_part_content_text (GMimeObject *part)\r
112  {\r
113 -    GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (part);\r
114 +    const char *cid = g_mime_object_get_content_id (part);\r
115      GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));\r
116      GMimeStream *stream_stdout = g_mime_stream_file_new (stdout);\r
117  \r
118 -    printf (", Content-type: %s\n", g_mime_content_type_to_string (content_type));\r
119 -\r
120 -    if (disposition &&\r
121 -       strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)\r
122 +    if (GMIME_IS_PART (part))\r
123      {\r
124         const char *filename = g_mime_part_get_filename (GMIME_PART (part));\r
125 -       printf ("Attachment: %s (%s)\n", filename,\r
126 -               g_mime_content_type_to_string (content_type));\r
127 +       if (filename)\r
128 +           printf (", Filename: %s", filename);\r
129      }\r
130  \r
131 +    if (cid)\r
132 +       printf (", Content-id: %s", cid);\r
133 +\r
134 +    printf (", Content-type: %s\n", g_mime_content_type_to_string (content_type));\r
135 +\r
136      if (g_mime_content_type_is_type (content_type, "text", "*") &&\r
137         !g_mime_content_type_is_type (content_type, "text", "html"))\r
138      {\r
139 @@ -580,7 +582,6 @@ format_part_content_json (GMimeObject *part)\r
140      GMimeStream *stream_memory = g_mime_stream_mem_new ();\r
141      const char *cid = g_mime_object_get_content_id (part);\r
142      void *ctx = talloc_new (NULL);\r
143 -    GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (part);\r
144      GByteArray *part_content;\r
145  \r
146      printf (", \"content-type\": %s",\r
147 @@ -589,12 +590,11 @@ format_part_content_json (GMimeObject *part)\r
148      if (cid != NULL)\r
149             printf(", \"content-id\": %s", json_quote_str (ctx, cid));\r
150  \r
151 -    if (disposition &&\r
152 -       strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)\r
153 +    if (GMIME_IS_PART (part))\r
154      {\r
155         const char *filename = g_mime_part_get_filename (GMIME_PART (part));\r
156 -\r
157 -       printf (", \"filename\": %s", json_quote_str (ctx, filename));\r
158 +       if (filename)\r
159 +           printf (", \"filename\": %s", json_quote_str (ctx, filename));\r
160      }\r
161  \r
162      if (g_mime_content_type_is_type (content_type, "text", "*") &&\r
163 -- \r
164 1.7.5.3\r
165 \r