]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-show.c
Integrate reply_part_content function into reply_part function.
[notmuch] / notmuch-show.c
index e128be541b9f36b1144192e1f094f8db3d85b50b..65c780e7b8681716c85a1b11e990ffbfd40d6dfb 100644 (file)
@@ -416,7 +416,8 @@ format_part_text (GMimeObject *part, int *part_count)
        show_part_content (part, stream_stdout);
        g_object_unref(stream_stdout);
     }
-    else if (g_mime_content_type_is_type (content_type, "multipart", "*"))
+    else if (g_mime_content_type_is_type (content_type, "multipart", "*") ||
+            g_mime_content_type_is_type (content_type, "message", "rfc822"))
     {
        /* Do nothing for multipart since its content will be printed
         * when recursing. */
@@ -483,7 +484,8 @@ format_part_json (GMimeObject *part, int *part_count)
 
        printf (", \"content\": %s", json_quote_chararray (ctx, (char *) part_content->data, part_content->len));
     }
-    else if (g_mime_content_type_is_type (content_type, "multipart", "*"))
+    else if (g_mime_content_type_is_type (content_type, "multipart", "*") ||
+            g_mime_content_type_is_type (content_type, "message", "rfc822"))
     {
        printf (", \"content\": [");
     }
@@ -500,7 +502,8 @@ format_part_end_json (GMimeObject *part)
 
     content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
 
-    if (g_mime_content_type_is_type (content_type, "multipart", "*"))
+    if (g_mime_content_type_is_type (content_type, "multipart", "*") ||
+       g_mime_content_type_is_type (content_type, "message", "rfc822"))
        printf ("]");
 
     printf ("}");
@@ -709,6 +712,8 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
     char *opt;
     const notmuch_show_format_t *format = &format_text;
     notmuch_show_params_t params;
+    int mbox = 0;
+    int format_specified = 0;
     int i;
 
     params.entire_thread = 0;
@@ -729,6 +734,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
                params.entire_thread = 1;
            } else if (strcmp (opt, "mbox") == 0) {
                format = &format_mbox;
+               mbox = 1;
            } else if (strcmp (opt, "raw") == 0) {
                format = &format_raw;
                params.raw = 1;
@@ -736,6 +742,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
                fprintf (stderr, "Invalid value for --format: %s\n", opt);
                return 1;
            }
+           format_specified = 1;
        } else if (STRNCMP_LITERAL (argv[i], "--part=") == 0) {
            params.part = atoi(argv[i] + sizeof ("--part=") - 1);
        } else if (STRNCMP_LITERAL (argv[i], "--entire-thread") == 0) {
@@ -759,6 +766,11 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
        return 1;
     }
 
+    if (mbox && params.part > 0) {
+       fprintf (stderr, "Error: specifying parts is incompatible with mbox output format.\n");
+       return 1;
+    }
+
     if (*query_string == '\0') {
        fprintf (stderr, "Error: notmuch show requires at least one search term.\n");
        return 1;
@@ -775,6 +787,10 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
        return 1;
     }
 
+    /* if part was requested and format was not specified, use format=raw */
+    if (params.part >= 0 && !format_specified)
+       format = &format_raw;
+
     /* If --format=raw specified without specifying part, we can only
      * output single message, so set part=0 */
     if (params.raw && params.part < 0)