]> git.notmuchmail.org Git - notmuch/commitdiff
show: Introduce mime_node formatter callback
authorAustin Clements <amdragon@MIT.EDU>
Mon, 23 Jan 2012 23:33:10 +0000 (18:33 -0500)
committerDavid Bremner <bremner@debian.org>
Wed, 25 Jan 2012 11:21:40 +0000 (07:21 -0400)
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
notmuch-reply.c
notmuch-show.c

index 70f2336214bfd53c5df421881ef7070609c877e5..e0eb594ad0394510ecdd20e0a04ee1119f247775 100644 (file)
 #define STRINGIFY(s) STRINGIFY_(s)
 #define STRINGIFY_(s) #s
 
 #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;
 typedef struct notmuch_show_format {
     const char *message_set_start;
+    void (*part) (const void *ctx,
+                 struct mime_node *node, int indent,
+                 const struct notmuch_show_params *params);
     const char *message_start;
     void (*message) (const void *ctx,
                     notmuch_message_t *message,
     const char *message_start;
     void (*message) (const void *ctx,
                     notmuch_message_t *message,
index bf6796019e71b3bbd295bf6c0bae555afdb9040e..f55b1d22bbe2f1d5ed1603dafc3b7d2615715fa9 100644 (file)
@@ -31,7 +31,7 @@ static void
 reply_part_content (GMimeObject *part);
 
 static const notmuch_show_format_t format_reply = {
 reply_part_content (GMimeObject *part);
 
 static const notmuch_show_format_t format_reply = {
-    "",
+    "", NULL,
        "", NULL,
            "", NULL, reply_headers_message_part, ">\n",
            "",
        "", NULL,
            "", NULL, reply_headers_message_part, ">\n",
            "",
index 682aa71888e7a816ea854b30edb02af146e5c422..dec799c7a0ed91801f951868b38b6b3544317ae7 100644 (file)
@@ -42,7 +42,7 @@ static void
 format_part_end_text (GMimeObject *part);
 
 static const notmuch_show_format_t format_text = {
 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",
        "\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 = {
 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\": [",
        "{", 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 = {
                     unused (int indent));
 
 static const notmuch_show_format_t format_mbox = {
-    "",
+    "", NULL,
         "", format_message_mbox,
             "", NULL, 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 = {
 format_part_content_raw (GMimeObject *part);
 
 static const notmuch_show_format_t format_raw = {
-    "",
+    "", NULL,
        "", NULL,
            "", NULL, format_headers_message_part_text, "\n",
             "",
        "", NULL,
            "", NULL, format_headers_message_part_text, "\n",
             "",
@@ -850,6 +850,19 @@ show_message (void *ctx,
              int indent,
              notmuch_show_params_t *params)
 {
              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 &&
+           (part = mime_node_seek_dfs (root, (params->part < 0 ?
+                                              0 : params->part))))
+           format->part (local, part, indent, params);
+       talloc_free (local);
+       return;
+    }
+
     if (params->part <= 0) {
        fputs (format->message_start, stdout);
        if (format->message)
     if (params->part <= 0) {
        fputs (format->message_start, stdout);
        if (format->message)