Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 6E84D421198 for ; Mon, 23 Jan 2012 12:29:09 -0800 (PST) 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 kweERuifQIFe for ; Mon, 23 Jan 2012 12:29:08 -0800 (PST) Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU [18.9.25.13]) by olra.theworths.org (Postfix) with ESMTP id 929F1429E54 for ; Mon, 23 Jan 2012 12:29:08 -0800 (PST) X-AuditID: 1209190d-b7fbf6d0000008ba-f4-4f1dc312ccef Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP id F6.4D.02234.213CD1F4; Mon, 23 Jan 2012 15:29:06 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q0NKT56p008194; Mon, 23 Jan 2012 15:29:05 -0500 Received: from drake.mit.edu (26-4-166.dynamic.csail.mit.edu [18.26.4.166]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0NKT4QU000598 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Mon, 23 Jan 2012 15:29:05 -0500 (EST) Received: from amthrax by drake.mit.edu with local (Exim 4.77) (envelope-from ) id 1RpQVj-0000Md-PE; Mon, 23 Jan 2012 15:29:03 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v3 2/2] show: Introduce mime_node formatter callback Date: Mon, 23 Jan 2012 15:29:01 -0500 Message-Id: <1327350541-1303-3-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1327350541-1303-1-git-send-email-amdragon@mit.edu> References: <1326918507-28033-1-git-send-email-amdragon@mit.edu> <1327350541-1303-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrMIsWRmVeSWpSXmKPExsUixCmqrSt0WNbfYO4JeYvrN2cyOzB6PFt1 izmAMYrLJiU1J7MstUjfLoEr4+e6s+wF86Uqvmx9zdzAuFGki5GTQ0LARGLm135GCFtM4sK9 9WxdjFwcQgL7GCVmr7nGBOFsYJTYeOYyC4RznEliwZRjUGXzGSWeP+1iB+lnE9CQ2LZ/Odgs EQFpiZ13Z7N2MXJwMAuoSfzpUgEJCwu4SDzYdZkJxGYRUJXo2/OBDcTmFbCX2NH0ngXiDAWJ c6vPgY3kFHCQuP5uKpgtJFAmsfv2ZeYJjPwLGBlWMcqm5Fbp5iZm5hSnJusWJyfm5aUW6Rrp 5WaW6KWmlG5iBIeNJO8OxncHlQ4xCnAwKvHwSsyU9RdiTSwrrsw9xCjJwaQkyquyDyjEl5Sf UpmRWJwRX1Sak1p8iFGCg1lJhNfosYy/EG9KYmVValE+TEqag0VJnFdV652fkEB6Yklqdmpq QWoRTFaGg0NJgrfkENBQwaLU9NSKtMycEoQ0EwcnyHAeoOFFIDW8xQWJucWZ6RD5U4yKUuK8 eSAJAZBERmkeXC8srl8xigO9IszbDVLFA0wJcN2vgAYzAQ3myJMCGVySiJCSAsb3yc+bhILW Bd2d1JASKxMhnVLFxBuSELXB01vv9OEfB3UVpv8s91/fseNl6oMvQb8tvi0+OJUta86mzOsu n898+ym9Im9V8N4goZIfcqmsR5T5vqucqAi9Iihn8O/J3f+R5QFaKhq6lw9HR96/V6/NxKqm m8m6T02c9XD51L2zpol+fXVis4ISS3FGoqEWc1FxIgB2BxLUxgIAAA== 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: Mon, 23 Jan 2012 20:29:09 -0000 This callback is the gateway to the new mime_node_t-based formatters. This maintains backwards compatibility so the formatters can be transitioned one at a time. Once all formatters are converted, the formatter structure can be reduced to only message_set_{start,sep,end} and part, most of show_message can be deleted, and all of show-message.c can be deleted. --- notmuch-client.h | 6 ++++++ notmuch-reply.c | 2 +- notmuch-show.c | 23 +++++++++++++++++++---- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index abfe5d3..59606b4 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -62,8 +62,14 @@ #define STRINGIFY(s) STRINGIFY_(s) #define STRINGIFY_(s) #s +struct mime_node; +struct notmuch_show_params; + typedef struct notmuch_show_format { const char *message_set_start; + void (*part) (const void *ctx, + struct mime_node *node, int indent, + struct notmuch_show_params *params); const char *message_start; void (*message) (const void *ctx, notmuch_message_t *message, diff --git a/notmuch-reply.c b/notmuch-reply.c index bf67960..f55b1d2 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -31,7 +31,7 @@ static void reply_part_content (GMimeObject *part); static const notmuch_show_format_t format_reply = { - "", + "", NULL, "", NULL, "", NULL, reply_headers_message_part, ">\n", "", diff --git a/notmuch-show.c b/notmuch-show.c index 682aa71..8185b02 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -42,7 +42,7 @@ static void format_part_end_text (GMimeObject *part); static const notmuch_show_format_t format_text = { - "", + "", NULL, "\fmessage{ ", format_message_text, "\fheader{\n", format_headers_text, format_headers_message_part_text, "\fheader}\n", "\fbody{\n", @@ -89,7 +89,7 @@ static void format_part_end_json (GMimeObject *part); static const notmuch_show_format_t format_json = { - "[", + "[", NULL, "{", format_message_json, "\"headers\": {", format_headers_json, format_headers_message_part_json, "}", ", \"body\": [", @@ -110,7 +110,7 @@ format_message_mbox (const void *ctx, unused (int indent)); static const notmuch_show_format_t format_mbox = { - "", + "", NULL, "", format_message_mbox, "", NULL, NULL, "", "", @@ -129,7 +129,7 @@ static void format_part_content_raw (GMimeObject *part); static const notmuch_show_format_t format_raw = { - "", + "", NULL, "", NULL, "", NULL, format_headers_message_part_text, "\n", "", @@ -850,6 +850,21 @@ show_message (void *ctx, int indent, notmuch_show_params_t *params) { + if (format->part) { + void *local = talloc_new (ctx); + mime_node_t *root, *part; + + if (mime_node_open (local, message, params->cryptoctx, params->decrypt, + &root) != NOTMUCH_STATUS_SUCCESS) + goto DONE; + part = mime_node_seek_dfs (root, params->part < 0 ? 0 : params->part); + if (part) + format->part (local, part, indent, params); + DONE: + talloc_free (local); + return; + } + if (params->part <= 0) { fputs (format->message_start, stdout); if (format->message) -- 1.7.7.3