From: Austin Clements <amdragon@MIT.EDU>
To: notmuch@notmuchmail.org
Subject: [PATCH v2 3/3] show: Introduce mime_node formatter callback
Date: Sun, 22 Jan 2012 21:31:13 -0500 [thread overview]
Message-ID: <1327285873-4713-4-git-send-email-amdragon@mit.edu> (raw)
In-Reply-To: <1327285873-4713-1-git-send-email-amdragon@mit.edu>
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
next prev parent reply other threads:[~2012-01-23 2:31 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-18 20:28 [PATCH 0/3] Second step of 'show' rewrite Austin Clements
2012-01-18 20:28 ` [PATCH 1/3] mime node: Record depth-first part numbers Austin Clements
2012-01-18 22:25 ` Jani Nikula
2012-01-19 2:12 ` Austin Clements
2012-01-23 1:02 ` Austin Clements
2012-01-18 20:28 ` [PATCH 2/3] show: Use consistent header ordering in the text format Austin Clements
2012-01-20 13:45 ` Tomi Ollila
2012-01-18 20:28 ` [PATCH 3/3] show: Introduce mime_node formatter callback Austin Clements
2012-01-18 22:33 ` Jani Nikula
2012-01-19 2:23 ` Austin Clements
2012-01-18 20:35 ` [PATCH 0/3] Second step of 'show' rewrite Dmitry Kurochkin
2012-01-18 20:45 ` Austin Clements
2012-01-22 22:44 ` Jameson Graef Rollins
2012-01-23 2:31 ` [PATCH v2 " Austin Clements
2012-01-23 2:31 ` [PATCH v2 1/3] mime node: Record depth-first part numbers Austin Clements
2012-01-23 18:07 ` Jani Nikula
2012-01-23 21:36 ` Tomi Ollila
2012-01-23 22:19 ` Dmitry Kurochkin
2012-01-23 23:15 ` Austin Clements
2012-01-23 2:31 ` [PATCH v2 2/3] show: Use consistent header ordering in the text format Austin Clements
2012-01-23 2:31 ` Austin Clements [this message]
2012-01-23 21:00 ` [PATCH v2 3/3] show: Introduce mime_node formatter callback Tomi Ollila
2012-01-23 22:37 ` Dmitry Kurochkin
2012-01-23 23:23 ` Austin Clements
2012-01-23 20:28 ` [PATCH v3 0/2] Second step of 'show' rewrite Austin Clements
2012-01-23 20:29 ` [PATCH v3 1/2] mime node: Record depth-first part numbers Austin Clements
2012-01-23 20:29 ` [PATCH v3 2/2] show: Introduce mime_node formatter callback Austin Clements
2012-01-23 23:26 ` [PATCH v4 0/3] Second step of 'show' rewrite Austin Clements
2012-01-23 23:26 ` [PATCH v4 1/3] mime node: Record depth-first part numbers Austin Clements
2012-01-23 23:26 ` [PATCH v4 2/3] show: Use consistent header ordering in the text format Austin Clements
2012-01-23 23:26 ` [PATCH v4 3/3] show: Introduce mime_node formatter callback Austin Clements
2012-01-23 23:33 ` [PATCH v5 0/2] Second step of 'show' rewrite Austin Clements
2012-01-23 23:33 ` [PATCH v5 1/2] mime node: Record depth-first part numbers Austin Clements
2012-01-23 23:36 ` Dmitry Kurochkin
2012-01-24 8:57 ` Tomi Ollila
2012-01-23 23:33 ` [PATCH v5 2/2] show: Introduce mime_node formatter callback Austin Clements
2012-01-23 23:36 ` Dmitry Kurochkin
2012-01-24 8:58 ` Tomi Ollila
2012-01-24 18:26 ` Jani Nikula
2012-01-25 11:33 ` [PATCH v5 0/2] Second step of 'show' rewrite David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1327285873-4713-4-git-send-email-amdragon@mit.edu \
--to=amdragon@mit.edu \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).