From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id CCE45429E4D for ; Thu, 2 Aug 2012 18:15:12 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id L2tW2ssioUTB for ; Thu, 2 Aug 2012 18:15:10 -0700 (PDT) Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU [18.7.68.37]) by olra.theworths.org (Postfix) with ESMTP id 56A2C431E84 for ; Thu, 2 Aug 2012 18:15:08 -0700 (PDT) X-AuditID: 12074425-b7f9b6d0000008c4-bd-501b261beb97 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP id 29.BD.02244.B162B105; Thu, 2 Aug 2012 21:15:07 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id q731F6Io019971; Thu, 2 Aug 2012 21:15:06 -0400 Received: from drake.dyndns.org (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [209.6.116.242]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q731F4oF002789 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Thu, 2 Aug 2012 21:15:05 -0400 (EDT) Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1Sx6To-0003wP-Ac; Thu, 02 Aug 2012 21:15:04 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v3 07/13] show: Convert format_headers_json to use sprinter Date: Thu, 2 Aug 2012 21:14:53 -0400 Message-Id: <1343956499-14543-8-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1343956499-14543-1-git-send-email-amdragon@mit.edu> References: <1343956499-14543-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrKIsWRmVeSWpSXmKPExsUixG6noiutJh1gcK5fy2L1XB6L6zdnMlu8 WTmP1YHZY+esu+weh78uZPF4tuoWcwBzFJdNSmpOZllqkb5dAlfG1l8aBW9VK/5eX8HWwPhW rouRk0NCwETiR28XI4QtJnHh3nq2LkYuDiGBfYwS31pnQznrGSXuv7vAAuE8ZJLYsKOFHcKZ yyix/fsOFpB+NgENiW37l4PNEhGQlth5dzYriM0sECexZcp/sLiwgLfEubnTmboYOThYBFQl Xr91AQnzCjhInJl3hxXiDHmJp/f72EBsTgFHoJJXYK1CQDXL27pZJzDyL2BkWMUom5JbpZub mJlTnJqsW5ycmJeXWqRroZebWaKXmlK6iREcWi6qOxgnHFI6xCjAwajEw2skKR0gxJpYVlyZ e4hRkoNJSZSXWQkoxJeUn1KZkVicEV9UmpNafIhRgoNZSYS3aolUgBBvSmJlVWpRPkxKmoNF SZz3RspNfyGB9MSS1OzU1ILUIpisDAeHkgSvrCrQUMGi1PTUirTMnBKENBMHJ8hwHqDh9iA1 vMUFibnFmekQ+VOMilLivOwgCQGQREZpHlwvLPZfMYoDvSLMe0EFqIoHmDbgul8BDWYCGmxn BnJ1cUkiQkqqgdHqsW9IDecdpXeXxd5nvzI9GBIxq3+K0/ymFMWZrY9uPjpxMbmJTzTPTfHB 9u86Vh4bTxTcWsjgdsdBfWtxU+em5pc1542kJRtOyeZY2eXOe1NreNSXd5qU6hG+Jr1HS7tP Pnu43lb/oN/z/DTz6yuqrx7yn24zR6L9zr+VIn9LNC25jt1K6lNiKc5INNRiLipOBADsO7D8 2AIAAA== Cc: tomi.ollila@iki.fi X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Aug 2012 01:15:13 -0000 This no longer requires a talloc context (not that it really did before since it didn't return anything), so we remove its context argument. --- notmuch-client.h | 3 ++- notmuch-reply.c | 2 +- notmuch-show.c | 58 ++++++++++++++++++++++++++---------------------------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index 112574c..b11caff 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -183,7 +183,8 @@ format_part_json (const void *ctx, struct sprinter *sp, mime_node_t *node, notmuch_bool_t first, notmuch_bool_t output_body); void -format_headers_json (const void *ctx, GMimeMessage *message, notmuch_bool_t reply); +format_headers_json (struct sprinter *sp, GMimeMessage *message, + notmuch_bool_t reply); typedef enum { NOTMUCH_SHOW_TEXT_PART_REPLY = 1 << 0, diff --git a/notmuch-reply.c b/notmuch-reply.c index 07d4452..fa6665f 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -617,7 +617,7 @@ notmuch_reply_format_json(void *ctx, /* The headers of the reply message we've created */ printf ("{\"reply-headers\": "); - format_headers_json (ctx, reply, TRUE); + format_headers_json (sp, reply, TRUE); g_object_unref (G_OBJECT (reply)); reply = NULL; diff --git a/notmuch-show.c b/notmuch-show.c index b258f65..9852119 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -199,48 +199,46 @@ _is_from_line (const char *line) } void -format_headers_json (const void *ctx, GMimeMessage *message, notmuch_bool_t reply) +format_headers_json (sprinter_t *sp, GMimeMessage *message, + notmuch_bool_t reply) { - void *local = talloc_new (ctx); InternetAddressList *recipients; const char *recipients_string; - printf ("{%s: %s", - json_quote_str (local, "Subject"), - json_quote_str (local, g_mime_message_get_subject (message))); - printf (", %s: %s", - json_quote_str (local, "From"), - json_quote_str (local, g_mime_message_get_sender (message))); + sp->begin_map (sp); + + sp->map_key (sp, "Subject"); + sp->string (sp, g_mime_message_get_subject (message)); + + sp->map_key (sp, "From"); + sp->string (sp, g_mime_message_get_sender (message)); + recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO); recipients_string = internet_address_list_to_string (recipients, 0); - if (recipients_string) - printf (", %s: %s", - json_quote_str (local, "To"), - json_quote_str (local, recipients_string)); + if (recipients_string) { + sp->map_key (sp, "To"); + sp->string (sp, recipients_string); + } + recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC); recipients_string = internet_address_list_to_string (recipients, 0); - if (recipients_string) - printf (", %s: %s", - json_quote_str (local, "Cc"), - json_quote_str (local, recipients_string)); + if (recipients_string) { + sp->map_key (sp, "Cc"); + sp->string (sp, recipients_string); + } if (reply) { - printf (", %s: %s", - json_quote_str (local, "In-reply-to"), - json_quote_str (local, g_mime_object_get_header (GMIME_OBJECT (message), "In-reply-to"))); + sp->map_key (sp, "In-reply-to"); + sp->string (sp, g_mime_object_get_header (GMIME_OBJECT (message), "In-reply-to")); - printf (", %s: %s", - json_quote_str (local, "References"), - json_quote_str (local, g_mime_object_get_header (GMIME_OBJECT (message), "References"))); + sp->map_key (sp, "References"); + sp->string (sp, g_mime_object_get_header (GMIME_OBJECT (message), "References")); } else { - printf (", %s: %s", - json_quote_str (local, "Date"), - json_quote_str (local, g_mime_message_get_date_as_string (message))); + sp->map_key (sp, "Date"); + sp->string (sp, g_mime_message_get_date_as_string (message)); } - printf ("}"); - - talloc_free (local); + sp->end (sp); } /* Write a MIME text part out to the given stream. @@ -575,7 +573,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node, format_message_json (ctx, node->envelope_file); printf ("\"headers\": "); - format_headers_json (ctx, GMIME_MESSAGE (node->part), FALSE); + format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE); if (output_body) { printf (", \"body\": ["); @@ -651,7 +649,7 @@ format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node, } else if (GMIME_IS_MESSAGE (node->part)) { printf (", \"content\": [{"); printf ("\"headers\": "); - format_headers_json (local, GMIME_MESSAGE (node->part), FALSE); + format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE); printf (", \"body\": ["); terminator = "]}]"; -- 1.7.10