- 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;
+ notmuch_message_t *message = node->envelope_file;
+
+ const char *filename;
+ gzFile file;
+ const char *from;
+
+ time_t date;
+ struct tm date_gmtime;
+ char date_asctime[26];
+
+ char *line = NULL;
+ ssize_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 = gzopen (filename, "r");
+ if (file == NULL) {
+ fprintf (stderr, "Failed to open %s: %s\n",
+ filename, strerror (errno));
+ return NOTMUCH_STATUS_FILE_ERROR;
+ }
+
+ from = notmuch_message_get_header (message, "from");
+ from = _extract_email_address (ctx, from);
+
+ date = notmuch_message_get_date (message);
+ gmtime_r (&date, &date_gmtime);
+ asctime_r (&date_gmtime, date_asctime);
+
+ printf ("From %s %s", from, date_asctime);
+
+ while ((line_len = gz_getline (message, &line, &line_size, file)) != UTIL_EOF ) {
+ if (_is_from_line (line))
+ putchar ('>');
+ printf ("%s", line);
+ }
+
+ printf ("\n");
+
+ gzclose (file);
+
+ return NOTMUCH_STATUS_SUCCESS;
+}
+
+static notmuch_status_t
+format_part_raw (unused (const void *ctx), unused (sprinter_t *sp),
+ mime_node_t *node, unused (int indent),
+ const notmuch_show_params_t *params)
+{
+ if (node->envelope_file) {
+ /* Special case the entire message to avoid MIME parsing. */
+ const char *filename;
+ GMimeStream *stream = NULL;
+ ssize_t ssize;
+ char buf[4096];
+ notmuch_status_t ret = NOTMUCH_STATUS_FILE_ERROR;
+
+ filename = _get_filename (node->envelope_file, params->duplicate);
+ if (filename == NULL) {
+ fprintf (stderr, "Error: Cannot get message filename.\n");
+ goto DONE;
+ }
+
+ stream = g_mime_stream_gzfile_open (filename);
+ if (stream == NULL) {
+ fprintf (stderr, "Error: Cannot open file %s: %s\n", filename, strerror (errno));
+ goto DONE;
+ }
+
+ while (! g_mime_stream_eos (stream)) {
+ ssize = g_mime_stream_read (stream, buf, sizeof (buf));
+ if (ssize < 0) {
+ fprintf (stderr, "Error: Read failed from %s\n", filename);
+ goto DONE;
+ }
+
+ if (ssize > 0 && fwrite (buf, ssize, 1, stdout) != 1) {
+ fprintf (stderr, "Error: Write %zd chars to stdout failed\n", ssize);
+ goto DONE;
+ }
+ }
+
+ ret = NOTMUCH_STATUS_SUCCESS;
+
+ /* XXX This DONE is just for the special case of a node in a single file */
+ DONE:
+ if (stream)
+ g_object_unref (stream);
+
+ return ret;