[notmuch] [PATCH] JSON output for notmuch-search and notmuch-show.

2009-12-31 Thread David Bremner
On Thu, 31 Dec 2009 00:54:55 -0800, Scott Robinson  
wrote:
> Excerpts from Carl Worth's message of Tue Dec 22 21:48:34 -0800 2009:
> > On Fri, 18 Dec 2009 10:47:33 -0800, Scott Robinson  
> > wrote:
> > > Resubmit a full patch, or submit another one on top of it?
> > 
> > A new full patch would be great, thanks!
> 
> Sadly, I won't be able to make the changes requested. I'm falling off the
> Internet shortly.
> 
> Hopefully David, who already put in a couple improvements, can do the 
> finishing
> touches?

Happy to. Thanks for your big effort so far!

d


[notmuch] [PATCH] JSON output for notmuch-search and notmuch-show.

2009-12-31 Thread Scott Robinson
Excerpts from Carl Worth's message of Tue Dec 22 21:48:34 -0800 2009:
> On Fri, 18 Dec 2009 10:47:33 -0800, Scott Robinson  
> wrote:
> > Resubmit a full patch, or submit another one on top of it?
> 
> A new full patch would be great, thanks!

Sadly, I won't be able to make the changes requested. I'm falling off the
Internet shortly.

Hopefully David, who already put in a couple improvements, can do the finishing
touches?


[notmuch] [PATCH] JSON output for notmuch-search and notmuch-show.

2009-12-25 Thread David Bremner
On Fri, 18 Dec 2009 10:47:33 -0800, Scott Robinson  
wrote:

> Resubmit a full patch, or submit another one on top of it?

My own feeling is that in general if a patch hasn't been merged into
master, and the changes don't form a separate logical change (i.e. "oh,
if you take that patch, you could have this feature too"), then
resubmitting makes the most sense. This also provides a chance to rebase
against master.

Of course, if I'm way off base here, please (notmuch list readers) let
me know.

David


[notmuch] [PATCH] JSON output for notmuch-search and notmuch-show.

2009-12-22 Thread Carl Worth
On Fri, 18 Dec 2009 10:47:33 -0800, Scott Robinson  
wrote:
> Resubmit a full patch, or submit another one on top of it?

A new full patch would be great, thanks!

-Carl
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 



[notmuch] [PATCH] JSON output for notmuch-search and notmuch-show.

2009-12-18 Thread Scott Robinson
Excerpts from Carl Worth's message of Fri Dec 18 09:31:39 -0800 2009:
> [...]
> I don't know why, but I think I'd prefer --format for the name here.

ACK

> [...]
> It looks like the new documentation is missing that point, (and the man
> page in notmuch.1 is missing an update as well).

ACK

> [...]
> That's just fine. The old numbering semantics were quite bizarre and
> nothing I wanted to set it stone.

Cool. :-)

Resubmit a full patch, or submit another one on top of it?
-- 
Scott Robinson | http://quadhome.com/

Q: Why are my replies five sentences or less?
A: http://five.sentenc.es/


Re: [notmuch] [PATCH] JSON output for notmuch-search and notmuch-show.

2009-12-18 Thread Carl Worth
On Thu, 17 Dec 2009 21:33:54 -0800, Scott Robinson sc...@quadhome.com wrote:
 I took an earlier suggestion and didn't use cJSON, instead writing custom code
 for emitting the new format.

Nice! I have a few comments below.

 Added an --output=(json|text|) command-line option to both
 notmuch-search and notmuch-show.

I don't know why, but I think I'd prefer --format for the name here.

 In the case of notmuch-show, --output=json also implies
 --entire-thread as the thread structure is implicit in the emitted
 document tree.

It looks like the new documentation is missing that point, (and the man
page in notmuch.1 is missing an update as well).

 As a coincidence to the implementation, multipart message ID numbers are
 now incremented with each part printed. This changes the previous
 semantics, which were unclear and not necessary related to the actual
 ordering of the message parts.

That's just fine. The old numbering semantics were quite bizarre and
nothing I wanted to set it stone.

-Carl


pgpQHJQbXaM0f.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[notmuch] [PATCH] JSON output for notmuch-search and notmuch-show.

2009-12-17 Thread Scott Robinson
Excerpts from David Bremner's message of Mon Dec 14 15:10:12 -0800 2009:
> OK, I'll wait for Scott's patch, and see how he is using cJSON. Just
> stealing a few functions might be the way to go.
> 
> The cJSON code is less horrifying after running through indent. Now all
> we need is "indent --carl" :)
> 

I took an earlier suggestion and didn't use cJSON, instead writing custom code
for emitting the new format.



Added an "--output=(json|text|)" command-line option to both
notmuch-search and notmuch-show.

In the case of notmuch-show, "--output=json" also implies
"--entire-thread" as the thread structure is implicit in the emitted
document tree.

As a coincidence to the implementation, multipart message ID numbers are
now incremented with each part printed. This changes the previous
semantics, which were unclear and not necessary related to the actual
ordering of the message parts.
---
 Makefile.local   |3 +-
 json.c   |   73 ++
 notmuch-client.h |3 +
 notmuch-search.c |  163 +---
 notmuch-show.c   |  275 ++
 notmuch.c|   24 --
 show-message.c   |4 +-
 7 files changed, 481 insertions(+), 64 deletions(-)
 create mode 100644 json.c

diff --git a/Makefile.local b/Makefile.local
index 933ff4c..53b474b 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -18,7 +18,8 @@ notmuch_client_srcs = \
notmuch-tag.c   \
notmuch-time.c  \
query-string.c  \
-   show-message.c
+   show-message.c  \
+   json.c

 notmuch_client_modules = $(notmuch_client_srcs:.c=.o)
 notmuch: $(notmuch_client_modules) lib/notmuch.a
diff --git a/json.c b/json.c
new file mode 100644
index 000..ee563d6
--- /dev/null
+++ b/json.c
@@ -0,0 +1,73 @@
+/* notmuch - Not much of an email program, (just index and search)
+ *
+ * Copyright ? 2009 Carl Worth
+ * Copyright ? 2009 Keith Packard
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see http://www.gnu.org/licenses/ .
+ *
+ * Authors: Carl Worth 
+ * Keith Packard 
+ */
+
+#include "notmuch-client.h"
+
+/*
+ * json_quote_str derived from cJSON's print_string_ptr,
+ * Copyright (c) 2009 Dave Gamble
+ */
+
+char *
+json_quote_str(const void *ctx, const char *str)
+{
+const char *ptr;
+char *ptr2;
+char *out;
+int len = 0;
+
+if (!str)
+   return NULL;
+
+for (ptr = str; *ptr; len++, ptr++) {
+   if (*ptr < 32 || *ptr == '\"' || *ptr == '\\')
+   len++;
+}
+
+out = talloc_array (ctx, char, len + 3);
+
+ptr = str;
+ptr2 = out;
+
+*ptr2++ = '\"';
+while (*ptr) {
+   if (*ptr > 31 && *ptr != '\"' && *ptr != '\\') {
+   *ptr2++ = *ptr++;
+   } else {
+   *ptr2++ = '\\';
+   switch (*ptr++) {
+   case '\"':  *ptr2++ = '\"'; break;
+   case '\\':  *ptr2++ = '\\'; break;
+   case '\b':  *ptr2++ = 'b';  break;
+   case '\f':  *ptr2++ = 'f';  break;
+   case '\n':  *ptr2++ = 'n';  break;
+   case '\r':  *ptr2++ = 'r';  break;
+   case '\t':  *ptr2++ = 't';  break;
+   default: ptr2--;break;
+   }
+   }
+}
+*ptr2++ = '\"';
+*ptr2++ = '\0';
+
+return out;
+}
diff --git a/notmuch-client.h b/notmuch-client.h
index 50a30fe..7b844b9 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -143,6 +143,9 @@ notmuch_status_t
 show_message_body (const char *filename,
   void (*show_part) (GMimeObject *part, int *part_count));

+char *
+json_quote_str (const void *ctx, const char *str);
+
 /* notmuch-config.c */

 typedef struct _notmuch_config notmuch_config_t;
diff --git a/notmuch-search.c b/notmuch-search.c
index dc44eb6..e243747 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -20,8 +20,120 @@

 #include "notmuch-client.h"

+typedef struct search_format {
+const char *results_start;
+const char *thread_start;
+void (*thread) (const void *ctx,
+   const char *id,
+   const time_t date,
+   const int matched,
+   const int total,
+   const char *authors,
+   const char *subject);
+const char *tag_start;
+const char *tag;
+ 

[notmuch] [PATCH] JSON output for notmuch-search and notmuch-show.

2009-12-17 Thread Scott Robinson
Excerpts from David Bremner's message of Mon Dec 14 15:10:12 -0800 2009:
 OK, I'll wait for Scott's patch, and see how he is using cJSON. Just
 stealing a few functions might be the way to go.
 
 The cJSON code is less horrifying after running through indent. Now all
 we need is indent --carl :)
 

I took an earlier suggestion and didn't use cJSON, instead writing custom code
for emitting the new format.



Added an --output=(json|text|) command-line option to both
notmuch-search and notmuch-show.

In the case of notmuch-show, --output=json also implies
--entire-thread as the thread structure is implicit in the emitted
document tree.

As a coincidence to the implementation, multipart message ID numbers are
now incremented with each part printed. This changes the previous
semantics, which were unclear and not necessary related to the actual
ordering of the message parts.
---
 Makefile.local   |3 +-
 json.c   |   73 ++
 notmuch-client.h |3 +
 notmuch-search.c |  163 +---
 notmuch-show.c   |  275 ++
 notmuch.c|   24 --
 show-message.c   |4 +-
 7 files changed, 481 insertions(+), 64 deletions(-)
 create mode 100644 json.c

diff --git a/Makefile.local b/Makefile.local
index 933ff4c..53b474b 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -18,7 +18,8 @@ notmuch_client_srcs = \
notmuch-tag.c   \
notmuch-time.c  \
query-string.c  \
-   show-message.c
+   show-message.c  \
+   json.c
 
 notmuch_client_modules = $(notmuch_client_srcs:.c=.o)
 notmuch: $(notmuch_client_modules) lib/notmuch.a
diff --git a/json.c b/json.c
new file mode 100644
index 000..ee563d6
--- /dev/null
+++ b/json.c
@@ -0,0 +1,73 @@
+/* notmuch - Not much of an email program, (just index and search)
+ *
+ * Copyright © 2009 Carl Worth
+ * Copyright © 2009 Keith Packard
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see http://www.gnu.org/licenses/ .
+ *
+ * Authors: Carl Worth cwo...@cworth.org
+ * Keith Packard kei...@keithp.com
+ */
+
+#include notmuch-client.h
+
+/*
+ * json_quote_str derived from cJSON's print_string_ptr,
+ * Copyright (c) 2009 Dave Gamble
+ */
+
+char *
+json_quote_str(const void *ctx, const char *str)
+{
+const char *ptr;
+char *ptr2;
+char *out;
+int len = 0;
+
+if (!str)
+   return NULL;
+
+for (ptr = str; *ptr; len++, ptr++) {
+   if (*ptr  32 || *ptr == '\' || *ptr == '\\')
+   len++;
+}
+
+out = talloc_array (ctx, char, len + 3);
+
+ptr = str;
+ptr2 = out;
+
+*ptr2++ = '\';
+while (*ptr) {
+   if (*ptr  31  *ptr != '\'  *ptr != '\\') {
+   *ptr2++ = *ptr++;
+   } else {
+   *ptr2++ = '\\';
+   switch (*ptr++) {
+   case '\':  *ptr2++ = '\'; break;
+   case '\\':  *ptr2++ = '\\'; break;
+   case '\b':  *ptr2++ = 'b';  break;
+   case '\f':  *ptr2++ = 'f';  break;
+   case '\n':  *ptr2++ = 'n';  break;
+   case '\r':  *ptr2++ = 'r';  break;
+   case '\t':  *ptr2++ = 't';  break;
+   default: ptr2--;break;
+   }
+   }
+}
+*ptr2++ = '\';
+*ptr2++ = '\0';
+
+return out;
+}
diff --git a/notmuch-client.h b/notmuch-client.h
index 50a30fe..7b844b9 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -143,6 +143,9 @@ notmuch_status_t
 show_message_body (const char *filename,
   void (*show_part) (GMimeObject *part, int *part_count));
 
+char *
+json_quote_str (const void *ctx, const char *str);
+
 /* notmuch-config.c */
 
 typedef struct _notmuch_config notmuch_config_t;
diff --git a/notmuch-search.c b/notmuch-search.c
index dc44eb6..e243747 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -20,8 +20,120 @@
 
 #include notmuch-client.h
 
+typedef struct search_format {
+const char *results_start;
+const char *thread_start;
+void (*thread) (const void *ctx,
+   const char *id,
+   const time_t date,
+   const int matched,
+   const int total,
+   const char *authors,
+   const char *subject);
+const char *tag_start;
+const