]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-show.c
show: Move format_part_content_raw with the other new-style formats
[notmuch] / notmuch-show.c
index f13e1875d074681934d238b9b6f0a3c38e3ecc9c..341634dec6aad846745c218c84d93e6c9fcf7994 100644 (file)
@@ -45,25 +45,15 @@ static const notmuch_show_format_t format_json = {
     .message_set_end = "]"
 };
 
-static void
-format_message_mbox (const void *ctx,
-                    notmuch_message_t *message,
-                    unused (int indent));
+static notmuch_status_t
+format_part_mbox (const void *ctx, mime_node_t *node,
+                 int indent, const notmuch_show_params_t *params);
 
 static const notmuch_show_format_t format_mbox = {
-    "", NULL,
-        "", format_message_mbox,
-            "", NULL, NULL, "",
-            "",
-                NULL,
-                NULL,
-                NULL,
-                NULL,
-                NULL,
-                "",
-            "",
-        "", "",
-    ""
+    .message_set_start = "",
+    .part = format_part_mbox,
+    .message_set_sep = "",
+    .message_set_end = ""
 };
 
 static void
@@ -486,33 +476,6 @@ format_part_sigstatus_json (mime_node_t *node)
 }
 #endif
 
-static void
-format_part_content_raw (GMimeObject *part)
-{
-    if (! GMIME_IS_PART (part))
-       return;
-
-    GMimeStream *stream_stdout;
-    GMimeStream *stream_filter = NULL;
-    GMimeDataWrapper *wrapper;
-
-    stream_stdout = g_mime_stream_file_new (stdout);
-    g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE);
-
-    stream_filter = g_mime_stream_filter_new (stream_stdout);
-
-    wrapper = g_mime_part_get_content_object (GMIME_PART (part));
-
-    if (wrapper && stream_filter)
-       g_mime_data_wrapper_write_to_stream (wrapper, stream_filter);
-
-    if (stream_filter)
-       g_object_unref (stream_filter);
-
-    if (stream_stdout)
-       g_object_unref(stream_stdout);
-}
-
 static notmuch_status_t
 format_part_text (const void *ctx, mime_node_t *node,
                  int indent, const notmuch_show_params_t *params)
@@ -719,11 +682,12 @@ format_part_json_entry (const void *ctx, mime_node_t *node, unused (int indent),
  *
  * http://qmail.org/qmail-manual-html/man5/mbox.html
  */
-static void
-format_message_mbox (const void *ctx,
-                    notmuch_message_t *message,
-                    unused (int indent))
+static notmuch_status_t
+format_part_mbox (const void *ctx, mime_node_t *node, unused (int indent),
+                 unused (const notmuch_show_params_t *params))
 {
+    notmuch_message_t *message = node->envelope_file;
+
     const char *filename;
     FILE *file;
     const char *from;
@@ -736,12 +700,15 @@ format_message_mbox (const void *ctx,
     size_t line_size;
     ssize_t line_len;
 
+    if (!message)
+       INTERNAL_ERROR ("format_part_mbox requires a root part");
+
     filename = notmuch_message_get_filename (message);
     file = fopen (filename, "r");
     if (file == NULL) {
        fprintf (stderr, "Failed to open %s: %s\n",
                 filename, strerror (errno));
-       return;
+       return NOTMUCH_STATUS_FILE_ERROR;
     }
 
     from = notmuch_message_get_header (message, "from");
@@ -762,6 +729,35 @@ format_message_mbox (const void *ctx,
     printf ("\n");
 
     fclose (file);
+
+    return NOTMUCH_STATUS_SUCCESS;
+}
+
+static void
+format_part_content_raw (GMimeObject *part)
+{
+    if (! GMIME_IS_PART (part))
+       return;
+
+    GMimeStream *stream_stdout;
+    GMimeStream *stream_filter = NULL;
+    GMimeDataWrapper *wrapper;
+
+    stream_stdout = g_mime_stream_file_new (stdout);
+    g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE);
+
+    stream_filter = g_mime_stream_filter_new (stream_stdout);
+
+    wrapper = g_mime_part_get_content_object (GMIME_PART (part));
+
+    if (wrapper && stream_filter)
+       g_mime_data_wrapper_write_to_stream (wrapper, stream_filter);
+
+    if (stream_filter)
+       g_object_unref (stream_filter);
+
+    if (stream_stdout)
+       g_object_unref(stream_stdout);
 }
 
 static notmuch_status_t