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 98A70429E25 for ; Wed, 11 Jan 2012 17:49:47 -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 c1ldN0hxlG3j for ; Wed, 11 Jan 2012 17:49:46 -0800 (PST) Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU [18.7.68.34]) by olra.theworths.org (Postfix) with ESMTP id B6942429E21 for ; Wed, 11 Jan 2012 17:49:46 -0800 (PST) X-AuditID: 12074422-b7fd66d0000008f9-aa-4f0e3c398863 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP id C8.2B.02297.93C3E0F4; Wed, 11 Jan 2012 20:49:45 -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 q0C1njXD005936; Wed, 11 Jan 2012 20:49:45 -0500 Received: from drake.mit.edu (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 q0C1nhHg001518 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Wed, 11 Jan 2012 20:49:45 -0500 (EST) Received: from amthrax by drake.mit.edu with local (Exim 4.77) (envelope-from ) id 1Rl9nS-000806-A9; Wed, 11 Jan 2012 20:49:42 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [RFC PATCH 2/5] show: Introduce mime_node formatter callback Date: Wed, 11 Jan 2012 20:49:30 -0500 Message-Id: <1326332973-30225-3-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1326332973-30225-1-git-send-email-amdragon@mit.edu> References: <1326332973-30225-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrEIsWRmVeSWpSXmKPExsUixCmqrWtpw+dv8Oq1vMX1mzOZHRg9nq26 xRzAGMVlk5Kak1mWWqRvl8CVcXzTL/aCVsmKC3PPMTYwbhHuYuTgkBAwkbj7VK2LkRPIFJO4 cG89WxcjF4eQwD5GiTWfljFBOBsYJY52LGeBcO4zSWya9pAVwpnPKHHyJYjDycEmoCGxbf9y RhBbREBaYufd2awgK5gFRCTezWQCCQsLuEpc2byfDcRmEVCVmPtlMlicV8BBYs7jfSwQZyhI nFt9jh3E5hRwlOg/fgysXgio5sXOp8wTGPkXMDKsYpRNya3SzU3MzClOTdYtTk7My0st0jXV y80s0UtNKd3ECAoadhelHYw/DyodYhTgYFTi4d2xl9dfiDWxrLgy9xCjJAeTkijvdys+fyG+ pPyUyozE4oz4otKc1OJDjBIczEoivE41QOW8KYmVValF+TApaQ4WJXFeda13fkIC6Yklqdmp qQWpRTBZGQ4OJQneEmugoYJFqempFWmZOSUIaSYOTpDhPEDDM0BqeIsLEnOLM9Mh8qcYFaXE ed1BEgIgiYzSPLheWFS/YhQHekWYNx+kigeYEOC6XwENZgIavGUdD8jgkkSElFQD44x7kb/X u7ge/fDT8maolefzzIhSkaPCBm7c4Sr3Hisc1nVoZLzZYrZMY1npfPm255ZpfH+cfx2RNaxQ Ti95HPF05081NuYth556f44rDm13WqW1yzbkdp+I0ZTMXxdnp3SaMdx4eFtD2fXY0vdS4WX1 r6bM40m6EehVJ+DcZG1XM98gdesqJZbijERDLeai4kQA+iiai8UCAAA= 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: Thu, 12 Jan 2012 01:49:47 -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 this is done, the formatter structure can be safely gutted. --- notmuch-client.h | 6 ++++++ notmuch-reply.c | 2 +- notmuch-show.c | 22 ++++++++++++++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index 8832242..52448ef 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -54,8 +54,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 000f6da..33c4ee8 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 0200b9c..45c3569 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", @@ -85,7 +85,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\": [", @@ -106,7 +106,7 @@ format_message_mbox (const void *ctx, unused (int indent)); static const notmuch_show_format_t format_mbox = { - "", + "", NULL, "", format_message_mbox, "", NULL, NULL, "", "", @@ -125,7 +125,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", "", @@ -744,6 +744,20 @@ 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) + return; + part = mime_node_seek_dfs (root, params->part < 0 ? 0 : params->part); + if (part) + format->part (local, part, indent, params); + talloc_free (local); + return; + } + if (params->part <= 0) { fputs (format->message_start, stdout); if (format->message) -- 1.7.7.3