[notmuch] [PATCH] notmuch-show.c: provide an option --format=message-ids which outputs only ids.

2009-12-17 Thread da...@tethera.net
From: David Bremner 

If the option --format=message-ids is passed on the command line, only message
IDs are output.  A new structure show_options_t is defined to keep track of
all (currently 2) command line options.
---

It seems a shame to parse the entire output of notmuch show to get a
message id (or all of the message ids) contained in a thread.  One
might like a shorter command line option, but this seems to leave room
for --format=json, and so on.  Similarly, defining an option structure is 
arguably overengineering; I'm happy to rework to just pass a second boolean 
parameter to notmuch_show_messages.  

 notmuch-show.c |   30 ++
 1 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index 376aacd..4ed8cec 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -20,6 +20,11 @@

 #include "notmuch-client.h"

+typedef struct {
+  enum { FORMAT_DEFAULT, FORMAT_MESSAGE_ID } format;
+  int entire_thread;
+} show_options_t;
+
 static const char *
 _get_tags_as_string (void *ctx, notmuch_message_t *message)
 {
@@ -185,7 +190,7 @@ show_message (void *ctx, notmuch_message_t *message, int 
indent)

 static void
 show_messages (void *ctx, notmuch_messages_t *messages, int indent,
-  notmuch_bool_t entire_thread)
+  show_options_t *options)
 {
 notmuch_message_t *message;
 notmuch_bool_t match;
@@ -201,13 +206,17 @@ show_messages (void *ctx, notmuch_messages_t *messages, 
int indent,

next_indent = indent;

-   if (match || entire_thread) {
-   show_message (ctx, message, indent);
-   next_indent = indent + 1;
+   if (match || options->entire_thread) {
+   if (options->format == FORMAT_DEFAULT) {
+   show_message (ctx, message, indent);
+   next_indent = indent + 1;
+   } else {
+   puts (notmuch_message_get_message_id (message));
+   } 
}

show_messages (ctx, notmuch_message_get_replies (message),
-  next_indent, entire_thread);
+  next_indent, options);

notmuch_message_destroy (message);
 }
@@ -222,17 +231,22 @@ notmuch_show_command (void *ctx, unused (int argc), 
unused (char *argv[]))
 notmuch_threads_t *threads;
 notmuch_thread_t *thread;
 notmuch_messages_t *messages;
+show_options_t options;
 char *query_string;
-int entire_thread = 0;
 int i;

+options.entire_thread = 0;
+options.format = FORMAT_DEFAULT;
+
 for (i = 0; i < argc && argv[i][0] == '-'; i++) {
if (strcmp (argv[i], "--") == 0) {
i++;
break;
}
 if (strcmp(argv[i], "--entire-thread") == 0) {
-   entire_thread = 1;
+   options.entire_thread = 1;
+   } else if (strcmp (argv[i], "--format=message-ids") == 0) {
+   options.format = FORMAT_MESSAGE_ID;
} else {
fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
return 1;
@@ -280,7 +294,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused 
(char *argv[]))
INTERNAL_ERROR ("Thread %s has no toplevel messages.\n",
notmuch_thread_get_thread_id (thread));

-   show_messages (ctx, messages, 0, entire_thread);
+   show_messages (ctx, messages, 0, );

notmuch_thread_destroy (thread);
 }
-- 
1.6.5.3



[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 2/9] Adjust autoload comments

2009-12-17 Thread James Rowe
  [Sorry, I'm flipping back and forth between mail clients at the moment and
I appear to have inadvertently marked a lot of mail as read that wasn't.]

Excerpts from Carl's message of Fri Dec 04 01:07:07 + 2009:
> On Mon, 30 Nov 2009 20:38:00 +, James Rowe wrote:
> >   I had planned on posting a patch for inclusion in packaging/Gentoo per
> > Carl's mail[2], but the whole GPL 2 vs 3 thing made me put it on the
> > backburner and I haven't looked again. Might still be useful to people
> > unless there is going to be a "real" release soon, as then it would be
> > easier to push for it on bugs.gentoo.org.
>
> Is the GPLv3 a problem for you and your ebuild for some reason, or is it
> just that you happened to start with a GPLv2 file or so?

  GPL v3 isn't a problem for me personally.  The problem is Gentoo ebuilds in
the main tree are all GPL v2, and I accepted changes with a clear GPL v2 header
on the ebuild.  I don't claim to understand the licensing stuff enough to know
if mixing the two together is valid, so I just moved on to something more fun.

  I might have pushed the issue if it was important, but it isn't even
a valuable change.

> I'm definitely interested in hearing, since this is the first project
> I've let loose myself under the GPLv3. So far, it hasn't seemed to be a
> big impediment to contributions, which I think is great.

  It definitely doesn't seem to have been an impediment.  git-rank-contributors
shows 29 contributors already, and that is very impressive given the age of the
project.
-- 
Thanks,

James
-- next part --
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 290 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20091217/f651b40e/attachment.pgp>


[notmuch] [PATCH 2/9] Adjust autoload comments

2009-12-17 Thread Carl Worth
On Thu, 17 Dec 2009 17:17:12 +, "James Rowe"  wrote:
>   [Sorry, I'm flipping back and forth between mail clients at the moment and
> I appear to have inadvertently marked a lot of mail as read that
> wasn't.]

No worries. I don't even have the excuse of flipping back and forth, and
I keep messing up my mail too.

Most recently I realized that just moving existing mail files into the
mail store keeps them hidden from notmuch, (the mtime of the containing
directory is updated, but the mtime of the file itself is still older so
gets ignored). This bug will be fixed with the rewrite of new-file
detection (with support for deleted/renamed files). I'll be landing that
soon (promise!).

>   GPL v3 isn't a problem for me personally.

OK. Thanks for following up.

> The problem is Gentoo ebuilds in
> the main tree are all GPL v2, and I accepted changes with a clear GPL v2 
> header
> on the ebuild.  I don't claim to understand the licensing stuff enough to know
> if mixing the two together is valid, so I just moved on to something more fun.

GPLv2 and GPLv3 are incompatible by design. So there's no way to mix
them unless the code with the GPLv2 license has a notice that says
"either version 2 of the License, or (at your option) any later
version."

>   It definitely doesn't seem to have been an impediment.  
> git-rank-contributors
> shows 29 contributors already, and that is very impressive given the age of 
> the
> project.

I agree. It's delightful to have so much help on the project
already. (And a bunch more will be landing soon once I start working
through my patch backlog.)

-Carl
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20091217/c93aaf5e/attachment.pgp>


[notmuch] [PATCH (rebased)] Handle message renames in mail spool

2009-12-17 Thread Mikhail Gusarov

Twas brillig at 16:51:17 16.12.2009 UTC-07 when bdale at gag.com did gyre and 
gimble:

 >> But the above sounds like the List-Id header is unreliable enough to
 >> be useless.

 BG> FWIW, that does not match my experience.

Yeah. This mail just arrived to my "main" folder instead of "notmuch"
one, as you kept me in CC and hence Mailman did not send the copy with
List-Id to me.

Please read the whole thread.

-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20091217/0f93593e/attachment.pgp>


Re: [notmuch] [PATCH 2/9] Adjust autoload comments

2009-12-17 Thread James Rowe
  [Sorry, I'm flipping back and forth between mail clients at the moment and
I appear to have inadvertently marked a lot of mail as read that wasn't.]

Excerpts from Carl's message of Fri Dec 04 01:07:07 + 2009:
 On Mon, 30 Nov 2009 20:38:00 +, James Rowe wrote:
I had planned on posting a patch for inclusion in packaging/Gentoo per
  Carl's mail[2], but the whole GPL 2 vs 3 thing made me put it on the
  backburner and I haven't looked again. Might still be useful to people
  unless there is going to be a real release soon, as then it would be
  easier to push for it on bugs.gentoo.org.

 Is the GPLv3 a problem for you and your ebuild for some reason, or is it
 just that you happened to start with a GPLv2 file or so?

  GPL v3 isn't a problem for me personally.  The problem is Gentoo ebuilds in
the main tree are all GPL v2, and I accepted changes with a clear GPL v2 header
on the ebuild.  I don't claim to understand the licensing stuff enough to know
if mixing the two together is valid, so I just moved on to something more fun.

  I might have pushed the issue if it was important, but it isn't even
a valuable change.

 I'm definitely interested in hearing, since this is the first project
 I've let loose myself under the GPLv3. So far, it hasn't seemed to be a
 big impediment to contributions, which I think is great.

  It definitely doesn't seem to have been an impediment.  git-rank-contributors
shows 29 contributors already, and that is very impressive given the age of the
project.
-- 
Thanks,

James


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


Re: [notmuch] [PATCH 2/9] Adjust autoload comments

2009-12-17 Thread Carl Worth
On Thu, 17 Dec 2009 17:17:12 +, James Rowe jnr...@gmail.com wrote:
   [Sorry, I'm flipping back and forth between mail clients at the moment and
 I appear to have inadvertently marked a lot of mail as read that
 wasn't.]

No worries. I don't even have the excuse of flipping back and forth, and
I keep messing up my mail too.

Most recently I realized that just moving existing mail files into the
mail store keeps them hidden from notmuch, (the mtime of the containing
directory is updated, but the mtime of the file itself is still older so
gets ignored). This bug will be fixed with the rewrite of new-file
detection (with support for deleted/renamed files). I'll be landing that
soon (promise!).

   GPL v3 isn't a problem for me personally.

OK. Thanks for following up.

 The problem is Gentoo ebuilds in
 the main tree are all GPL v2, and I accepted changes with a clear GPL v2 
 header
 on the ebuild.  I don't claim to understand the licensing stuff enough to know
 if mixing the two together is valid, so I just moved on to something more fun.

GPLv2 and GPLv3 are incompatible by design. So there's no way to mix
them unless the code with the GPLv2 license has a notice that says
either version 2 of the License, or (at your option) any later
version.

   It definitely doesn't seem to have been an impediment.  
 git-rank-contributors
 shows 29 contributors already, and that is very impressive given the age of 
 the
 project.

I agree. It's delightful to have so much help on the project
already. (And a bunch more will be landing soon once I start working
through my patch backlog.)

-Carl


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


Re: [notmuch] wish: syncable/immutable threads

2009-12-17 Thread David Bremner
On Tue, 15 Dec 2009 16:36:04 -0800, Carl Worth cwo...@cworth.org wrote:

 But yes, if you can make your links depend only on message IDs then you
 can get reliable results even before we start including thread IDs in
 the dump output. The result of notmuch show --entire-thread id:foo is
 quite similar to the result of notmuch show thread:bar (for the
 corresponding thread ID of course). It differs only in the match
 field, which is used to determine which messages to open by default.

I'm thinking of making links in the style threadof:msg-id.  At the
moment I just substitute id: for threadof: and call notmuch-show. This
relies on (notmuch-show id:foo) using notmuch show --entire-thread
or something equivalent.  I could also put another layer of function
there if relying on the behaviour of notmuch-show is an obviously bad
idea.

David

___
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 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