[notmuch] [PATCH] Produce valid JSON output even if mail body is empty

Michal Sojka sojkam1 at fel.cvut.cz
Sun Mar 14 11:19:11 PDT 2010


Mails with empty body produced the following output:
  "body": [{"id": 1, "content-type": "text/plain", "content": (null)}]
The (null) is not valid JSON syntax.

This patch changes the output to:
  "body": [{"id": 1, "content-type": "text/plain", "content": ""}]

Signed-off-by: Michal Sojka <sojkam1 at fel.cvut.cz>
---
 notmuch-show.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index ff1fecb..cc2fb6a 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -323,7 +323,7 @@ format_part_json (GMimeObject *part, int *part_count)
 	show_part_content (part, stream_memory);
 	part_content = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (stream_memory));
 
-	printf (", \"content\": %s", json_quote_str (ctx, (char *) part_content->data));
+	printf (", \"content\": %s", json_quote_str (ctx, part_content->data ? (char *)part_content->data : ""));
     }
 
     fputs ("}", stdout);
-- 
1.7.0



More information about the notmuch mailing list