From 1c193eb25177edc47b2badcaff2d449f26bcab54 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 3 Aug 2012 21:14:52 +2000 Subject: [PATCH] [PATCH v3 06/13] show: Feed the sprinter down to part formatters --- 12/b83bb0010903d120f748b594a57bb0c22268f1 | 342 ++++++++++++++++++++++ 1 file changed, 342 insertions(+) create mode 100644 12/b83bb0010903d120f748b594a57bb0c22268f1 diff --git a/12/b83bb0010903d120f748b594a57bb0c22268f1 b/12/b83bb0010903d120f748b594a57bb0c22268f1 new file mode 100644 index 000000000..30cec3c6a --- /dev/null +++ b/12/b83bb0010903d120f748b594a57bb0c22268f1 @@ -0,0 +1,342 @@ +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 D8668429E26 + for ; Thu, 2 Aug 2012 18:15:15 -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 I6-cbFb19Ian for ; + Thu, 2 Aug 2012 18:15:12 -0700 (PDT) +Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU + [18.7.68.36]) + by olra.theworths.org (Postfix) with ESMTP id BA768429E31 + for ; Thu, 2 Aug 2012 18:15:08 -0700 (PDT) +X-AuditID: 12074424-b7fa06d0000008c2-c5-501b261ba9af +Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) + by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP + id 75.5C.02242.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-3.mit.edu (8.13.8/8.9.2) with ESMTP id q731F6UA008952; + 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 q731F4hX002788 + (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-0003wM-8P; Thu, 02 Aug 2012 21:15:04 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v3 06/13] show: Feed the sprinter down to part formatters +Date: Thu, 2 Aug 2012 21:14:52 -0400 +Message-Id: <1343956499-14543-7-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+NgFjrOIsWRmVeSWpSXmKPExsUixCmqrSutJh1gMHmPusXquTwW12/OZLZ4 + s3IeqwOzx85Zd9k9Dn9dyOLxbNUt5gDmKC6blNSczLLUIn27BK6M9v4V7AW9fhXfrx9mbWDc + btfFyMkhIWAi8ar1HROELSZx4d56ti5GLg4hgX2MEmseLGSCcNYzSvSdvMYO4Txkkli6YDlU + 2VxGiZtnToH1swloSGzbv5wRxBYRkJbYeXc2K4jNLBAnsWXKf7C4sICnRP/fFWA2i4CqxObX + 89lBbF4BB4nN2yawQNwhL/H0fh8biM0p4Cjx+u0rsHohoJrlbd2sExj5FzAyrGKUTcmt0s1N + zMwpTk3WLU5OzMtLLdI118vNLNFLTSndxAgKL3YXlR2MzYeUDjEKcDAq8fAaSUoHCLEmlhVX + 5h5ilORgUhLlZVYCCvEl5adUZiQWZ8QXleakFh9ilOBgVhLhrVoiFSDEm5JYWZValA+TkuZg + URLnvZ5y019IID2xJDU7NbUgtQgmK8PBoSTBG6wKNFSwKDU9tSItM6cEIc3EwQkynAdouD1I + DW9xQWJucWY6RP4Uo6KUOG86SEIAJJFRmgfXC4v/V4ziQK8I83qBVPEAUwdc9yugwUxAg+3M + QK4uLklESEk1ME602S9atuOv/wsJxvPKBwSu6VdFcq1kfHt3qZFZx8N7mZ7pcTGH2S11WxKM + 5WbzJ9/IdQ4sntm812MaE5fu3El/dk2V2BGluqWYk+Ge6sW3+7QUvk56zMS1JnqJ74KWtCe3 + Fj7IETGf6uJ779Tvj1ZPjf2/NDy84xiudUFdb1VeGUvnudf+OUosxRmJhlrMRcWJAF3Lltja AgAA +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:16 -0000 + +There are several levels of function calls between where we create the +sprinter and the call to the part formatter in show_message. This +feeds the sprinter through all of them and into the part formatters. +--- + notmuch-client.h | 6 ++++-- + notmuch-reply.c | 2 +- + notmuch-show.c | 50 +++++++++++++++++++++++++++++--------------------- + 3 files changed, 34 insertions(+), 24 deletions(-) + +diff --git a/notmuch-client.h b/notmuch-client.h +index bbc0a11..112574c 100644 +--- a/notmuch-client.h ++++ b/notmuch-client.h +@@ -66,12 +66,13 @@ typedef GMimeCipherContext notmuch_crypto_context_t; + #define STRINGIFY_(s) #s + + typedef struct mime_node mime_node_t; ++struct sprinter; + struct notmuch_show_params; + + typedef struct notmuch_show_format { + struct sprinter *(*new_sprinter) (const void *ctx, FILE *stream); + const char *message_set_start; +- notmuch_status_t (*part) (const void *ctx, ++ notmuch_status_t (*part) (const void *ctx, struct sprinter *sprinter, + struct mime_node *node, int indent, + const struct notmuch_show_params *params); + const char *message_set_sep; +@@ -178,7 +179,8 @@ notmuch_status_t + show_one_part (const char *filename, int part); + + void +-format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first, notmuch_bool_t output_body); ++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); +diff --git a/notmuch-reply.c b/notmuch-reply.c +index e42ba79..07d4452 100644 +--- a/notmuch-reply.c ++++ b/notmuch-reply.c +@@ -624,7 +624,7 @@ notmuch_reply_format_json(void *ctx, + /* Start the original */ + printf (", \"original\": "); + +- format_part_json (ctx, node, TRUE, TRUE); ++ format_part_json (ctx, sp, node, TRUE, TRUE); + + /* End */ + printf ("}\n"); +diff --git a/notmuch-show.c b/notmuch-show.c +index d04943f..b258f65 100644 +--- a/notmuch-show.c ++++ b/notmuch-show.c +@@ -23,7 +23,7 @@ + #include "sprinter.h" + + static notmuch_status_t +-format_part_text (const void *ctx, mime_node_t *node, ++format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node, + int indent, const notmuch_show_params_t *params); + + static const notmuch_show_format_t format_text = { +@@ -32,7 +32,7 @@ static const notmuch_show_format_t format_text = { + }; + + static notmuch_status_t +-format_part_json_entry (const void *ctx, mime_node_t *node, ++format_part_json_entry (const void *ctx, sprinter_t *sp, mime_node_t *node, + int indent, const notmuch_show_params_t *params); + + static const notmuch_show_format_t format_json = { +@@ -45,7 +45,7 @@ static const notmuch_show_format_t format_json = { + }; + + static notmuch_status_t +-format_part_mbox (const void *ctx, mime_node_t *node, ++format_part_mbox (const void *ctx, sprinter_t *sp, mime_node_t *node, + int indent, const notmuch_show_params_t *params); + + static const notmuch_show_format_t format_mbox = { +@@ -54,7 +54,7 @@ static const notmuch_show_format_t format_mbox = { + }; + + static notmuch_status_t +-format_part_raw (unused (const void *ctx), mime_node_t *node, ++format_part_raw (unused (const void *ctx), sprinter_t *sp, mime_node_t *node, + unused (int indent), + unused (const notmuch_show_params_t *params)); + +@@ -471,7 +471,7 @@ format_part_sigstatus_json (mime_node_t *node) + #endif + + static notmuch_status_t +-format_part_text (const void *ctx, mime_node_t *node, ++format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node, + int indent, const notmuch_show_params_t *params) + { + /* The disposition and content-type metadata are associated with +@@ -553,7 +553,7 @@ format_part_text (const void *ctx, mime_node_t *node, + } + + for (i = 0; i < node->nchildren; i++) +- format_part_text (ctx, mime_node_child (node, i), indent, params); ++ format_part_text (ctx, sp, mime_node_child (node, i), indent, params); + + if (GMIME_IS_MESSAGE (node->part)) + printf ("\fbody}\n"); +@@ -564,7 +564,8 @@ format_part_text (const void *ctx, mime_node_t *node, + } + + void +-format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first, notmuch_bool_t output_body) ++format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node, ++ notmuch_bool_t first, notmuch_bool_t output_body) + { + /* Any changes to the JSON format should be reflected in the file + * devel/schemata. */ +@@ -578,7 +579,7 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first, notm + + if (output_body) { + printf (", \"body\": ["); +- format_part_json (ctx, mime_node_child (node, 0), first, TRUE); ++ format_part_json (ctx, sp, mime_node_child (node, 0), first, TRUE); + printf ("]"); + } + printf ("}"); +@@ -659,16 +660,17 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first, notm + talloc_free (local); + + for (i = 0; i < node->nchildren; i++) +- format_part_json (ctx, mime_node_child (node, i), i == 0, TRUE); ++ format_part_json (ctx, sp, mime_node_child (node, i), i == 0, TRUE); + + printf ("%s}", terminator); + } + + static notmuch_status_t +-format_part_json_entry (const void *ctx, mime_node_t *node, unused (int indent), ++format_part_json_entry (const void *ctx, sprinter_t *sp, ++ mime_node_t *node, unused (int indent), + const notmuch_show_params_t *params) + { +- format_part_json (ctx, node, TRUE, params->output_body); ++ format_part_json (ctx, sp, node, TRUE, params->output_body); + + return NOTMUCH_STATUS_SUCCESS; + } +@@ -679,7 +681,8 @@ format_part_json_entry (const void *ctx, mime_node_t *node, unused (int indent), + * http://qmail.org/qmail-manual-html/man5/mbox.html + */ + static notmuch_status_t +-format_part_mbox (const void *ctx, mime_node_t *node, unused (int indent), ++format_part_mbox (const void *ctx, unused (sprinter_t *sp), mime_node_t *node, ++ unused (int indent), + unused (const notmuch_show_params_t *params)) + { + notmuch_message_t *message = node->envelope_file; +@@ -730,8 +733,8 @@ format_part_mbox (const void *ctx, mime_node_t *node, unused (int indent), + } + + static notmuch_status_t +-format_part_raw (unused (const void *ctx), mime_node_t *node, +- unused (int indent), ++format_part_raw (unused (const void *ctx), unused (sprinter_t *sp), ++ mime_node_t *node, unused (int indent), + unused (const notmuch_show_params_t *params)) + { + if (node->envelope_file) { +@@ -819,6 +822,7 @@ show_null_message (const notmuch_show_format_t *format) + static notmuch_status_t + show_message (void *ctx, + const notmuch_show_format_t *format, ++ sprinter_t *sp, + notmuch_message_t *message, + int indent, + notmuch_show_params_t *params) +@@ -832,7 +836,7 @@ show_message (void *ctx, + goto DONE; + part = mime_node_seek_dfs (root, (params->part < 0 ? 0 : params->part)); + if (part) +- status = format->part (local, part, indent, params); ++ status = format->part (local, sp, part, indent, params); + DONE: + talloc_free (local); + return status; +@@ -841,6 +845,7 @@ show_message (void *ctx, + static notmuch_status_t + show_messages (void *ctx, + const notmuch_show_format_t *format, ++ sprinter_t *sp, + notmuch_messages_t *messages, + int indent, + notmuch_show_params_t *params) +@@ -874,7 +879,7 @@ show_messages (void *ctx, + next_indent = indent; + + if ((match && (!excluded || !params->omit_excluded)) || params->entire_thread) { +- status = show_message (ctx, format, message, indent, params); ++ status = show_message (ctx, format, sp, message, indent, params); + if (status && !res) + res = status; + next_indent = indent + 1; +@@ -886,7 +891,7 @@ show_messages (void *ctx, + fputs (format->message_set_sep, stdout); + + status = show_messages (ctx, +- format, ++ format, sp, + notmuch_message_get_replies (message), + next_indent, + params); +@@ -910,6 +915,7 @@ static int + do_show_single (void *ctx, + notmuch_query_t *query, + const notmuch_show_format_t *format, ++ sprinter_t *sp, + notmuch_show_params_t *params) + { + notmuch_messages_t *messages; +@@ -930,7 +936,8 @@ do_show_single (void *ctx, + + notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH, 1); + +- return show_message (ctx, format, message, 0, params) != NOTMUCH_STATUS_SUCCESS; ++ return show_message (ctx, format, sp, message, 0, params) ++ != NOTMUCH_STATUS_SUCCESS; + } + + /* Formatted output of threads */ +@@ -938,6 +945,7 @@ static int + do_show (void *ctx, + notmuch_query_t *query, + const notmuch_show_format_t *format, ++ sprinter_t *sp, + notmuch_show_params_t *params) + { + notmuch_threads_t *threads; +@@ -965,7 +973,7 @@ do_show (void *ctx, + fputs (format->message_set_sep, stdout); + first_toplevel = 0; + +- status = show_messages (ctx, format, messages, 0, params); ++ status = show_messages (ctx, format, sp, messages, 0, params); + if (status && !res) + res = status; + +@@ -1141,7 +1149,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[])) + + /* If a single message is requested we do not use search_excludes. */ + if (params.part >= 0) +- ret = do_show_single (ctx, query, format, ¶ms); ++ ret = do_show_single (ctx, query, format, sprinter, ¶ms); + else { + /* We always apply set the exclude flag. The + * exclude=true|false option controls whether or not we return +@@ -1160,7 +1168,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[])) + params.omit_excluded = FALSE; + } + +- ret = do_show (ctx, query, format, ¶ms); ++ ret = do_show (ctx, query, format, sprinter, ¶ms); + } + + notmuch_crypto_cleanup (¶ms.crypto); +-- +1.7.10 + -- 2.26.2