Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 6e / 813e189bbe19bb5b77478ef4cab347ab9398e5
1 Return-Path: <amdragon@mit.edu>\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 589F5431FAF\r
6         for <notmuch@notmuchmail.org>; Thu,  2 Aug 2012 18:15:09 -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.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 bc4P4AXYm3B4 for <notmuch@notmuchmail.org>;\r
16         Thu,  2 Aug 2012 18:15:08 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU\r
18         [18.7.68.34])\r
19         by olra.theworths.org (Postfix) with ESMTP id D46B6431FAE\r
20         for <notmuch@notmuchmail.org>; Thu,  2 Aug 2012 18:15:07 -0700 (PDT)\r
21 X-AuditID: 12074422-b7f1f6d00000090b-de-501b261b04f0\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
23         by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id C9.20.02315.B162B105; Thu,  2 Aug 2012 21:15:07 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q731F6jD012766; \r
27         Thu, 2 Aug 2012 21:15:06 -0400\r
28 Received: from drake.dyndns.org\r
29         (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
30         [209.6.116.242]) (authenticated bits=0)\r
31         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
32         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q731F4UM002791\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Thu, 2 Aug 2012 21:15:05 -0400 (EDT)\r
35 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
36         (envelope-from <amdragon@mit.edu>)\r
37         id 1Sx6To-0003wR-CH; Thu, 02 Aug 2012 21:15:04 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH v3 08/13] show: Convert format_part_sigstatus_json to use\r
41         sprinter\r
42 Date: Thu,  2 Aug 2012 21:14:54 -0400\r
43 Message-Id: <1343956499-14543-9-git-send-email-amdragon@mit.edu>\r
44 X-Mailer: git-send-email 1.7.10\r
45 In-Reply-To: <1343956499-14543-1-git-send-email-amdragon@mit.edu>\r
46 References: <1343956499-14543-1-git-send-email-amdragon@mit.edu>\r
47 X-Brightmail-Tracker:\r
48  H4sIAAAAAAAAA+NgFjrOIsWRmVeSWpSXmKPExsUixCmqrCutJh1gMOOnjMXquTwW12/OZLZ4\r
49         s3IeqwOzx85Zd9k9Dn9dyOLxbNUt5gDmKC6blNSczLLUIn27BK6Mzas2sBZcMq2Y3LCSpYHx\r
50         r0YXIyeHhICJxMaNM1khbDGJC/fWs3UxcnEICexjlDj0dS4jhLOeUWL/88dQmYdMEtNff4By\r
51         5jJKbJ+2BKyfTUBDYtv+5YwgtoiAtMTOu7PB4swCcRJbpvwHiwsLBEmca50JZrMIqEqceHKZ\r
52         CcTmFXCQaOg5AXWHvMTT+31sIDangKPE67evwOqFgGqWt3WzTmDkX8DIsIpRNiW3Sjc3MTOn\r
53         ODVZtzg5MS8vtUjXVC83s0QvNaV0EyMovNhdlHYw/jyodIhRgINRiYfXWFI6QIg1say4MvcQ\r
54         oyQHk5IoL7MSUIgvKT+lMiOxOCO+qDQntfgQowQHs5IIb9USqQAh3pTEyqrUonyYlDQHi5I4\r
55         77WUm/5CAumJJanZqakFqUUwWRkODiUJ3j5VoKGCRanpqRVpmTklCGkmDk6Q4TxAw7eD1PAW\r
56         FyTmFmemQ+RPMSpKifOmgyQEQBIZpXlwvbD4f8UoDvSKMG87SBUPMHXAdb8CGswENNjODOTq\r
57         4pJEhJRUAyNnA2vI0mmhzLFbzN5Fnt+2pyZd2/tw927NX/XB3z8ck2Hu+sjA8VRT5NTZgssC\r
58         5pIdDlXT9/z+yn9K0Pa05MwVnWXvyhxv8VtKsKWuFMn89nHDhypD7vktE51/qX9aVr3DbNva\r
59         YLFtBS93PhRnVJcVZTTbt+zElQbDmbevrKkSm15RpRn+yEqJpTgj0VCLuag4EQAvGA2d2gIA        AA==\r
60 Cc: tomi.ollila@iki.fi\r
61 X-BeenThere: notmuch@notmuchmail.org\r
62 X-Mailman-Version: 2.1.13\r
63 Precedence: list\r
64 List-Id: "Use and development of the notmuch mail system."\r
65         <notmuch.notmuchmail.org>\r
66 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
68 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
69 List-Post: <mailto:notmuch@notmuchmail.org>\r
70 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
71 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
72         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
73 X-List-Received-Date: Fri, 03 Aug 2012 01:15:09 -0000\r
74 \r
75 ---\r
76  notmuch-show.c |  118 +++++++++++++++++++++++++++++---------------------------\r
77  1 file changed, 61 insertions(+), 57 deletions(-)\r
78 \r
79 diff --git a/notmuch-show.c b/notmuch-show.c\r
80 index 9852119..3ff32df 100644\r
81 --- a/notmuch-show.c\r
82 +++ b/notmuch-show.c\r
83 @@ -337,134 +337,138 @@ signer_status_to_string (GMimeSignerStatus x)\r
84  \r
85  #ifdef GMIME_ATLEAST_26\r
86  static void\r
87 -format_part_sigstatus_json (mime_node_t *node)\r
88 +format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)\r
89  {\r
90      GMimeSignatureList *siglist = node->sig_list;\r
91  \r
92 -    printf ("[");\r
93 +    sp->begin_list (sp);\r
94  \r
95      if (!siglist) {\r
96 -       printf ("]");\r
97 +       sp->end (sp);\r
98         return;\r
99      }\r
100  \r
101 -    void *ctx_quote = talloc_new (NULL);\r
102      int i;\r
103      for (i = 0; i < g_mime_signature_list_length (siglist); i++) {\r
104         GMimeSignature *signature = g_mime_signature_list_get_signature (siglist, i);\r
105  \r
106 -       if (i > 0)\r
107 -           printf (", ");\r
108 -\r
109 -       printf ("{");\r
110 +       sp->begin_map (sp);\r
111  \r
112         /* status */\r
113         GMimeSignatureStatus status = g_mime_signature_get_status (signature);\r
114 -       printf ("\"status\": %s",\r
115 -               json_quote_str (ctx_quote,\r
116 -                               signature_status_to_string (status)));\r
117 +       sp->map_key (sp, "status");\r
118 +       sp->string (sp, signature_status_to_string (status));\r
119  \r
120         GMimeCertificate *certificate = g_mime_signature_get_certificate (signature);\r
121         if (status == GMIME_SIGNATURE_STATUS_GOOD) {\r
122 -           if (certificate)\r
123 -               printf (", \"fingerprint\": %s", json_quote_str (ctx_quote, g_mime_certificate_get_fingerprint (certificate)));\r
124 +           if (certificate) {\r
125 +               sp->map_key (sp, "fingerprint");\r
126 +               sp->string (sp, g_mime_certificate_get_fingerprint (certificate));\r
127 +           }\r
128             /* these dates are seconds since the epoch; should we\r
129              * provide a more human-readable format string? */\r
130             time_t created = g_mime_signature_get_created (signature);\r
131 -           if (created != -1)\r
132 -               printf (", \"created\": %d", (int) created);\r
133 +           if (created != -1) {\r
134 +               sp->map_key (sp, "created");\r
135 +               sp->integer (sp, created);\r
136 +           }\r
137             time_t expires = g_mime_signature_get_expires (signature);\r
138 -           if (expires > 0)\r
139 -               printf (", \"expires\": %d", (int) expires);\r
140 +           if (expires > 0) {\r
141 +               sp->map_key (sp, "expires");\r
142 +               sp->integer (sp, expires);\r
143 +           }\r
144             /* output user id only if validity is FULL or ULTIMATE. */\r
145             /* note that gmime is using the term "trust" here, which\r
146              * is WRONG.  It's actually user id "validity". */\r
147             if (certificate) {\r
148                 const char *name = g_mime_certificate_get_name (certificate);\r
149                 GMimeCertificateTrust trust = g_mime_certificate_get_trust (certificate);\r
150 -               if (name && (trust == GMIME_CERTIFICATE_TRUST_FULLY || trust == GMIME_CERTIFICATE_TRUST_ULTIMATE))\r
151 -                   printf (", \"userid\": %s", json_quote_str (ctx_quote, name));\r
152 +               if (name && (trust == GMIME_CERTIFICATE_TRUST_FULLY || trust == GMIME_CERTIFICATE_TRUST_ULTIMATE)) {\r
153 +                   sp->map_key (sp, "userid");\r
154 +                   sp->string (sp, name);\r
155 +               }\r
156             }\r
157         } else if (certificate) {\r
158             const char *key_id = g_mime_certificate_get_key_id (certificate);\r
159 -           if (key_id)\r
160 -               printf (", \"keyid\": %s", json_quote_str (ctx_quote, key_id));\r
161 +           if (key_id) {\r
162 +               sp->map_key (sp, "keyid");\r
163 +               sp->string (sp, key_id);\r
164 +           }\r
165         }\r
166  \r
167         GMimeSignatureError errors = g_mime_signature_get_errors (signature);\r
168         if (errors != GMIME_SIGNATURE_ERROR_NONE) {\r
169 -           printf (", \"errors\": %d", errors);\r
170 +           sp->map_key (sp, "errors");\r
171 +           sp->integer (sp, errors);\r
172         }\r
173  \r
174 -       printf ("}");\r
175 +       sp->end (sp);\r
176       }\r
177  \r
178 -    printf ("]");\r
179 -\r
180 -    talloc_free (ctx_quote);\r
181 +    sp->end (sp);\r
182  }\r
183  #else\r
184  static void\r
185 -format_part_sigstatus_json (mime_node_t *node)\r
186 +format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)\r
187  {\r
188      const GMimeSignatureValidity* validity = node->sig_validity;\r
189  \r
190 -    printf ("[");\r
191 +    sp->begin_list (sp);\r
192  \r
193      if (!validity) {\r
194 -       printf ("]");\r
195 +       sp->end (sp);\r
196         return;\r
197      }\r
198  \r
199      const GMimeSigner *signer = g_mime_signature_validity_get_signers (validity);\r
200 -    int first = 1;\r
201 -    void *ctx_quote = talloc_new (NULL);\r
202 -\r
203      while (signer) {\r
204 -       if (first)\r
205 -           first = 0;\r
206 -       else\r
207 -           printf (", ");\r
208 -\r
209 -       printf ("{");\r
210 +       sp->begin_map (sp);\r
211  \r
212         /* status */\r
213 -       printf ("\"status\": %s",\r
214 -               json_quote_str (ctx_quote,\r
215 -                               signer_status_to_string (signer->status)));\r
216 +       sp->map_key (sp, "status");\r
217 +       sp->string (sp, signer_status_to_string (signer->status));\r
218  \r
219         if (signer->status == GMIME_SIGNER_STATUS_GOOD)\r
220         {\r
221 -           if (signer->fingerprint)\r
222 -               printf (", \"fingerprint\": %s", json_quote_str (ctx_quote, signer->fingerprint));\r
223 +           if (signer->fingerprint) {\r
224 +               sp->map_key (sp, "fingerprint");\r
225 +               sp->string (sp, signer->fingerprint);\r
226 +           }\r
227             /* these dates are seconds since the epoch; should we\r
228              * provide a more human-readable format string? */\r
229 -           if (signer->created)\r
230 -               printf (", \"created\": %d", (int) signer->created);\r
231 -           if (signer->expires)\r
232 -               printf (", \"expires\": %d", (int) signer->expires);\r
233 +           if (signer->created) {\r
234 +               sp->map_key (sp, "created");\r
235 +               sp->integer (sp, signer->created);\r
236 +           }\r
237 +           if (signer->expires) {\r
238 +               sp->map_key (sp, "expires");\r
239 +               sp->integer (sp, signer->expires);\r
240 +           }\r
241             /* output user id only if validity is FULL or ULTIMATE. */\r
242             /* note that gmime is using the term "trust" here, which\r
243              * is WRONG.  It's actually user id "validity". */\r
244             if ((signer->name) && (signer->trust)) {\r
245 -               if ((signer->trust == GMIME_SIGNER_TRUST_FULLY) || (signer->trust == GMIME_SIGNER_TRUST_ULTIMATE))\r
246 -                   printf (", \"userid\": %s", json_quote_str (ctx_quote, signer->name));\r
247 +               if ((signer->trust == GMIME_SIGNER_TRUST_FULLY) || (signer->trust == GMIME_SIGNER_TRUST_ULTIMATE)) {\r
248 +                   sp->map_key (sp, "userid");\r
249 +                   sp->string (sp, signer->name);\r
250 +               }\r
251             }\r
252         } else {\r
253 -           if (signer->keyid)\r
254 -               printf (", \"keyid\": %s", json_quote_str (ctx_quote, signer->keyid));\r
255 +           if (signer->keyid) {\r
256 +              sp->map_key (sp, "keyid");\r
257 +              sp->string (sp, signer->keyid);\r
258 +          }\r
259         }\r
260         if (signer->errors != GMIME_SIGNER_ERROR_NONE) {\r
261 -           printf (", \"errors\": %d", signer->errors);\r
262 +          sp->map_key (sp, "errors");\r
263 +          sp->integer (sp, signer->errors);\r
264         }\r
265  \r
266 -       printf ("}");\r
267 +       sp->end (sp);\r
268         signer = signer->next;\r
269      }\r
270  \r
271 -    printf ("]");\r
272 -\r
273 -    talloc_free (ctx_quote);\r
274 +    sp->end (sp);\r
275  }\r
276  #endif\r
277  \r
278 @@ -607,7 +611,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,\r
279  \r
280      if (node->verify_attempted) {\r
281         printf (", \"sigstatus\": ");\r
282 -       format_part_sigstatus_json (node);\r
283 +       format_part_sigstatus_json (sp, node);\r
284      }\r
285  \r
286      printf (", \"content-type\": %s",\r
287 -- \r
288 1.7.10\r
289 \r