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

2010-03-14 Thread Michal Sojka
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 
---
 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



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

2010-03-14 Thread James Westby
On Sun, 14 Mar 2010 19:19:11 +0100, Michal Sojka  wrote:
> Mails with empty body produced the following output:
>   "body": [{"id": 1, "content-type": "text/plain", "content": (null)}]
> The (null) is not valid JSON syntax.

Is this just something that can happen with the body?

I've see (null) in the emacs interface when I've done something silly
such as opening a newer notmuch db with an old client.

Should all the attributes be guarded in a similar manner to ensure valid
JSON?

Thanks,

James