Re: [notmuch] [PATCH] Add an "--format=(json|text)" command-line option to both notmuch-search and notmuch-show.

2010-02-23 Thread Carl Worth
On Thu, 31 Dec 2009 11:17:40 -0400, da...@tethera.net wrote:
> This is an updated version of Scott Robinson's patch of
> id:1261114167-sup-8...@lisa. All of the hard work is Scott's. My
> changes to Scotts patch are 
>  - change option to --format from --output
>  - make a couple of calls to function points conditional on the 
>function pointers being non-null
>  - updated the built-in documentation and the man page
> 
> I also changed the copyright of json.c to Scott. Hope that's OK with
> Scott.

Well that's embarrassing. I just went through the effort of reviewing
the old patch and basically re-constructing that same list of tasks,
(only to find out that this updated patch was already sitting in my
queue, but later).

Anyway, very well done! I've applied this now with one change:

I'm now printing "thread" instead of "id" as the JSON name for the
field with the thread id in it.

I also added a mention to the TODO file that we should fix --format=json
to not imply --entire-thread.

Thanks again, David and Scott (and we hope that all the backpacking goes
well, Scott!).

-Carl


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


[notmuch] [PATCH] Add an "--format=(json|text)" command-line option to both notmuch-search and notmuch-show.

2010-02-23 Thread Carl Worth
On Thu, 31 Dec 2009 11:17:40 -0400, david at tethera.net wrote:
> This is an updated version of Scott Robinson's patch of
> id:1261114167-sup-8228 at lisa. All of the hard work is Scott's. My
> changes to Scotts patch are 
>  - change option to --format from --output
>  - make a couple of calls to function points conditional on the 
>function pointers being non-null
>  - updated the built-in documentation and the man page
> 
> I also changed the copyright of json.c to Scott. Hope that's OK with
> Scott.

Well that's embarrassing. I just went through the effort of reviewing
the old patch and basically re-constructing that same list of tasks,
(only to find out that this updated patch was already sitting in my
queue, but later).

Anyway, very well done! I've applied this now with one change:

I'm now printing "thread" instead of "id" as the JSON name for the
field with the thread id in it.

I also added a mention to the TODO file that we should fix --format=json
to not imply --entire-thread.

Thanks again, David and Scott (and we hope that all the backpacking goes
well, Scott!).

-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] Add an "--format=(json|text)" command-line option to both notmuch-search and notmuch-show.

2010-02-10 Thread Scott Robinson
Excerpts from David Bremner's message of Wed Feb 10 07:51:47 -0600 2010:
> Dear Scott and other interested parties;
> 
> As I play with json output a bit more, it seems like having
> --entire-thread optional would be useful for quite a few applications.
> For example, if I want to get the From address for a given message-ID, I
> with the current setup I have to post process the output. This is
> doable, but I wonder if the better option isn't to make --entire-thread
> optional for --format=json as well. 
> 
> Any thoughts?

I made --entire-thread forced becuase it kept the JSON patch minimal. The way
the thread structure is calculated is closely tied into the message tree
recursion. It would have required a much more significant refactoring to get
both ways; and, I wanted the patch to have as few barriers to being merged.

However, as patch still hasn't been merged and probably needs to be rebased,
there doesn't seem to be any good reason anymore to avoid the work.

Except, I can't do it. As I noted in an earlier e-mail, I have to abandon this
piece of code. I'm a bit busy backpacking through Central America. :-)


Re: [notmuch] [PATCH] Add an "--format=(json|text)" command-line option to both notmuch-search and notmuch-show.

2010-02-10 Thread Scott Robinson
Excerpts from David Bremner's message of Wed Feb 10 07:51:47 -0600 2010:
> Dear Scott and other interested parties;
> 
> As I play with json output a bit more, it seems like having
> --entire-thread optional would be useful for quite a few applications.
> For example, if I want to get the From address for a given message-ID, I
> with the current setup I have to post process the output. This is
> doable, but I wonder if the better option isn't to make --entire-thread
> optional for --format=json as well. 
> 
> Any thoughts?

I made --entire-thread forced becuase it kept the JSON patch minimal. The way
the thread structure is calculated is closely tied into the message tree
recursion. It would have required a much more significant refactoring to get
both ways; and, I wanted the patch to have as few barriers to being merged.

However, as patch still hasn't been merged and probably needs to be rebased,
there doesn't seem to be any good reason anymore to avoid the work.

Except, I can't do it. As I noted in an earlier e-mail, I have to abandon this
piece of code. I'm a bit busy backpacking through Central America. :-)
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[notmuch] [PATCH] Add an "--format=(json|text)" command-line option to both notmuch-search and notmuch-show.

2010-02-10 Thread David Bremner
On Thu, 31 Dec 2009 11:17:40 -0400, david at tethera.net wrote:
> From: Scott Robinson 
> 
> In the case of notmuch-show, "--format=json" also implies
> "--entire-thread" as the thread structure is implicit in the emitted
> document tree.
> 

Dear Scott and other interested parties;

As I play with json output a bit more, it seems like having
--entire-thread optional would be useful for quite a few applications.
For example, if I want to get the From address for a given message-ID, I
with the current setup I have to post process the output. This is
doable, but I wonder if the better option isn't to make --entire-thread
optional for --format=json as well. 

Any thoughts?

David



Re: [notmuch] [PATCH] Add an "--format=(json|text)" command-line option to both notmuch-search and notmuch-show.

2010-02-10 Thread David Bremner
On Thu, 31 Dec 2009 11:17:40 -0400, da...@tethera.net wrote:
> From: Scott Robinson 
> 
> In the case of notmuch-show, "--format=json" also implies
> "--entire-thread" as the thread structure is implicit in the emitted
> document tree.
> 

Dear Scott and other interested parties;

As I play with json output a bit more, it seems like having
--entire-thread optional would be useful for quite a few applications.
For example, if I want to get the From address for a given message-ID, I
with the current setup I have to post process the output. This is
doable, but I wonder if the better option isn't to make --entire-thread
optional for --format=json as well. 

Any thoughts?

David

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [notmuch] [PATCH] Add an "--format=(json|text)" command-line option to both notmuch-search and notmuch-show.

2009-12-31 Thread Scott Robinson
Excerpts from david's message of Thu Dec 31 07:17:40 -0800 2009:
> I also changed the copyright of json.c to Scott. Hope that's OK with
> Scott.

That is totally OK.

Thank you for carrying this patch to conclusion!

Can't wait to see how notmuch has evolved in six or so months...
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[notmuch] [PATCH] Add an "--format=(json|text)" command-line option to both notmuch-search and notmuch-show.

2009-12-31 Thread Scott Robinson
Excerpts from david's message of Thu Dec 31 07:17:40 -0800 2009:
> I also changed the copyright of json.c to Scott. Hope that's OK with
> Scott.

That is totally OK.

Thank you for carrying this patch to conclusion!

Can't wait to see how notmuch has evolved in six or so months...


[notmuch] [PATCH] Add an "--format=(json|text)" command-line option to both notmuch-search and notmuch-show.

2009-12-31 Thread da...@tethera.net
From: Scott Robinson 

In the case of notmuch-show, "--format=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.
---

This is an updated version of Scott Robinson's patch of
id:1261114167-sup-8228 at lisa. All of the hard work is Scott's. My
changes to Scotts patch are 
 - change option to --format from --output
 - make a couple of calls to function points conditional on the 
   function pointers being non-null
 - updated the built-in documentation and the man page

I also changed the copyright of json.c to Scott. Hope that's OK with
Scott.

 Makefile.local   |3 +-
 json.c   |   72 ++
 notmuch-client.h |3 +
 notmuch-search.c |  163 +---
 notmuch-show.c   |  278 ++
 notmuch.1|   27 +-
 notmuch.c|   29 +--
 show-message.c   |4 +-
 8 files changed, 514 insertions(+), 65 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..3960750
--- /dev/null
+++ b/json.c
@@ -0,0 +1,72 @@
+/* notmuch - Not much of an email program, (just index and search)
+ *
+ * Copyright ?? 2009 Scott Robinson
+ *
+ * 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: Scott Robinson 
+ *
+ */
+
+#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..482c6e8 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;
+const char *tag_sep;
+const char *tag_end;
+const char *thread_se

[notmuch] [PATCH] Add an "--format=(json|text)" command-line option to both notmuch-search and notmuch-show.

2009-12-31 Thread david
From: Scott Robinson 

In the case of notmuch-show, "--format=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.
---

This is an updated version of Scott Robinson's patch of
id:1261114167-sup-8...@lisa. All of the hard work is Scott's. My
changes to Scotts patch are 
 - change option to --format from --output
 - make a couple of calls to function points conditional on the 
   function pointers being non-null
 - updated the built-in documentation and the man page

I also changed the copyright of json.c to Scott. Hope that's OK with
Scott.

 Makefile.local   |3 +-
 json.c   |   72 ++
 notmuch-client.h |3 +
 notmuch-search.c |  163 +---
 notmuch-show.c   |  278 ++
 notmuch.1|   27 +-
 notmuch.c|   29 +--
 show-message.c   |4 +-
 8 files changed, 514 insertions(+), 65 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..3960750
--- /dev/null
+++ b/json.c
@@ -0,0 +1,72 @@
+/* notmuch - Not much of an email program, (just index and search)
+ *
+ * Copyright © 2009 Scott Robinson
+ *
+ * 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: Scott Robinson 
+ *
+ */
+
+#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..482c6e8 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;
+const char *tag_sep;
+const char *tag_end;
+const char *thread_