--- /dev/null
+Return-Path: <markwalters1009@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 14C42431FBF\r
+ for <notmuch@notmuchmail.org>; Sat, 7 Jul 2012 08:13:22 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+ RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id FCPujwf8XFS6 for <notmuch@notmuchmail.org>;\r
+ Sat, 7 Jul 2012 08:13:19 -0700 (PDT)\r
+Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com\r
+ [209.85.212.173]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 6BB42431FC7\r
+ for <notmuch@notmuchmail.org>; Sat, 7 Jul 2012 08:13:16 -0700 (PDT)\r
+Received: by wibhm6 with SMTP id hm6so1274327wib.2\r
+ for <notmuch@notmuchmail.org>; Sat, 07 Jul 2012 08:13:13 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+ bh=UcaJpKhKMa4xVgDc/o+ti+Bw3tHVMSXEtHTiCQAf1Gw=;\r
+ b=zjtTzxTBykr33/U5ghILLwISbwGZyccZ1gPmknLk32BwnX5INC4ON/ZUyBYI/0qQyF\r
+ mqVrKbcvsJe0xQdlna83klcBPjl4njnxRwNGgx7V+DTla2/P6XKRUBkwh2OtIjQNrF79\r
+ p7c0nn3mOd58XQM5sKdeS7LvSb/NGLY5AgyIf+Lo5eIxAp2YySapEm5KtbeTtoxkAfRm\r
+ OnfTFnTJqyzYS7a3bw6Rk01R6qI/+yRmpLI54jvJzF6IxoKDdFvBnhmhkuAC3qyF5iEY\r
+ sCcMJX/lwo0h8i6bcfMCPpioUo5tjWs/A3/Vd1qaK5+mqau3ZQpPi4mE6KfAFfFYrTMd\r
+ fJYA==\r
+Received: by 10.180.78.35 with SMTP id y3mr15901560wiw.16.1341673993770;\r
+ Sat, 07 Jul 2012 08:13:13 -0700 (PDT)\r
+Received: from localhost (94-192-233-223.zone6.bethere.co.uk.\r
+ [94.192.233.223]) by mx.google.com with ESMTPS id\r
+ el6sm12172162wib.8.2012.07.07.08.13.11 (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Sat, 07 Jul 2012 08:13:12 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/3] cli: show allow the caller to specify the headers output.\r
+Date: Sat, 7 Jul 2012 16:12:57 +0100\r
+Message-Id: <1341673978-6094-3-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1341673978-6094-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1341673978-6094-1-git-send-email-markwalters1009@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 07 Jul 2012 15:13:22 -0000\r
+\r
+This uses the new parsing functionality to allow the caller of notmuch\r
+show to specify which headers they want. Callers of format_part_json\r
+should pass a bitfield specifiying the headers they want.\r
+\r
+Since the functionality includes that contained in the previous\r
+"reply" boolean passed notmuch-reply.c is converted to use this new\r
+style.\r
+---\r
+ notmuch-client.h | 24 +++++++++++++-\r
+ notmuch-reply.c | 12 ++++++-\r
+ notmuch-show.c | 90 ++++++++++++++++++++++++++++++++++++-----------------\r
+ 3 files changed, 93 insertions(+), 33 deletions(-)\r
+\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index 0c17b79..c241a7d 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -68,6 +68,24 @@ typedef GMimeCipherContext notmuch_crypto_context_t;\r
+ typedef struct mime_node mime_node_t;\r
+ struct notmuch_show_params;\r
+ \r
++\r
++typedef enum {\r
++ NOTMUCH_SHOW_OUTPUT_HDR_DATE = 0x1,\r
++ NOTMUCH_SHOW_OUTPUT_HDR_SUBJECT = 0x2,\r
++ NOTMUCH_SHOW_OUTPUT_HDR_FROM = 0x4,\r
++ NOTMUCH_SHOW_OUTPUT_HDR_TO = 0x8,\r
++ NOTMUCH_SHOW_OUTPUT_HDR_CC = 0x10,\r
++ NOTMUCH_SHOW_OUTPUT_HDR_REPLY_TO = 0x20,\r
++ NOTMUCH_SHOW_OUTPUT_HDR_IN_REPLY_TO = 0x40,\r
++ NOTMUCH_SHOW_OUTPUT_HDR_REFERENCES = 0x80,\r
++ NOTMUCH_SHOW_OUTPUT_DEFAULT =\r
++ NOTMUCH_SHOW_OUTPUT_HDR_SUBJECT |\r
++ NOTMUCH_SHOW_OUTPUT_HDR_FROM |\r
++ NOTMUCH_SHOW_OUTPUT_HDR_TO |\r
++ NOTMUCH_SHOW_OUTPUT_HDR_CC |\r
++ NOTMUCH_SHOW_OUTPUT_HDR_DATE\r
++} notmuch_show_output_t;\r
++\r
+ typedef struct notmuch_show_format {\r
+ const char *message_set_start;\r
+ notmuch_status_t (*part) (const void *ctx,\r
+@@ -90,6 +108,7 @@ typedef struct notmuch_show_params {\r
+ notmuch_bool_t raw;\r
+ int part;\r
+ notmuch_crypto_t crypto;\r
++ notmuch_show_output_t output;\r
+ } notmuch_show_params_t;\r
+ \r
+ /* There's no point in continuing when we've detected that we've done\r
+@@ -176,10 +195,11 @@ notmuch_status_t\r
+ show_one_part (const char *filename, int part);\r
+ \r
+ void\r
+-format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first);\r
++format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first,\r
++ notmuch_show_output_t output);\r
+ \r
+ void\r
+-format_headers_json (const void *ctx, GMimeMessage *message, notmuch_bool_t reply);\r
++format_headers_json (const void *ctx, GMimeMessage *message, notmuch_show_output_t output);\r
+ \r
+ typedef enum {\r
+ NOTMUCH_SHOW_TEXT_PART_REPLY = 1 << 0,\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index 3a038ed..f4bf70d 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -611,16 +611,24 @@ notmuch_reply_format_json(void *ctx,\r
+ if (!reply)\r
+ return 1;\r
+ \r
++ notmuch_show_output_t NOTMUCH_REPLY_OUTPUT =\r
++ NOTMUCH_SHOW_OUTPUT_HDR_SUBJECT |\r
++ NOTMUCH_SHOW_OUTPUT_HDR_FROM |\r
++ NOTMUCH_SHOW_OUTPUT_HDR_TO |\r
++ NOTMUCH_SHOW_OUTPUT_HDR_CC |\r
++ NOTMUCH_SHOW_OUTPUT_HDR_IN_REPLY_TO |\r
++ NOTMUCH_SHOW_OUTPUT_HDR_REFERENCES;\r
++\r
+ /* The headers of the reply message we've created */\r
+ printf ("{\"reply-headers\": ");\r
+- format_headers_json (ctx, reply, TRUE);\r
++ format_headers_json (ctx, reply, NOTMUCH_REPLY_OUTPUT);\r
+ g_object_unref (G_OBJECT (reply));\r
+ reply = NULL;\r
+ \r
+ /* Start the original */\r
+ printf (", \"original\": ");\r
+ \r
+- format_part_json (ctx, node, TRUE);\r
++ format_part_json (ctx, node, TRUE, NOTMUCH_SHOW_OUTPUT_DEFAULT);\r
+ \r
+ /* End */\r
+ printf ("}\n");\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index 8f3c60e..242e8e0 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -194,44 +194,58 @@ _is_from_line (const char *line)\r
+ }\r
+ \r
+ void\r
+-format_headers_json (const void *ctx, GMimeMessage *message, notmuch_bool_t reply)\r
++format_headers_json (const void *ctx, GMimeMessage *message, notmuch_show_output_t output)\r
+ {\r
+ void *local = talloc_new (ctx);\r
+ InternetAddressList *recipients;\r
+ const char *recipients_string;\r
++ const char *reply_to_string;\r
+ \r
+- printf ("{%s: %s",\r
+- json_quote_str (local, "Subject"),\r
+- json_quote_str (local, g_mime_message_get_subject (message)));\r
+- printf (", %s: %s",\r
+- json_quote_str (local, "From"),\r
+- json_quote_str (local, g_mime_message_get_sender (message)));\r
+- recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);\r
+- recipients_string = internet_address_list_to_string (recipients, 0);\r
+- if (recipients_string)\r
++ if (output & NOTMUCH_SHOW_OUTPUT_HDR_SUBJECT)\r
++ printf ("{%s: %s",\r
++ json_quote_str (local, "Subject"),\r
++ json_quote_str (local, g_mime_message_get_subject (message)));\r
++ if (output & NOTMUCH_SHOW_OUTPUT_HDR_FROM)\r
+ printf (", %s: %s",\r
+- json_quote_str (local, "To"),\r
+- json_quote_str (local, recipients_string));\r
+- recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);\r
+- recipients_string = internet_address_list_to_string (recipients, 0);\r
+- if (recipients_string)\r
+- printf (", %s: %s",\r
+- json_quote_str (local, "Cc"),\r
+- json_quote_str (local, recipients_string));\r
+-\r
+- if (reply) {\r
++ json_quote_str (local, "From"),\r
++ json_quote_str (local, g_mime_message_get_sender (message)));\r
++ if (output & NOTMUCH_SHOW_OUTPUT_HDR_TO) {\r
++ recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);\r
++ recipients_string = internet_address_list_to_string (recipients, 0);\r
++ if (recipients_string)\r
++ printf (", %s: %s",\r
++ json_quote_str (local, "To"),\r
++ json_quote_str (local, recipients_string));\r
++ }\r
++ if (output & NOTMUCH_SHOW_OUTPUT_HDR_CC) {\r
++ recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);\r
++ recipients_string = internet_address_list_to_string (recipients, 0);\r
++ if (recipients_string)\r
++ printf (", %s: %s",\r
++ json_quote_str (local, "Cc"),\r
++ json_quote_str (local, recipients_string));\r
++ }\r
++ if (output & NOTMUCH_SHOW_OUTPUT_HDR_REPLY_TO) {\r
++ reply_to_string = g_mime_message_get_reply_to (message);\r
++ if (reply_to_string)\r
++ printf (", %s: %s",\r
++ json_quote_str (local, "Reply-To"),\r
++ json_quote_str (local, reply_to_string));\r
++ }\r
++ if (output & NOTMUCH_SHOW_OUTPUT_HDR_IN_REPLY_TO)\r
+ printf (", %s: %s",\r
+ json_quote_str (local, "In-reply-to"),\r
+ json_quote_str (local, g_mime_object_get_header (GMIME_OBJECT (message), "In-reply-to")));\r
+ \r
++ if (output & NOTMUCH_SHOW_OUTPUT_HDR_REFERENCES)\r
+ printf (", %s: %s",\r
+ json_quote_str (local, "References"),\r
+ json_quote_str (local, g_mime_object_get_header (GMIME_OBJECT (message), "References")));\r
+- } else {\r
++\r
++ if (output & NOTMUCH_SHOW_OUTPUT_HDR_DATE)\r
+ printf (", %s: %s",\r
+ json_quote_str (local, "Date"),\r
+ json_quote_str (local, g_mime_message_get_date_as_string (message)));\r
+- }\r
+ \r
+ printf ("}");\r
+ \r
+@@ -559,7 +573,7 @@ format_part_text (const void *ctx, mime_node_t *node,\r
+ }\r
+ \r
+ void\r
+-format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)\r
++format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first, notmuch_show_output_t output)\r
+ {\r
+ /* Any changes to the JSON format should be reflected in the file\r
+ * devel/schemata. */\r
+@@ -569,10 +583,10 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)\r
+ format_message_json (ctx, node->envelope_file);\r
+ \r
+ printf ("\"headers\": ");\r
+- format_headers_json (ctx, GMIME_MESSAGE (node->part), FALSE);\r
++ format_headers_json (ctx, GMIME_MESSAGE (node->part), output);\r
+ \r
+ printf (", \"body\": [");\r
+- format_part_json (ctx, mime_node_child (node, 0), first);\r
++ format_part_json (ctx, mime_node_child (node, 0), first, output);\r
+ \r
+ printf ("]}");\r
+ return;\r
+@@ -643,7 +657,7 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)\r
+ } else if (GMIME_IS_MESSAGE (node->part)) {\r
+ printf (", \"content\": [{");\r
+ printf ("\"headers\": ");\r
+- format_headers_json (local, GMIME_MESSAGE (node->part), FALSE);\r
++ format_headers_json (local, GMIME_MESSAGE (node->part), output);\r
+ \r
+ printf (", \"body\": [");\r
+ terminator = "]}]";\r
+@@ -652,16 +666,16 @@ format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first)\r
+ talloc_free (local);\r
+ \r
+ for (i = 0; i < node->nchildren; i++)\r
+- format_part_json (ctx, mime_node_child (node, i), i == 0);\r
++ format_part_json (ctx, mime_node_child (node, i), i == 0, output);\r
+ \r
+ printf ("%s}", terminator);\r
+ }\r
+ \r
+ static notmuch_status_t\r
+ format_part_json_entry (const void *ctx, mime_node_t *node, unused (int indent),\r
+- unused (const notmuch_show_params_t *params))\r
++ const notmuch_show_params_t *params)\r
+ {\r
+- format_part_json (ctx, node, TRUE);\r
++ format_part_json (ctx, node, TRUE, params->output);\r
+ \r
+ return NOTMUCH_STATUS_SUCCESS;\r
+ }\r
+@@ -1020,6 +1034,17 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+ { "mbox", NOTMUCH_FORMAT_MBOX },\r
+ { "raw", NOTMUCH_FORMAT_RAW },\r
+ { 0, 0 } } },\r
++ { NOTMUCH_OPT_KEYWORD_LIST, ¶ms.output, "output", 'o',\r
++ (notmuch_keyword_t []){ { "default", NOTMUCH_SHOW_OUTPUT_DEFAULT },\r
++ { "date", NOTMUCH_SHOW_OUTPUT_HDR_DATE },\r
++ { "subject", NOTMUCH_SHOW_OUTPUT_HDR_SUBJECT },\r
++ { "from", NOTMUCH_SHOW_OUTPUT_HDR_FROM },\r
++ { "to", NOTMUCH_SHOW_OUTPUT_HDR_TO },\r
++ { "cc", NOTMUCH_SHOW_OUTPUT_HDR_CC },\r
++ { "reply-to", NOTMUCH_SHOW_OUTPUT_HDR_REPLY_TO },\r
++ { "in-reply-to", NOTMUCH_SHOW_OUTPUT_HDR_IN_REPLY_TO },\r
++ { "references", NOTMUCH_SHOW_OUTPUT_HDR_REFERENCES },\r
++ { 0, 0 } } },\r
+ { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',\r
+ (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },\r
+ { "false", EXCLUDE_FALSE },\r
+@@ -1053,6 +1078,13 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+ format_sel = NOTMUCH_FORMAT_TEXT;\r
+ }\r
+ \r
++ if (params.output) {\r
++ if (format_sel != NOTMUCH_FORMAT_JSON)\r
++ fprintf (stderr, "Error: specifying output is only implemented for json format.\n");\r
++ } else {\r
++ params.output = NOTMUCH_SHOW_OUTPUT_DEFAULT;\r
++ }\r
++\r
+ switch (format_sel) {\r
+ case NOTMUCH_FORMAT_JSON:\r
+ format = &format_json;\r
+-- \r
+1.7.9.1\r
+\r