maintenance of notmuch ruby bindings

2014-05-15 Thread Ali Polatel
2014-05-15 0:59 GMT+03:00 Wael Nasreddine :
> David Bremner  writes:
>
>> Dear Ali;

Hello David,

>> Looking at the commit history, I noticed you haven't worked very much on
>> the notmuch ruby bindings in the last couple years.  That could be
>> because notmuch needs to be done, but if you've lost interest, maybe we
>> should pass on the torch to someone else?  I think Felipe, in copy,
>> would be willing to take that on. At the moment I guess his notmuch-mua
>> is the main consumer. Of course if your still willing/able, that's fine
>> too.

Honestly it's a good idea for me to step down as the maintainer.
I would still love to contribute when I have the time again.
Of course this does not require me to be the maintainer.
As far as I can tell Felipe would be a great fit.

Thanks for the great software.
It is always a pleasure to contribute :)


> I'll be willing to help maintaining it if you need more volunteers.
>
>>
>> d
>> ___
>> notmuch mailing list
>> notmuch at notmuchmail.org
>> http://notmuchmail.org/mailman/listinfo/notmuch
>
> --
>


Re: maintenance of notmuch ruby bindings

2014-05-15 Thread Ali Polatel
2014-05-15 0:59 GMT+03:00 Wael Nasreddine wael.nasredd...@gmail.com:
 David Bremner da...@tethera.net writes:

 Dear Ali;

Hello David,

 Looking at the commit history, I noticed you haven't worked very much on
 the notmuch ruby bindings in the last couple years.  That could be
 because notmuch needs to be done, but if you've lost interest, maybe we
 should pass on the torch to someone else?  I think Felipe, in copy,
 would be willing to take that on. At the moment I guess his notmuch-mua
 is the main consumer. Of course if your still willing/able, that's fine
 too.

Honestly it's a good idea for me to step down as the maintainer.
I would still love to contribute when I have the time again.
Of course this does not require me to be the maintainer.
As far as I can tell Felipe would be a great fit.

Thanks for the great software.
It is always a pleasure to contribute :)


 I'll be willing to help maintaining it if you need more volunteers.


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

 --

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


[PATCH 2/2] ruby: fix missing symbol UINT2FIX()

2013-05-21 Thread Ali Polatel
2013/05/21 Tomi Ollila :
>On Mon, May 20 2013, Felipe Contreras  wrote:
>
>> It has never existed in Ruby (maybe JRuby). Fortunately the symbols are
>> loaded lazily, so nobody would notice unless they try
>> 'query::count_messages'.
>>
>> Signed-off-by: Felipe Contreras 
>
>This patch could be pushed on it's own, but someone (like Ali) could
>comment on the change as searches on both UINT2FIX() & UINT2NUM()
>provides (IMH) insatisfactory results...

LGTM.

My bad, there's no such thing as UINT2FIX().
Yet, what's wrong with UINT2NUM()?

The description looks like:
"...take an unsigned int and convert it to a FIXNUM object if it will fit;
otherwise, convert to a Bignum object..."

Besides ruby-1.8 has it and that's the oldest version I was willing to
support. (If you have some free time, please confirm this because I may
not be remembering correctly.)

>Tomi

-alip

>
>> ---
>>  bindings/ruby/query.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c
>> index e5ba1b7..1658ede 100644
>> --- a/bindings/ruby/query.c
>> +++ b/bindings/ruby/query.c
>> @@ -180,5 +180,5 @@ notmuch_rb_query_count_messages (VALUE self)
>>   * (function may return 0 after printing a message)
>>   * Thus there is nothing we can do here...
>>   */
>> -return UINT2FIX(notmuch_query_count_messages(query));
>> +return UINT2NUM(notmuch_query_count_messages(query));
>>  }
>> --
>> 1.8.3.rc3.286.g3d43083
>>
>> ___
>> notmuch mailing list
>> notmuch at notmuchmail.org
>> http://notmuchmail.org/mailman/listinfo/notmuch
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: 



Re: [PATCH 2/2] ruby: fix missing symbol UINT2FIX()

2013-05-21 Thread Ali Polatel

2013/05/21 Tomi Ollila tomi.oll...@iki.fi:

On Mon, May 20 2013, Felipe Contreras felipe.contre...@gmail.com wrote:


It has never existed in Ruby (maybe JRuby). Fortunately the symbols are
loaded lazily, so nobody would notice unless they try
'query::count_messages'.

Signed-off-by: Felipe Contreras felipe.contre...@gmail.com


This patch could be pushed on it's own, but someone (like Ali) could
comment on the change as searches on both UINT2FIX()  UINT2NUM()
provides (IMH) insatisfactory results...


LGTM.

My bad, there's no such thing as UINT2FIX().
Yet, what's wrong with UINT2NUM()?

The description looks like:
...take an unsigned int and convert it to a FIXNUM object if it will fit;
otherwise, convert to a Bignum object...

Besides ruby-1.8 has it and that's the oldest version I was willing to
support. (If you have some free time, please confirm this because I may
not be remembering correctly.)


Tomi


-alip




---
 bindings/ruby/query.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c
index e5ba1b7..1658ede 100644
--- a/bindings/ruby/query.c
+++ b/bindings/ruby/query.c
@@ -180,5 +180,5 @@ notmuch_rb_query_count_messages (VALUE self)
  * (function may return 0 after printing a message)
  * Thus there is nothing we can do here...
  */
-return UINT2FIX(notmuch_query_count_messages(query));
+return UINT2NUM(notmuch_query_count_messages(query));
 }
--
1.8.3.rc3.286.g3d43083

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


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


[PATCH v2] debian: package ruby bindings

2013-05-16 Thread Ali Polatel
2013/5/16 David Bremner :
> Felipe Contreras  writes:
>>
>> Yes. Do you have an old version of notmuch installed?
>>
>
> Yes I do. Hmm. It still seems like a bug to me; shouldn't the include
> paths be ordered to find the right include files first?
>
> d

Well I must accept I haven't spent much time on thinking how to make
extconf.rb perfect.
Excerpt from extconf.rb from bindings/ruby:

find_header('notmuch.h', '../../lib')
find_library('notmuch', 'notmuch_database_create', '../../lib')

Two problems here:
1. The library must be built before the bindings are built otherwise
the installed version is used.
However the installed version should never be used (or must be
made a non-default option somehow)
2. The library must be built in the source tree. Out-of-source tree
builds will cause extconf.rb to look for the installed version too.
Not sure whether this is a major concern because I don't know
whether out-of-tree builds are supported by the build system.

Having said that, I will try to have a look at solving these issues
this weekend.
Unfortunately I can't make promises because real-life is killing all
my time lately.

-alip


Re: [PATCH v2] debian: package ruby bindings

2013-05-16 Thread Ali Polatel
2013/5/16 David Bremner brem...@debian.org:
 Felipe Contreras felipe.contre...@gmail.com writes:

 Yes. Do you have an old version of notmuch installed?


 Yes I do. Hmm. It still seems like a bug to me; shouldn't the include
 paths be ordered to find the right include files first?

 d

Well I must accept I haven't spent much time on thinking how to make
extconf.rb perfect.
Excerpt from extconf.rb from bindings/ruby:

find_header('notmuch.h', '../../lib')
find_library('notmuch', 'notmuch_database_create', '../../lib')

Two problems here:
1. The library must be built before the bindings are built otherwise
the installed version is used.
However the installed version should never be used (or must be
made a non-default option somehow)
2. The library must be built in the source tree. Out-of-source tree
builds will cause extconf.rb to look for the installed version too.
Not sure whether this is a major concern because I don't know
whether out-of-tree builds are supported by the build system.

Having said that, I will try to have a look at solving these issues
this weekend.
Unfortunately I can't make promises because real-life is killing all
my time lately.

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


[PATCH 6/6] ruby: Add bindings for notmuch_thread_get_messages

2012-11-26 Thread Ali Polatel
LGTM. Thanks for showing love to the ruby bindings as I was away.

On Sat, Nov 24, 2012 at 11:57:07PM -0500, Austin Clements wrote:
>---
> bindings/ruby/defs.h   |3 +++
> bindings/ruby/init.c   |1 +
> bindings/ruby/thread.c |   20 
> 3 files changed, 24 insertions(+)
>
>diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
>index fe81b3f..5b44585 100644
>--- a/bindings/ruby/defs.h
>+++ b/bindings/ruby/defs.h
>@@ -262,6 +262,9 @@ VALUE
> notmuch_rb_thread_get_toplevel_messages (VALUE self);
>
> VALUE
>+notmuch_rb_thread_get_messages (VALUE self);
>+
>+VALUE
> notmuch_rb_thread_get_matched_messages (VALUE self);
>
> VALUE
>diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
>index f4931d3..663271d 100644
>--- a/bindings/ruby/init.c
>+++ b/bindings/ruby/init.c
>@@ -306,6 +306,7 @@ Init_notmuch (void)
> rb_define_method (notmuch_rb_cThread, "thread_id", 
> notmuch_rb_thread_get_thread_id, 0); /* in thread.c */
> rb_define_method (notmuch_rb_cThread, "total_messages", 
> notmuch_rb_thread_get_total_messages, 0); /* in thread.c */
> rb_define_method (notmuch_rb_cThread, "toplevel_messages", 
> notmuch_rb_thread_get_toplevel_messages, 0); /* in thread.c */
>+rb_define_method (notmuch_rb_cThread, "messages", 
>notmuch_rb_thread_get_messages, 0); /* in thread.c */
> rb_define_method (notmuch_rb_cThread, "matched_messages", 
> notmuch_rb_thread_get_matched_messages, 0); /* in thread.c */
> rb_define_method (notmuch_rb_cThread, "authors", 
> notmuch_rb_thread_get_authors, 0); /* in thread.c */
> rb_define_method (notmuch_rb_cThread, "subject", 
> notmuch_rb_thread_get_subject, 0); /* in thread.c */
>diff --git a/bindings/ruby/thread.c b/bindings/ruby/thread.c
>index efe5aaf..56616d9 100644
>--- a/bindings/ruby/thread.c
>+++ b/bindings/ruby/thread.c
>@@ -92,6 +92,26 @@ notmuch_rb_thread_get_toplevel_messages (VALUE self)
> }
>
> /*
>+ * call-seq: THREAD.messages => MESSAGES
>+ *
>+ * Get a Notmuch::Messages iterator for the all messages in thread.
>+ */
>+VALUE
>+notmuch_rb_thread_get_messages (VALUE self)
>+{
>+notmuch_messages_t *messages;
>+notmuch_thread_t *thread;
>+
>+Data_Get_Notmuch_Thread (self, thread);
>+
>+messages = notmuch_thread_get_messages (thread);
>+if (!messages)
>+  rb_raise (notmuch_rb_eMemoryError, "Out of memory");
>+
>+return Data_Wrap_Struct (notmuch_rb_cMessages, NULL, NULL, messages);
>+}
>+
>+/*
>  * call-seq: THREAD.matched_messages => fixnum
>  *
>  * Get the number of messages in thread that matched the search
>-- 
>1.7.10.4
>
>___
>notmuch mailing list
>notmuch at notmuchmail.org
>http://notmuchmail.org/mailman/listinfo/notmuch
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: 



[PATCH 04/18] insert: copy stdin to Maildir tmp file

2012-11-26 Thread Ali Polatel
On Wed, Jul 25, 2012 at 11:42:33PM +1000, Peter Wang wrote:
>Read the new message from standard input into the Maildir tmp file.
>---
> notmuch-insert.c |   51 +--
> 1 files changed, 49 insertions(+), 2 deletions(-)
>
>diff --git a/notmuch-insert.c b/notmuch-insert.c
>index f01a6f2..340f7e4 100644
>--- a/notmuch-insert.c
>+++ b/notmuch-insert.c
>@@ -75,21 +75,68 @@ maildir_open_tmp (void *ctx, const char *dir, char 
>**tmppath, char **newpath)
> }
>
> static notmuch_bool_t
>+copy_fd_data (int fdin, int fdout)
>+{
>+char buf[4096];
>+char *p;
>+ssize_t remain;
>+ssize_t written;
>+
>+for (;;) {
>+  remain = read (fdin, buf, sizeof(buf));
>+  if (remain == 0)
>+  break;
>+  if (remain < 0) {
>+  if (errno == EINTR)
>+  continue;
>+  fprintf (stderr, "Error: reading from standard input: %s\n",
>+   strerror (errno));
>+  return FALSE;
>+  }
>+
>+  p = buf;
>+  do {
>+  written = write (fdout, p, remain);
>+  if (written == 0)
>+  return FALSE;
>+  if (written < 0) {
>+  if (errno == EINTR)
>+  continue;
>+  fprintf (stderr, "Error: writing to temporary file: %s",
>+   strerror (errno));
>+  return FALSE;
>+  }
>+  p += written;
>+  remain -= written;
>+  } while (remain > 0);
>+}
>+
>+return TRUE;
>+}

LGTM. As an optimisation we can also consider using the splice(2) system
call if it is available (as notmuch-deliver does). In case splice()
fails with ENOSYS or EINVAL we can fall back to this method.

I can write the patch for it once this is accepted.
Thanks for the good work!

>+static notmuch_bool_t
> insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,
>   const char *dir)
> {
> char *tmppath;
> char *newpath;
> int fdout;
>+notmuch_bool_t ret;
>
> fdout = maildir_open_tmp (ctx, dir, , );
> if (fdout < 0) {
>   return FALSE;
> }
>
>+ret = copy_fd_data (fdin, fdout);
>+
> close (fdout);
>-unlink (tmppath);
>-return FALSE;
>+
>+if (!ret) {
>+  unlink (tmppath);
>+}
>+
>+return ret;
> }
>
> int
>-- 
>1.7.4.4
>
>___
>notmuch mailing list
>notmuch at notmuchmail.org
>http://notmuchmail.org/mailman/listinfo/notmuch
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: 



Re: [PATCH 04/18] insert: copy stdin to Maildir tmp file

2012-11-26 Thread Ali Polatel

On Wed, Jul 25, 2012 at 11:42:33PM +1000, Peter Wang wrote:

Read the new message from standard input into the Maildir tmp file.
---
notmuch-insert.c |   51 +--
1 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/notmuch-insert.c b/notmuch-insert.c
index f01a6f2..340f7e4 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -75,21 +75,68 @@ maildir_open_tmp (void *ctx, const char *dir, char 
**tmppath, char **newpath)
}

static notmuch_bool_t
+copy_fd_data (int fdin, int fdout)
+{
+char buf[4096];
+char *p;
+ssize_t remain;
+ssize_t written;
+
+for (;;) {
+   remain = read (fdin, buf, sizeof(buf));
+   if (remain == 0)
+   break;
+   if (remain  0) {
+   if (errno == EINTR)
+   continue;
+   fprintf (stderr, Error: reading from standard input: %s\n,
+strerror (errno));
+   return FALSE;
+   }
+
+   p = buf;
+   do {
+   written = write (fdout, p, remain);
+   if (written == 0)
+   return FALSE;
+   if (written  0) {
+   if (errno == EINTR)
+   continue;
+   fprintf (stderr, Error: writing to temporary file: %s,
+strerror (errno));
+   return FALSE;
+   }
+   p += written;
+   remain -= written;
+   } while (remain  0);
+}
+
+return TRUE;
+}


LGTM. As an optimisation we can also consider using the splice(2) system
call if it is available (as notmuch-deliver does). In case splice()
fails with ENOSYS or EINVAL we can fall back to this method.

I can write the patch for it once this is accepted.
Thanks for the good work!


+static notmuch_bool_t
insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,
const char *dir)
{
char *tmppath;
char *newpath;
int fdout;
+notmuch_bool_t ret;

fdout = maildir_open_tmp (ctx, dir, tmppath, newpath);
if (fdout  0) {
return FALSE;
}

+ret = copy_fd_data (fdin, fdout);
+
close (fdout);
-unlink (tmppath);
-return FALSE;
+
+if (!ret) {
+   unlink (tmppath);
+}
+
+return ret;
}

int
--
1.7.4.4

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


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


Re: [PATCH 6/6] ruby: Add bindings for notmuch_thread_get_messages

2012-11-26 Thread Ali Polatel

LGTM. Thanks for showing love to the ruby bindings as I was away.

On Sat, Nov 24, 2012 at 11:57:07PM -0500, Austin Clements wrote:

---
bindings/ruby/defs.h   |3 +++
bindings/ruby/init.c   |1 +
bindings/ruby/thread.c |   20 
3 files changed, 24 insertions(+)

diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index fe81b3f..5b44585 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -262,6 +262,9 @@ VALUE
notmuch_rb_thread_get_toplevel_messages (VALUE self);

VALUE
+notmuch_rb_thread_get_messages (VALUE self);
+
+VALUE
notmuch_rb_thread_get_matched_messages (VALUE self);

VALUE
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index f4931d3..663271d 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -306,6 +306,7 @@ Init_notmuch (void)
rb_define_method (notmuch_rb_cThread, thread_id, 
notmuch_rb_thread_get_thread_id, 0); /* in thread.c */
rb_define_method (notmuch_rb_cThread, total_messages, 
notmuch_rb_thread_get_total_messages, 0); /* in thread.c */
rb_define_method (notmuch_rb_cThread, toplevel_messages, 
notmuch_rb_thread_get_toplevel_messages, 0); /* in thread.c */
+rb_define_method (notmuch_rb_cThread, messages, 
notmuch_rb_thread_get_messages, 0); /* in thread.c */
rb_define_method (notmuch_rb_cThread, matched_messages, 
notmuch_rb_thread_get_matched_messages, 0); /* in thread.c */
rb_define_method (notmuch_rb_cThread, authors, 
notmuch_rb_thread_get_authors, 0); /* in thread.c */
rb_define_method (notmuch_rb_cThread, subject, 
notmuch_rb_thread_get_subject, 0); /* in thread.c */
diff --git a/bindings/ruby/thread.c b/bindings/ruby/thread.c
index efe5aaf..56616d9 100644
--- a/bindings/ruby/thread.c
+++ b/bindings/ruby/thread.c
@@ -92,6 +92,26 @@ notmuch_rb_thread_get_toplevel_messages (VALUE self)
}

/*
+ * call-seq: THREAD.messages = MESSAGES
+ *
+ * Get a Notmuch::Messages iterator for the all messages in thread.
+ */
+VALUE
+notmuch_rb_thread_get_messages (VALUE self)
+{
+notmuch_messages_t *messages;
+notmuch_thread_t *thread;
+
+Data_Get_Notmuch_Thread (self, thread);
+
+messages = notmuch_thread_get_messages (thread);
+if (!messages)
+   rb_raise (notmuch_rb_eMemoryError, Out of memory);
+
+return Data_Wrap_Struct (notmuch_rb_cMessages, NULL, NULL, messages);
+}
+
+/*
 * call-seq: THREAD.matched_messages = fixnum
 *
 * Get the number of messages in thread that matched the search
--
1.7.10.4

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


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


Re: [PATCH v2] ruby: extern linkage portability improvement

2012-06-24 Thread Ali Polatel
2012/6/24 Tomi Ollila tomi.oll...@iki.fi:
 Some C compilers are stricter when it comes to (tentative) definition
 of a variable -- in those compilers introducing variable without 'extern'
 keyword always allocates new 'storage' to the variable and linking all
 these modules fails due to duplicate symbols.

 This is reimplementation of Charlie Allom's patch:
 id:1336481467-66356-1-git-send-email-char...@mediasp.com,
 written originally by Ali Polatel. This version has
 more accurate commit message.
 ---
  bindings/ruby/defs.h |   46 +++---
  bindings/ruby/init.c |   26 ++
  2 files changed, 49 insertions(+), 23 deletions(-)

 diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
 index 3f9512b..fe81b3f 100644
 --- a/bindings/ruby/defs.h
 +++ b/bindings/ruby/defs.h
 @@ -24,31 +24,31 @@
  #include notmuch.h
  #include ruby.h

 -VALUE notmuch_rb_cDatabase;
 -VALUE notmuch_rb_cDirectory;
 -VALUE notmuch_rb_cFileNames;
 -VALUE notmuch_rb_cQuery;
 -VALUE notmuch_rb_cThreads;
 -VALUE notmuch_rb_cThread;
 -VALUE notmuch_rb_cMessages;
 -VALUE notmuch_rb_cMessage;
 -VALUE notmuch_rb_cTags;
 -
 -VALUE notmuch_rb_eBaseError;
 -VALUE notmuch_rb_eDatabaseError;
 -VALUE notmuch_rb_eMemoryError;
 -VALUE notmuch_rb_eReadOnlyError;
 -VALUE notmuch_rb_eXapianError;
 -VALUE notmuch_rb_eFileError;
 -VALUE notmuch_rb_eFileNotEmailError;
 -VALUE notmuch_rb_eNullPointerError;
 -VALUE notmuch_rb_eTagTooLongError;
 -VALUE notmuch_rb_eUnbalancedFreezeThawError;
 -VALUE notmuch_rb_eUnbalancedAtomicError;
 -
 -ID ID_call;
 -ID ID_db_create;
 -ID ID_db_mode;
 +extern VALUE notmuch_rb_cDatabase;
 +extern VALUE notmuch_rb_cDirectory;
 +extern VALUE notmuch_rb_cFileNames;
 +extern VALUE notmuch_rb_cQuery;
 +extern VALUE notmuch_rb_cThreads;
 +extern VALUE notmuch_rb_cThread;
 +extern VALUE notmuch_rb_cMessages;
 +extern VALUE notmuch_rb_cMessage;
 +extern VALUE notmuch_rb_cTags;
 +
 +extern VALUE notmuch_rb_eBaseError;
 +extern VALUE notmuch_rb_eDatabaseError;
 +extern VALUE notmuch_rb_eMemoryError;
 +extern VALUE notmuch_rb_eReadOnlyError;
 +extern VALUE notmuch_rb_eXapianError;
 +extern VALUE notmuch_rb_eFileError;
 +extern VALUE notmuch_rb_eFileNotEmailError;
 +extern VALUE notmuch_rb_eNullPointerError;
 +extern VALUE notmuch_rb_eTagTooLongError;
 +extern VALUE notmuch_rb_eUnbalancedFreezeThawError;
 +extern VALUE notmuch_rb_eUnbalancedAtomicError;
 +
 +extern ID ID_call;
 +extern ID ID_db_create;
 +extern ID ID_db_mode;

  /* RSTRING_PTR() is new in ruby-1.9 */
  #if !defined(RSTRING_PTR)
 diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
 index 3fe60fb..f4931d3 100644
 --- a/bindings/ruby/init.c
 +++ b/bindings/ruby/init.c
 @@ -20,6 +20,32 @@

  #include defs.h

 +VALUE notmuch_rb_cDatabase;
 +VALUE notmuch_rb_cDirectory;
 +VALUE notmuch_rb_cFileNames;
 +VALUE notmuch_rb_cQuery;
 +VALUE notmuch_rb_cThreads;
 +VALUE notmuch_rb_cThread;
 +VALUE notmuch_rb_cMessages;
 +VALUE notmuch_rb_cMessage;
 +VALUE notmuch_rb_cTags;
 +
 +VALUE notmuch_rb_eBaseError;
 +VALUE notmuch_rb_eDatabaseError;
 +VALUE notmuch_rb_eMemoryError;
 +VALUE notmuch_rb_eReadOnlyError;
 +VALUE notmuch_rb_eXapianError;
 +VALUE notmuch_rb_eFileError;
 +VALUE notmuch_rb_eFileNotEmailError;
 +VALUE notmuch_rb_eNullPointerError;
 +VALUE notmuch_rb_eTagTooLongError;
 +VALUE notmuch_rb_eUnbalancedFreezeThawError;
 +VALUE notmuch_rb_eUnbalancedAtomicError;
 +
 +ID ID_call;
 +ID ID_db_create;
 +ID ID_db_mode;
 +
  /*
  * Document-module: Notmuch
  *
 --
 1.7.1

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

Looks highly familiar yet strangely good to me.
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] ruby: extern linkage portability improvement

2012-05-15 Thread Ali Polatel
2012/5/13 Austin Clements :
> Quoth Tomi Ollila on May 10 at ?8:12 pm:
>> Some C compilers are stricter when it comes to (tentative) definition
>> of a variable -- in those compilers introducing variable without 'extern'
>> keyword always allocates new 'storage' to the variable and linking all
>> these modules fails due to duplicate symbols.
>>
>> This change uses some macro trickery to avoid writing every variable twice.
>>
>> This is reimplementation of Charlie Allom's patch:
>> id:"1336481467-66356-1-git-send-email-charlie at mediasp.com"
>>
>> combining information from other change made by Ali Polatel.
>> ---
>>
>> Charlie: could you test whether this patch actually work ? :)
>>
>> Everyone: what do you think of the "hiding extern" macro trick ?
>
> This seems like a hacky and nonstandard way to do this. ?Granted, the
> standard way to do this---always declare variables extern in .h files
> and also give a non-extern definition in exactly one .c file---is more
> verbose, but nobody will be surprised or confused by it.

I fully agree or otherwise I'd suggest using:
http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/sh/mac.h

>> ?bindings/ruby/defs.h | ? 56 
>> +++--
>> ?bindings/ruby/init.c | ? ?2 +
>> ?2 files changed, 33 insertions(+), 25 deletions(-)
>>
>> diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
>> index 85d8205..2531760 100644
>> --- a/bindings/ruby/defs.h
>> +++ b/bindings/ruby/defs.h
>> @@ -24,31 +24,37 @@
>> ?#include 
>> ?#include "notmuch.h"
>>
>> -VALUE notmuch_rb_cDatabase;
>> -VALUE notmuch_rb_cDirectory;
>> -VALUE notmuch_rb_cFileNames;
>> -VALUE notmuch_rb_cQuery;
>> -VALUE notmuch_rb_cThreads;
>> -VALUE notmuch_rb_cThread;
>> -VALUE notmuch_rb_cMessages;
>> -VALUE notmuch_rb_cMessage;
>> -VALUE notmuch_rb_cTags;
>> -
>> -VALUE notmuch_rb_eBaseError;
>> -VALUE notmuch_rb_eDatabaseError;
>> -VALUE notmuch_rb_eMemoryError;
>> -VALUE notmuch_rb_eReadOnlyError;
>> -VALUE notmuch_rb_eXapianError;
>> -VALUE notmuch_rb_eFileError;
>> -VALUE notmuch_rb_eFileNotEmailError;
>> -VALUE notmuch_rb_eNullPointerError;
>> -VALUE notmuch_rb_eTagTooLongError;
>> -VALUE notmuch_rb_eUnbalancedFreezeThawError;
>> -VALUE notmuch_rb_eUnbalancedAtomicError;
>> -
>> -ID ID_call;
>> -ID ID_db_create;
>> -ID ID_db_mode;
>> +#ifdef RUBY_INIT_C
>> +#define extern
>> +#endif
>> +
>> +extern VALUE notmuch_rb_cDatabase;
>> +extern VALUE notmuch_rb_cDirectory;
>> +extern VALUE notmuch_rb_cFileNames;
>> +extern VALUE notmuch_rb_cQuery;
>> +extern VALUE notmuch_rb_cThreads;
>> +extern VALUE notmuch_rb_cThread;
>> +extern VALUE notmuch_rb_cMessages;
>> +extern VALUE notmuch_rb_cMessage;
>> +extern VALUE notmuch_rb_cTags;
>> +
>> +extern VALUE notmuch_rb_eBaseError;
>> +extern VALUE notmuch_rb_eDatabaseError;
>> +extern VALUE notmuch_rb_eMemoryError;
>> +extern VALUE notmuch_rb_eReadOnlyError;
>> +extern VALUE notmuch_rb_eXapianError;
>> +extern VALUE notmuch_rb_eFileError;
>> +extern VALUE notmuch_rb_eFileNotEmailError;
>> +extern VALUE notmuch_rb_eNullPointerError;
>> +extern VALUE notmuch_rb_eTagTooLongError;
>> +extern VALUE notmuch_rb_eUnbalancedFreezeThawError;
>> +extern VALUE notmuch_rb_eUnbalancedAtomicError;
>> +
>> +extern ID ID_call;
>> +extern ID ID_db_create;
>> +extern ID ID_db_mode;
>> +
>> +#undef extern
>>
>> ?/* RSTRING_PTR() is new in ruby-1.9 */
>> ?#if !defined(RSTRING_PTR)
>> diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
>> index 3fe60fb..b2dc7f6 100644
>> --- a/bindings/ruby/init.c
>> +++ b/bindings/ruby/init.c
>> @@ -18,7 +18,9 @@
>> ? * Author: Ali Polatel 
>> ? */
>>
>> +#define RUBY_INIT_C
>> ?#include "defs.h"
>> +#undef RUBY_INIT_C
>>
>> ?/*
>> ? * Document-module: Notmuch
> ___
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH 4/4] ruby: Add wrapper for notmuch_query_set_omit_excluded()

2012-05-07 Thread Ali Polatel
---
 bindings/ruby/defs.h  |3 +++
 bindings/ruby/init.c  |7 +++
 bindings/ruby/query.c |   18 ++
 3 files changed, 28 insertions(+)

diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index 6fe5787..85d8205 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -220,6 +220,9 @@ VALUE
 notmuch_rb_query_add_tag_exclude (VALUE self, VALUE tagv);

 VALUE
+notmuch_rb_query_set_omit_excluded (VALUE self, VALUE omitv);
+
+VALUE
 notmuch_rb_query_search_threads (VALUE self);

 VALUE
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index edcf101..3fe60fb 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -96,6 +96,12 @@ Init_notmuch (void)
  */
 rb_define_const (mod, "MESSAGE_FLAG_MATCH", INT2FIX 
(NOTMUCH_MESSAGE_FLAG_MATCH));
 /*
+ * Document-const: Notmuch::MESSAGE_FLAG_EXCLUDED
+ *
+ * Message flag "excluded"
+ */
+rb_define_const (mod, "MESSAGE_FLAG_EXCLUDED", INT2FIX 
(NOTMUCH_MESSAGE_FLAG_EXCLUDED));
+/*
  * Document-const: Notmuch::TAG_MAX
  *
  * Maximum allowed length of a tag
@@ -235,6 +241,7 @@ Init_notmuch (void)
 rb_define_method (notmuch_rb_cQuery, "sort=", notmuch_rb_query_set_sort, 
1); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, "to_s", notmuch_rb_query_get_string, 
0); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, "add_tag_exclude", 
notmuch_rb_query_add_tag_exclude, 1); /* in query.c */
+rb_define_method (notmuch_rb_cQuery, "omit_excluded=", 
notmuch_rb_query_set_omit_excluded, 1); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, "search_threads", 
notmuch_rb_query_search_threads, 0); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, "search_messages", 
notmuch_rb_query_search_messages, 0); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, "count_messages", 
notmuch_rb_query_count_messages, 0); /* in query.c */
diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c
index 2a80008..e5ba1b7 100644
--- a/bindings/ruby/query.c
+++ b/bindings/ruby/query.c
@@ -107,6 +107,24 @@ notmuch_rb_query_add_tag_exclude (VALUE self, VALUE tagv)
 }

 /*
+ * call-seq: QUERY.omit_excluded=(boolean) => nil
+ *
+ * Specify whether to omit excluded results or simply flag them.
+ * By default, this is set to +true+.
+ */
+VALUE
+notmuch_rb_query_set_omit_excluded (VALUE self, VALUE omitv)
+{
+notmuch_query_t *query;
+
+Data_Get_Notmuch_Query (self, query);
+
+notmuch_query_set_omit_excluded (query, RTEST (omitv));
+
+return Qnil;
+}
+
+/*
  * call-seq: QUERY.search_threads => THREADS
  *
  * Search for threads
-- 
1.7.10.1



[PATCH 3/4] ruby: Add workarounds to use in-tree build not the installed one

2012-05-07 Thread Ali Polatel
- Make mkmf use the notmuch.h under ../../lib
- Use libnotmuch.a instead of linking to the installed libnotmuch.so
---
 bindings/ruby/defs.h |4 ++--
 bindings/ruby/extconf.rb |   26 ++
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index a41cf10..6fe5787 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -1,6 +1,6 @@
 /* The Ruby interface to the notmuch mail library
  *
- * Copyright ? 2010, 2011 Ali Polatel
+ * Copyright ? 2010, 2011, 2012 Ali Polatel
  *
  * 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
@@ -21,8 +21,8 @@
 #ifndef DEFS_H
 #define DEFS_H

-#include 
 #include 
+#include "notmuch.h"

 VALUE notmuch_rb_cDatabase;
 VALUE notmuch_rb_cDirectory;
diff --git a/bindings/ruby/extconf.rb b/bindings/ruby/extconf.rb
index ccac609..933f34a 100644
--- a/bindings/ruby/extconf.rb
+++ b/bindings/ruby/extconf.rb
@@ -1,13 +1,31 @@
 #!/usr/bin/env ruby
 # coding: utf-8
-# Copyright 2010, 2011 Ali Polatel 
+# Copyright 2010, 2011, 2012 Ali Polatel 
 # Distributed under the terms of the GNU General Public License v3

 require 'mkmf'

-# Notmuch Library
-find_header('notmuch.h', '../../lib')
-find_library('notmuch', 'notmuch_database_create', '../../lib')
+NOTDIR = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
+NOTHDR = File.join(NOTDIR, 'notmuch.h')
+NOTLIB = File.join(NOTDIR, 'libnotmuch.a')
+
+unless File.exists? NOTHDR
+  $stderr.puts "notmuch.h is missing under #{NOTDIR}"
+  exit 1
+end
+
+unless File.exists? NOTLIB
+  $stderr.puts "libnotmuch.a is missing under #{NOTDIR}"
+  exit 1
+end
+
+# Small hack to build with in-tree version not the installed one.
+# find_header() and friends use standard include/library paths first.
+$stderr.puts "Added -I#{NOTDIR} to $INCFLAGS"
+$INCFLAGS = "-I#{NOTDIR}".quote + " " + $INCFLAGS
+find_header('notmuch.h', NOTDIR)
+
+$LOCAL_LIBS += NOTLIB

 # Create Makefile
 dir_config('notmuch')
-- 
1.7.10.1



[PATCH 2/4] ruby: Add wrapper for notmuch_query_add_tag_exclude

2012-05-07 Thread Ali Polatel
---
 bindings/ruby/defs.h  |3 +++
 bindings/ruby/init.c  |1 +
 bindings/ruby/query.c |   18 ++
 3 files changed, 22 insertions(+)

diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index 25222a6..a41cf10 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -217,6 +217,9 @@ VALUE
 notmuch_rb_query_get_string (VALUE self);

 VALUE
+notmuch_rb_query_add_tag_exclude (VALUE self, VALUE tagv);
+
+VALUE
 notmuch_rb_query_search_threads (VALUE self);

 VALUE
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index 7ad0ecf..edcf101 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -234,6 +234,7 @@ Init_notmuch (void)
 rb_define_method (notmuch_rb_cQuery, "sort", notmuch_rb_query_get_sort, 
0); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, "sort=", notmuch_rb_query_set_sort, 
1); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, "to_s", notmuch_rb_query_get_string, 
0); /* in query.c */
+rb_define_method (notmuch_rb_cQuery, "add_tag_exclude", 
notmuch_rb_query_add_tag_exclude, 1); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, "search_threads", 
notmuch_rb_query_search_threads, 0); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, "search_messages", 
notmuch_rb_query_search_messages, 0); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, "count_messages", 
notmuch_rb_query_count_messages, 0); /* in query.c */
diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c
index 02b7819..2a80008 100644
--- a/bindings/ruby/query.c
+++ b/bindings/ruby/query.c
@@ -89,6 +89,24 @@ notmuch_rb_query_get_string (VALUE self)
 }

 /*
+ * call-seq: QUERY.add_tag_exclude(tag) => nil
+ *
+ * Add a tag that will be excluded from the query results by default.
+ */
+VALUE
+notmuch_rb_query_add_tag_exclude (VALUE self, VALUE tagv)
+{
+notmuch_query_t *query;
+const char *tag;
+
+Data_Get_Notmuch_Query (self, query);
+tag = RSTRING_PTR(tagv);
+
+notmuch_query_add_tag_exclude(query, tag);
+return Qnil;
+}
+
+/*
  * call-seq: QUERY.search_threads => THREADS
  *
  * Search for threads
-- 
1.7.10.1



[PATCH 1/4] ruby: Add wrapper for notmuch_query_count_messages

2012-05-07 Thread Ali Polatel
---
 bindings/ruby/defs.h  |3 +++
 bindings/ruby/init.c  |3 ++-
 bindings/ruby/query.c |   21 -
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index 81f652f..25222a6 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -222,6 +222,9 @@ notmuch_rb_query_search_threads (VALUE self);
 VALUE
 notmuch_rb_query_search_messages (VALUE self);

+VALUE
+notmuch_rb_query_count_messages (VALUE self);
+
 /* threads.c */
 VALUE
 notmuch_rb_threads_destroy (VALUE self);
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index 4405f19..7ad0ecf 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -1,6 +1,6 @@
 /* The Ruby interface to the notmuch mail library
  *
- * Copyright ? 2010, 2011 Ali Polatel
+ * Copyright ? 2010, 2011, 2012 Ali Polatel
  *
  * 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
@@ -236,6 +236,7 @@ Init_notmuch (void)
 rb_define_method (notmuch_rb_cQuery, "to_s", notmuch_rb_query_get_string, 
0); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, "search_threads", 
notmuch_rb_query_search_threads, 0); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, "search_messages", 
notmuch_rb_query_search_messages, 0); /* in query.c */
+rb_define_method (notmuch_rb_cQuery, "count_messages", 
notmuch_rb_query_count_messages, 0); /* in query.c */

 /*
  * Document-class: Notmuch::Threads
diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c
index 74fd585..02b7819 100644
--- a/bindings/ruby/query.c
+++ b/bindings/ruby/query.c
@@ -1,6 +1,6 @@
 /* The Ruby interface to the notmuch mail library
  *
- * Copyright ? 2010, 2011 Ali Polatel
+ * Copyright ? 2010, 2011, 2012 Ali Polatel
  *
  * 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
@@ -127,3 +127,22 @@ notmuch_rb_query_search_messages (VALUE self)

 return Data_Wrap_Struct (notmuch_rb_cMessages, NULL, NULL, messages);
 }
+
+/*
+ * call-seq: QUERY.count_messages => Fixnum
+ *
+ * Return an estimate of the number of messages matching a search
+ */
+VALUE
+notmuch_rb_query_count_messages (VALUE self)
+{
+notmuch_query_t *query;
+
+Data_Get_Notmuch_Query (self, query);
+
+/* Xapian exceptions are not handled properly.
+ * (function may return 0 after printing a message)
+ * Thus there is nothing we can do here...
+ */
+return UINT2FIX(notmuch_query_count_messages(query));
+}
-- 
1.7.10.1



[PATCH 0/4] ruby: quick update before the freeze!

2012-05-07 Thread Ali Polatel
Hey David,

I've polished the small patch series I had lying around.
I believe I've covered all the lacking API changes.

In addition, the third patch fixes a long-standing bug about the build.

I've decided to send these to you and the list instead of committing right away
in case someone notices any quick errors. Otherwise, please commit these before
the freeze and make rubyists happy.

Ali Polatel (4):
  ruby: Add wrapper for notmuch_query_count_messages
  ruby: Add wrapper for notmuch_query_add_tag_exclude
  ruby: Add workarounds to use in-tree build not the installed one
  ruby: Add wrapper for notmuch_query_set_omit_excluded()

 bindings/ruby/defs.h |   13 +--
 bindings/ruby/extconf.rb |   26 +
 bindings/ruby/init.c |   11 -
 bindings/ruby/query.c|   57 +-
 4 files changed, 99 insertions(+), 8 deletions(-)

-- 
1.7.10.1



[PATCH 0/4] ruby: quick update before the freeze!

2012-05-07 Thread Ali Polatel
Hey David,

I've polished the small patch series I had lying around.
I believe I've covered all the lacking API changes.

In addition, the third patch fixes a long-standing bug about the build.

I've decided to send these to you and the list instead of committing right away
in case someone notices any quick errors. Otherwise, please commit these before
the freeze and make rubyists happy.

Ali Polatel (4):
  ruby: Add wrapper for notmuch_query_count_messages
  ruby: Add wrapper for notmuch_query_add_tag_exclude
  ruby: Add workarounds to use in-tree build not the installed one
  ruby: Add wrapper for notmuch_query_set_omit_excluded()

 bindings/ruby/defs.h |   13 +--
 bindings/ruby/extconf.rb |   26 +
 bindings/ruby/init.c |   11 -
 bindings/ruby/query.c|   57 +-
 4 files changed, 99 insertions(+), 8 deletions(-)

-- 
1.7.10.1

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


[PATCH 1/4] ruby: Add wrapper for notmuch_query_count_messages

2012-05-07 Thread Ali Polatel
---
 bindings/ruby/defs.h  |3 +++
 bindings/ruby/init.c  |3 ++-
 bindings/ruby/query.c |   21 -
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index 81f652f..25222a6 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -222,6 +222,9 @@ notmuch_rb_query_search_threads (VALUE self);
 VALUE
 notmuch_rb_query_search_messages (VALUE self);
 
+VALUE
+notmuch_rb_query_count_messages (VALUE self);
+
 /* threads.c */
 VALUE
 notmuch_rb_threads_destroy (VALUE self);
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index 4405f19..7ad0ecf 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -1,6 +1,6 @@
 /* The Ruby interface to the notmuch mail library
  *
- * Copyright © 2010, 2011 Ali Polatel
+ * Copyright © 2010, 2011, 2012 Ali Polatel
  *
  * 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
@@ -236,6 +236,7 @@ Init_notmuch (void)
 rb_define_method (notmuch_rb_cQuery, to_s, notmuch_rb_query_get_string, 
0); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, search_threads, 
notmuch_rb_query_search_threads, 0); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, search_messages, 
notmuch_rb_query_search_messages, 0); /* in query.c */
+rb_define_method (notmuch_rb_cQuery, count_messages, 
notmuch_rb_query_count_messages, 0); /* in query.c */
 
 /*
  * Document-class: Notmuch::Threads
diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c
index 74fd585..02b7819 100644
--- a/bindings/ruby/query.c
+++ b/bindings/ruby/query.c
@@ -1,6 +1,6 @@
 /* The Ruby interface to the notmuch mail library
  *
- * Copyright © 2010, 2011 Ali Polatel
+ * Copyright © 2010, 2011, 2012 Ali Polatel
  *
  * 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
@@ -127,3 +127,22 @@ notmuch_rb_query_search_messages (VALUE self)
 
 return Data_Wrap_Struct (notmuch_rb_cMessages, NULL, NULL, messages);
 }
+
+/*
+ * call-seq: QUERY.count_messages = Fixnum
+ *
+ * Return an estimate of the number of messages matching a search
+ */
+VALUE
+notmuch_rb_query_count_messages (VALUE self)
+{
+notmuch_query_t *query;
+
+Data_Get_Notmuch_Query (self, query);
+
+/* Xapian exceptions are not handled properly.
+ * (function may return 0 after printing a message)
+ * Thus there is nothing we can do here...
+ */
+return UINT2FIX(notmuch_query_count_messages(query));
+}
-- 
1.7.10.1

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


[PATCH 2/4] ruby: Add wrapper for notmuch_query_add_tag_exclude

2012-05-07 Thread Ali Polatel
---
 bindings/ruby/defs.h  |3 +++
 bindings/ruby/init.c  |1 +
 bindings/ruby/query.c |   18 ++
 3 files changed, 22 insertions(+)

diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index 25222a6..a41cf10 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -217,6 +217,9 @@ VALUE
 notmuch_rb_query_get_string (VALUE self);
 
 VALUE
+notmuch_rb_query_add_tag_exclude (VALUE self, VALUE tagv);
+
+VALUE
 notmuch_rb_query_search_threads (VALUE self);
 
 VALUE
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index 7ad0ecf..edcf101 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -234,6 +234,7 @@ Init_notmuch (void)
 rb_define_method (notmuch_rb_cQuery, sort, notmuch_rb_query_get_sort, 
0); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, sort=, notmuch_rb_query_set_sort, 
1); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, to_s, notmuch_rb_query_get_string, 
0); /* in query.c */
+rb_define_method (notmuch_rb_cQuery, add_tag_exclude, 
notmuch_rb_query_add_tag_exclude, 1); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, search_threads, 
notmuch_rb_query_search_threads, 0); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, search_messages, 
notmuch_rb_query_search_messages, 0); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, count_messages, 
notmuch_rb_query_count_messages, 0); /* in query.c */
diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c
index 02b7819..2a80008 100644
--- a/bindings/ruby/query.c
+++ b/bindings/ruby/query.c
@@ -89,6 +89,24 @@ notmuch_rb_query_get_string (VALUE self)
 }
 
 /*
+ * call-seq: QUERY.add_tag_exclude(tag) = nil
+ *
+ * Add a tag that will be excluded from the query results by default.
+ */
+VALUE
+notmuch_rb_query_add_tag_exclude (VALUE self, VALUE tagv)
+{
+notmuch_query_t *query;
+const char *tag;
+
+Data_Get_Notmuch_Query (self, query);
+tag = RSTRING_PTR(tagv);
+
+notmuch_query_add_tag_exclude(query, tag);
+return Qnil;
+}
+
+/*
  * call-seq: QUERY.search_threads = THREADS
  *
  * Search for threads
-- 
1.7.10.1

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


[PATCH 3/4] ruby: Add workarounds to use in-tree build not the installed one

2012-05-07 Thread Ali Polatel
- Make mkmf use the notmuch.h under ../../lib
- Use libnotmuch.a instead of linking to the installed libnotmuch.so
---
 bindings/ruby/defs.h |4 ++--
 bindings/ruby/extconf.rb |   26 ++
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index a41cf10..6fe5787 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -1,6 +1,6 @@
 /* The Ruby interface to the notmuch mail library
  *
- * Copyright © 2010, 2011 Ali Polatel
+ * Copyright © 2010, 2011, 2012 Ali Polatel
  *
  * 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
@@ -21,8 +21,8 @@
 #ifndef DEFS_H
 #define DEFS_H
 
-#include notmuch.h
 #include ruby.h
+#include notmuch.h
 
 VALUE notmuch_rb_cDatabase;
 VALUE notmuch_rb_cDirectory;
diff --git a/bindings/ruby/extconf.rb b/bindings/ruby/extconf.rb
index ccac609..933f34a 100644
--- a/bindings/ruby/extconf.rb
+++ b/bindings/ruby/extconf.rb
@@ -1,13 +1,31 @@
 #!/usr/bin/env ruby
 # coding: utf-8
-# Copyright 2010, 2011 Ali Polatel a...@exherbo.org
+# Copyright 2010, 2011, 2012 Ali Polatel a...@exherbo.org
 # Distributed under the terms of the GNU General Public License v3
 
 require 'mkmf'
 
-# Notmuch Library
-find_header('notmuch.h', '../../lib')
-find_library('notmuch', 'notmuch_database_create', '../../lib')
+NOTDIR = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
+NOTHDR = File.join(NOTDIR, 'notmuch.h')
+NOTLIB = File.join(NOTDIR, 'libnotmuch.a')
+
+unless File.exists? NOTHDR
+  $stderr.puts notmuch.h is missing under #{NOTDIR}
+  exit 1
+end
+
+unless File.exists? NOTLIB
+  $stderr.puts libnotmuch.a is missing under #{NOTDIR}
+  exit 1
+end
+
+# Small hack to build with in-tree version not the installed one.
+# find_header() and friends use standard include/library paths first.
+$stderr.puts Added -I#{NOTDIR} to $INCFLAGS
+$INCFLAGS = -I#{NOTDIR}.quote +   + $INCFLAGS
+find_header('notmuch.h', NOTDIR)
+
+$LOCAL_LIBS += NOTLIB
 
 # Create Makefile
 dir_config('notmuch')
-- 
1.7.10.1

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


[PATCH 4/4] ruby: Add wrapper for notmuch_query_set_omit_excluded()

2012-05-07 Thread Ali Polatel
---
 bindings/ruby/defs.h  |3 +++
 bindings/ruby/init.c  |7 +++
 bindings/ruby/query.c |   18 ++
 3 files changed, 28 insertions(+)

diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index 6fe5787..85d8205 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -220,6 +220,9 @@ VALUE
 notmuch_rb_query_add_tag_exclude (VALUE self, VALUE tagv);
 
 VALUE
+notmuch_rb_query_set_omit_excluded (VALUE self, VALUE omitv);
+
+VALUE
 notmuch_rb_query_search_threads (VALUE self);
 
 VALUE
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index edcf101..3fe60fb 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -96,6 +96,12 @@ Init_notmuch (void)
  */
 rb_define_const (mod, MESSAGE_FLAG_MATCH, INT2FIX 
(NOTMUCH_MESSAGE_FLAG_MATCH));
 /*
+ * Document-const: Notmuch::MESSAGE_FLAG_EXCLUDED
+ *
+ * Message flag excluded
+ */
+rb_define_const (mod, MESSAGE_FLAG_EXCLUDED, INT2FIX 
(NOTMUCH_MESSAGE_FLAG_EXCLUDED));
+/*
  * Document-const: Notmuch::TAG_MAX
  *
  * Maximum allowed length of a tag
@@ -235,6 +241,7 @@ Init_notmuch (void)
 rb_define_method (notmuch_rb_cQuery, sort=, notmuch_rb_query_set_sort, 
1); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, to_s, notmuch_rb_query_get_string, 
0); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, add_tag_exclude, 
notmuch_rb_query_add_tag_exclude, 1); /* in query.c */
+rb_define_method (notmuch_rb_cQuery, omit_excluded=, 
notmuch_rb_query_set_omit_excluded, 1); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, search_threads, 
notmuch_rb_query_search_threads, 0); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, search_messages, 
notmuch_rb_query_search_messages, 0); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, count_messages, 
notmuch_rb_query_count_messages, 0); /* in query.c */
diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c
index 2a80008..e5ba1b7 100644
--- a/bindings/ruby/query.c
+++ b/bindings/ruby/query.c
@@ -107,6 +107,24 @@ notmuch_rb_query_add_tag_exclude (VALUE self, VALUE tagv)
 }
 
 /*
+ * call-seq: QUERY.omit_excluded=(boolean) = nil
+ *
+ * Specify whether to omit excluded results or simply flag them.
+ * By default, this is set to +true+.
+ */
+VALUE
+notmuch_rb_query_set_omit_excluded (VALUE self, VALUE omitv)
+{
+notmuch_query_t *query;
+
+Data_Get_Notmuch_Query (self, query);
+
+notmuch_query_set_omit_excluded (query, RTEST (omitv));
+
+return Qnil;
+}
+
+/*
  * call-seq: QUERY.search_threads = THREADS
  *
  * Search for threads
-- 
1.7.10.1

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


[PATCH] ruby: make sure the database is closed

2012-04-26 Thread Ali Polatel
2012/4/24 Felipe Contreras :
> On Tue, Apr 24, 2012 at 4:15 AM, Austin Clements  wrote:
>> Quoth Felipe Contreras on Apr 24 at ?3:45 am:
>>> On Tue, Apr 24, 2012 at 2:46 AM, Ali Polatel  wrote:
>>> > 2012/4/24 Felipe Contreras :
>>>
>>> >> Personally I don't see why an object, like say a query would remain
>>> >> working correctly after the database is gone, either by calling
>>> >> .close() directly, or just loosing the pointer to the original object.
>>> >> I don't think users would expect that, or, even if they somehow found
>>> >> it useful, that most likely would be very seldom, and hardly worth
>>> >> worrying about it.
>>> >
>>> > Working correctly is not expected but wouldn't it be more appropriate
>>> > to throw an exception rather than dumping core or printing on standard 
>>> > error?
>>>
>>> Sure, if that was possible.
>>>
>>> > I wonder whether we can make both work somehow.
>>> > Maybe by using talloc explicitly and keeping reference pointers?
>>> > I don't know whether it's worth bothering.
>>>
>>> Maybe, I don't see how, that's just not how C works. Maybe talloc does
>>> have some way to figure out if a pointer has been freed, but I doubt
>>> that, and I can't find it by grepping through the API.
>>>
>>> Another option would be hook into talloc's destructor so we know when
>>> an object is freed and taint it, but then we would be overriding
>>> notmuch's destructor, and there's no way around that (unless we tap
>>> into talloc's internal structures). A way to workaround that would be
>>> to modify notmuch's API so that we can specify a destructor for
>>> notmuch objects, but that would be tedious, and I doubt a lof people
>>> beside us would benefit from that.
>>
>> I believe (though I might be wrong) that bindings could simply
>> maintain their own talloc references to C objects returned by
>> libnotmuch to prevent them from being freed until the wrapper object
>> is garbage collected. ?This would require modifying all of the
>> library's _destroy functions to use talloc_find_parent_bytype and
>> talloc_unlink instead of simply calling talloc_free, but I don't think
>> this change would be particularly invasive and it certainly wouldn't
>> affect the library interface.
>
> That might work, but still, I don't see why this patch can't be applied.

I don't have anything against applying this patch.
If this fix has a kind of urgency -and I doubt it does- please get
someone to push the patch.
Below is my confirmation to accept the consequences:
LGTM

Otherwise, I'd rather we fix it properly most probably using the
method described in Austin's previous mail.

> Cheers.
>
> --
> Felipe Contreras

-alip


Re: [PATCH] ruby: make sure the database is closed

2012-04-25 Thread Ali Polatel
2012/4/24 Felipe Contreras felipe.contre...@gmail.com:
 On Tue, Apr 24, 2012 at 4:15 AM, Austin Clements amdra...@mit.edu wrote:
 Quoth Felipe Contreras on Apr 24 at  3:45 am:
 On Tue, Apr 24, 2012 at 2:46 AM, Ali Polatel a...@exherbo.org wrote:
  2012/4/24 Felipe Contreras felipe.contre...@gmail.com:

  Personally I don't see why an object, like say a query would remain
  working correctly after the database is gone, either by calling
  .close() directly, or just loosing the pointer to the original object.
  I don't think users would expect that, or, even if they somehow found
  it useful, that most likely would be very seldom, and hardly worth
  worrying about it.
 
  Working correctly is not expected but wouldn't it be more appropriate
  to throw an exception rather than dumping core or printing on standard 
  error?

 Sure, if that was possible.

  I wonder whether we can make both work somehow.
  Maybe by using talloc explicitly and keeping reference pointers?
  I don't know whether it's worth bothering.

 Maybe, I don't see how, that's just not how C works. Maybe talloc does
 have some way to figure out if a pointer has been freed, but I doubt
 that, and I can't find it by grepping through the API.

 Another option would be hook into talloc's destructor so we know when
 an object is freed and taint it, but then we would be overriding
 notmuch's destructor, and there's no way around that (unless we tap
 into talloc's internal structures). A way to workaround that would be
 to modify notmuch's API so that we can specify a destructor for
 notmuch objects, but that would be tedious, and I doubt a lof people
 beside us would benefit from that.

 I believe (though I might be wrong) that bindings could simply
 maintain their own talloc references to C objects returned by
 libnotmuch to prevent them from being freed until the wrapper object
 is garbage collected.  This would require modifying all of the
 library's _destroy functions to use talloc_find_parent_bytype and
 talloc_unlink instead of simply calling talloc_free, but I don't think
 this change would be particularly invasive and it certainly wouldn't
 affect the library interface.

 That might work, but still, I don't see why this patch can't be applied.

I don't have anything against applying this patch.
If this fix has a kind of urgency -and I doubt it does- please get
someone to push the patch.
Below is my confirmation to accept the consequences:
LGTM

Otherwise, I'd rather we fix it properly most probably using the
method described in Austin's previous mail.

 Cheers.

 --
 Felipe Contreras

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


[PATCH] ruby: make sure the database is closed

2012-04-24 Thread Ali Polatel
2012/4/24 Felipe Contreras :
> On Mon, Apr 23, 2012 at 11:43 PM, Ali Polatel  wrote:
>> 2012/4/23 Felipe Contreras :
>>> On Mon, Apr 23, 2012 at 5:04 PM, Ali Polatel  wrote:
>>>
>>>> I'd rather not do this.
>>>> Please read: http://comments.gmane.org/gmane.comp.lang.ruby.general/320324
>>>
>>> OK, I've read this.. So?
>>
>> You are one step close to what I thought you had thought.
>
> I don't parse that. I meant that _now_ I've read it.

Sorry, my subconscious likes to barf on emails every now and then.

>>> The order in which Ruby's garbage-collector frees the database and
>>> other objects is irrelevant, because with this patch we are not
>>> manually freeing other objects, only the database.
>>
>> What I wanted was to make all objects "depending" on the database to be 
>> unusable
>> once the database object is freed. Seeing that's not practically easy
>> I decided to leave
>> it to the user.
>
> Well, sure, but if the user has problems, the user can keep the
> database object around.
>
> Personally I don't see why an object, like say a query would remain
> working correctly after the database is gone, either by calling
> .close() directly, or just loosing the pointer to the original object.
> I don't think users would expect that, or, even if they somehow found
> it useful, that most likely would be very seldom, and hardly worth
> worrying about it.

Working correctly is not expected but wouldn't it be more appropriate
to throw an exception rather than dumping core or printing on standard error?

>>> Sure, it's _better_ if the user calls close(), even better if it's
>>> inside an 'ensure', and even better if blocks are used (which I am
>>> using in most cases), but that's not *required*.
>>
>> If you have such a use case, I'm fine with that patch.
>> I might push it in the next few days or get someone else to push it.
>
> I did at some point, not sure if I do now. But that's beside the
> point, the point is that it really does happen.
>
>>> The user might just do:
>>>
>>> def foo
>>> ?db = Notmuch::Database.new($db_name, :mode => Notmuch::MODE_READ_WRITE)
>>> end
>>>
>>> That's perfectly fine in Ruby (although not ideal), since 'db' will
>>> get garbage-collected. But nobody will be able to use the database
>>> again until that process is killed.
>>>
>>> You think that's correct?
>>
>> Yes that is correct. I have not thought about this.
>> I'd say it's a partial misunderstanding on my part due to lack of
>> (and/or too much) vodka.
>
> Well, there's only two options.
>
> a) This works:
>
> ?def foo
> ? ?db = Notmuch::Database.new($db_name, :mode => Notmuch::MODE_READ_WRITE)
> ?end
>
> (as in; the database gets closed eventually)
>
> b) This works:
>
> ?def start_query(search)
> ? ?db = Notmuch::Database.new($db_name)
> ? ?return db.query(search)
> ?end
>
> (as in; the query returned would keep working properly)
>
> I personally don't see why anybody would want b), and if they have
> problems with code like that, I think it's obvious to see why.
>
> I think we should go for a) and thus apply the patch.

I wonder whether we can make both work somehow.
Maybe by using talloc explicitly and keeping reference pointers?
I don't know whether it's worth bothering.

> Cheers.

Cheers

> --
> Felipe Contreras

-alip


[PATCH] ruby: make sure the database is closed

2012-04-23 Thread Ali Polatel
2012/4/23 Felipe Contreras :
> If the Ruby code does not manually close the database, we need to make
> sure it's closed when garbage collected.
>
> In Ruby, users are not _required_ to close, the garbage collector should
> take care of that.
>
> Signed-off-by: Felipe Contreras 
> ---
> ?bindings/ruby/database.c | ? ?8 +++-
> ?1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c
> index 982fd59..7b2ed47 100644
> --- a/bindings/ruby/database.c
> +++ b/bindings/ruby/database.c
> @@ -20,10 +20,16 @@
>
> ?#include "defs.h"
>
> +static void
> +database_free (void *p)
> +{
> + ? ?notmuch_database_close (p);
> +}
> +
> ?VALUE
> ?notmuch_rb_database_alloc (VALUE klass)
> ?{
> - ? ?return Data_Wrap_Struct (klass, NULL, NULL, NULL);
> + ? ?return Data_Wrap_Struct (klass, NULL, database_free, NULL);
> ?}
>
> ?/*
> --
> 1.7.10
>

I'd rather not do this.
Please read: http://comments.gmane.org/gmane.comp.lang.ruby.general/320324

-alip


Re: [PATCH] ruby: make sure the database is closed

2012-04-23 Thread Ali Polatel
2012/4/23 Felipe Contreras felipe.contre...@gmail.com:
 If the Ruby code does not manually close the database, we need to make
 sure it's closed when garbage collected.

 In Ruby, users are not _required_ to close, the garbage collector should
 take care of that.

 Signed-off-by: Felipe Contreras felipe.contre...@gmail.com
 ---
  bindings/ruby/database.c |    8 +++-
  1 file changed, 7 insertions(+), 1 deletion(-)

 diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c
 index 982fd59..7b2ed47 100644
 --- a/bindings/ruby/database.c
 +++ b/bindings/ruby/database.c
 @@ -20,10 +20,16 @@

  #include defs.h

 +static void
 +database_free (void *p)
 +{
 +    notmuch_database_close (p);
 +}
 +
  VALUE
  notmuch_rb_database_alloc (VALUE klass)
  {
 -    return Data_Wrap_Struct (klass, NULL, NULL, NULL);
 +    return Data_Wrap_Struct (klass, NULL, database_free, NULL);
  }

  /*
 --
 1.7.10


I'd rather not do this.
Please read: http://comments.gmane.org/gmane.comp.lang.ruby.general/320324

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


Re: [PATCH] ruby: make sure the database is closed

2012-04-23 Thread Ali Polatel
2012/4/23 Felipe Contreras felipe.contre...@gmail.com:
 On Mon, Apr 23, 2012 at 5:04 PM, Ali Polatel a...@exherbo.org wrote:

 I'd rather not do this.
 Please read: http://comments.gmane.org/gmane.comp.lang.ruby.general/320324

 OK, I've read this.. So?

You are one step close to what I thought you had thought.

 The order in which Ruby's garbage-collector frees the database and
 other objects is irrelevant, because with this patch we are not
 manually freeing other objects, only the database.

What I wanted was to make all objects depending on the database to be unusable
once the database object is freed. Seeing that's not practically easy
I decided to leave
it to the user.

 Sure, it's _better_ if the user calls close(), even better if it's
 inside an 'ensure', and even better if blocks are used (which I am
 using in most cases), but that's not *required*.

If you have such a use case, I'm fine with that patch.
I might push it in the next few days or get someone else to push it.

 The user might just do:

 def foo
  db = Notmuch::Database.new($db_name, :mode = Notmuch::MODE_READ_WRITE)
 end

 That's perfectly fine in Ruby (although not ideal), since 'db' will
 get garbage-collected. But nobody will be able to use the database
 again until that process is killed.

 You think that's correct?

Yes that is correct. I have not thought about this.
I'd say it's a partial misunderstanding on my part due to lack of
(and/or too much) vodka.

 --
 Felipe Contreras

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


Re: [PATCH] ruby: make sure the database is closed

2012-04-23 Thread Ali Polatel
2012/4/24 Felipe Contreras felipe.contre...@gmail.com:
 On Mon, Apr 23, 2012 at 11:43 PM, Ali Polatel a...@exherbo.org wrote:
 2012/4/23 Felipe Contreras felipe.contre...@gmail.com:
 On Mon, Apr 23, 2012 at 5:04 PM, Ali Polatel a...@exherbo.org wrote:

 I'd rather not do this.
 Please read: http://comments.gmane.org/gmane.comp.lang.ruby.general/320324

 OK, I've read this.. So?

 You are one step close to what I thought you had thought.

 I don't parse that. I meant that _now_ I've read it.

Sorry, my subconscious likes to barf on emails every now and then.

 The order in which Ruby's garbage-collector frees the database and
 other objects is irrelevant, because with this patch we are not
 manually freeing other objects, only the database.

 What I wanted was to make all objects depending on the database to be 
 unusable
 once the database object is freed. Seeing that's not practically easy
 I decided to leave
 it to the user.

 Well, sure, but if the user has problems, the user can keep the
 database object around.

 Personally I don't see why an object, like say a query would remain
 working correctly after the database is gone, either by calling
 .close() directly, or just loosing the pointer to the original object.
 I don't think users would expect that, or, even if they somehow found
 it useful, that most likely would be very seldom, and hardly worth
 worrying about it.

Working correctly is not expected but wouldn't it be more appropriate
to throw an exception rather than dumping core or printing on standard error?

 Sure, it's _better_ if the user calls close(), even better if it's
 inside an 'ensure', and even better if blocks are used (which I am
 using in most cases), but that's not *required*.

 If you have such a use case, I'm fine with that patch.
 I might push it in the next few days or get someone else to push it.

 I did at some point, not sure if I do now. But that's beside the
 point, the point is that it really does happen.

 The user might just do:

 def foo
  db = Notmuch::Database.new($db_name, :mode = Notmuch::MODE_READ_WRITE)
 end

 That's perfectly fine in Ruby (although not ideal), since 'db' will
 get garbage-collected. But nobody will be able to use the database
 again until that process is killed.

 You think that's correct?

 Yes that is correct. I have not thought about this.
 I'd say it's a partial misunderstanding on my part due to lack of
 (and/or too much) vodka.

 Well, there's only two options.

 a) This works:

  def foo
    db = Notmuch::Database.new($db_name, :mode = Notmuch::MODE_READ_WRITE)
  end

 (as in; the database gets closed eventually)

 b) This works:

  def start_query(search)
    db = Notmuch::Database.new($db_name)
    return db.query(search)
  end

 (as in; the query returned would keep working properly)

 I personally don't see why anybody would want b), and if they have
 problems with code like that, I think it's obvious to see why.

 I think we should go for a) and thus apply the patch.

I wonder whether we can make both work somehow.
Maybe by using talloc explicitly and keeping reference pointers?
I don't know whether it's worth bothering.

 Cheers.

Cheers

 --
 Felipe Contreras

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


[PATCH 0/3] notmuch-deliver: wait for database to become unlocked and test

2011-11-07 Thread Ali Polatel
On Sun, Nov 06, 2011 at 12:23:01PM +0100, David Riebenbauer wrote:
>Hi,
>
>I noticed that mail would bounce in my setup, if the xapian database
>was locked while notmuch-deliver tried to run.

I recall having this problem sometime ago...

>My solution was to make it wait for some time adn retry. A test
>program for is alos included.

Looks like a workaround more than a solution. What happens if the
database doesn't become available for writing in the meantime?

Quoting from:
http://xapian.org/docs/admin_notes.html#single-writer-multiple-reader

"Xapian enforces this restriction using by having a writer lock the database.
Each Xapian database directory contains a lock file named flintlock (we've kept
the same name as flint used, since the locking technique is the same).

This lock-file will always exist, but will be locked using fcntl() when the
database is open for writing. Because of the semantics of fcntl() locking, for
each WritableDatabase opened we spawn a child process to hold the lock, which
then exec-s cat, so you will see a cat subprocess of any writer process in the
output of ps, top, etc."

See? It's a simple fcntl() lock!

That said, I'm against adding this kind of kludge to notmuch-deliver or
any other tool accessing the database via libnotmuch. Until the issue is
fixed properly I, and I suppose you, can live with a simple shell script
using flock(1) on the file .notmuch/xapian/flintlock.

One possible solution is described by Austin in the mail:
id:AANLkTi=KOx8aTJipkiArFVjEHE6zt_JypoASMiiAWBZ6 at mail.gmail.com
which I quite like.

>Regards,
>David

-alip

>David Riebenbauer (3):
>  notmuch-deliver: wait for the database to become unlocked
>  notmuch-deliver: test wait for database to become available
>  notmuch-deliver: Convert test program to glib main loop.
>
> contrib/notmuch-deliver/.gitignore  |2 +
> contrib/notmuch-deliver/Makefile.am |2 +-
> contrib/notmuch-deliver/configure.ac|1 +
> contrib/notmuch-deliver/src/main.c  |   25 +++-
> contrib/notmuch-deliver/test/Makefile.am|   26 +++
> contrib/notmuch-deliver/test/nm-test.sh |9 +
> contrib/notmuch-deliver/test/nm-testconfig  |   12 ++
> contrib/notmuch-deliver/test/notmuch-lock.c |  226 +++
> contrib/notmuch-deliver/test/testmail   |7 +
> 9 files changed, 306 insertions(+), 4 deletions(-)
> create mode 100644 contrib/notmuch-deliver/test/Makefile.am
> create mode 100755 contrib/notmuch-deliver/test/nm-test.sh
> create mode 100644 contrib/notmuch-deliver/test/nm-testconfig
> create mode 100644 contrib/notmuch-deliver/test/notmuch-lock.c
> create mode 100644 contrib/notmuch-deliver/test/testmail
>
>-- 
>1.7.7.1
>
>___
>notmuch mailing list
>notmuch at notmuchmail.org
>http://notmuchmail.org/mailman/listinfo/notmuch
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: 



[PATCH 1/2] notmuch-deliver: Retry with readwrite if splice() fails

2011-11-06 Thread Ali Polatel
Hey, David

Thanks for resending the patches!

On Sun, Nov 06, 2011 at 06:34:27AM +0100, David Riebenbauer wrote:
>notmuch-deliver should not just fail, when splice() doesn't work. Fall
>back to the readwrite method even if NOTMUCH_DELIVER_NO_SPLICE is not
>set.

This is a trivial change but I'm rather curious about the reasoning.
Did you have a problem with splice() not working?

>---
> contrib/notmuch-deliver/src/main.c |   10 +++---
> 1 files changed, 7 insertions(+), 3 deletions(-)
>
>diff --git a/contrib/notmuch-deliver/src/main.c 
>b/contrib/notmuch-deliver/src/main.c
>index f7a4eaa..8423d91 100644
>--- a/contrib/notmuch-deliver/src/main.c
>+++ b/contrib/notmuch-deliver/src/main.c
>@@ -252,9 +252,13 @@ save_maildir(int fdin, const char *dir, int auto_create, 
>char **path)
>
>   g_debug("Reading from standard input and writing to `%s'", 
> info.tmpname);
> #ifdef HAVE_SPLICE
>-  ret = g_getenv("NOTMUCH_DELIVER_NO_SPLICE")
>-  ? save_readwrite(fdin, fdout)
>-  : save_splice(fdin, fdout);
>+  if (g_getenv("NOTMUCH_DELIVER_NO_SPLICE"))
>+  ret = save_readwrite(fdin, fdout);
>+  else {
>+  ret = save_splice(fdin, fdout);
>+  if (ret)
>+  ret = save_readwrite(fdin, fdout);
>+  }

I'm inclined to think this retry should be user configurable as well.
How about we remove NOTMUCH_DELIVER_NO_SPLICE environment variable and
add a command line flag like --save-method which may have the following
invocations:

--save-method=readwritecalls save_readwrite()
--save-method=splice   calls save_splice()
--save-method=readwrite,splice try save_readwrite() and then splice()
--save-method=splice,readwrite try save_splice and then readwrite()

The second invocation should fail in case splice is not available. Also
adding an environment variable like NOTMUCH_DELIVER_SAVE_METHOD so
people can stick it into their dotfiles is a good idea.

Thoughts?

-alip

> #else
>   ret = save_readwrite(fdin, fdout);
> #endif /* HAVE_SPLICE */
>-- 
>1.7.7.1
>


Re: [PATCH 1/2] notmuch-deliver: Retry with readwrite if splice() fails

2011-11-06 Thread Ali Polatel

Hey, David

Thanks for resending the patches!

On Sun, Nov 06, 2011 at 06:34:27AM +0100, David Riebenbauer wrote:

notmuch-deliver should not just fail, when splice() doesn't work. Fall
back to the readwrite method even if NOTMUCH_DELIVER_NO_SPLICE is not
set.


This is a trivial change but I'm rather curious about the reasoning.
Did you have a problem with splice() not working?


---
contrib/notmuch-deliver/src/main.c |   10 +++---
1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/contrib/notmuch-deliver/src/main.c 
b/contrib/notmuch-deliver/src/main.c
index f7a4eaa..8423d91 100644
--- a/contrib/notmuch-deliver/src/main.c
+++ b/contrib/notmuch-deliver/src/main.c
@@ -252,9 +252,13 @@ save_maildir(int fdin, const char *dir, int auto_create, 
char **path)

g_debug(Reading from standard input and writing to `%s', 
info.tmpname);
#ifdef HAVE_SPLICE
-   ret = g_getenv(NOTMUCH_DELIVER_NO_SPLICE)
-   ? save_readwrite(fdin, fdout)
-   : save_splice(fdin, fdout);
+   if (g_getenv(NOTMUCH_DELIVER_NO_SPLICE))
+   ret = save_readwrite(fdin, fdout);
+   else {
+   ret = save_splice(fdin, fdout);
+   if (ret)
+   ret = save_readwrite(fdin, fdout);
+   }


I'm inclined to think this retry should be user configurable as well.
How about we remove NOTMUCH_DELIVER_NO_SPLICE environment variable and
add a command line flag like --save-method which may have the following
invocations:

--save-method=readwritecalls save_readwrite()
--save-method=splice   calls save_splice()
--save-method=readwrite,splice try save_readwrite() and then splice()
--save-method=splice,readwrite try save_splice and then readwrite()

The second invocation should fail in case splice is not available. Also
adding an environment variable like NOTMUCH_DELIVER_SAVE_METHOD so
people can stick it into their dotfiles is a good idea.

Thoughts?

-alip


#else
ret = save_readwrite(fdin, fdout);
#endif /* HAVE_SPLICE */
--
1.7.7.1


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


Re: [PATCH 0/3] notmuch-deliver: wait for database to become unlocked and test

2011-11-06 Thread Ali Polatel

On Sun, Nov 06, 2011 at 12:23:01PM +0100, David Riebenbauer wrote:

Hi,

I noticed that mail would bounce in my setup, if the xapian database
was locked while notmuch-deliver tried to run.


I recall having this problem sometime ago...


My solution was to make it wait for some time adn retry. A test
program for is alos included.


Looks like a workaround more than a solution. What happens if the
database doesn't become available for writing in the meantime?

Quoting from:
http://xapian.org/docs/admin_notes.html#single-writer-multiple-reader

Xapian enforces this restriction using by having a writer lock the database.
Each Xapian database directory contains a lock file named flintlock (we've kept
the same name as flint used, since the locking technique is the same).

This lock-file will always exist, but will be locked using fcntl() when the
database is open for writing. Because of the semantics of fcntl() locking, for
each WritableDatabase opened we spawn a child process to hold the lock, which
then exec-s cat, so you will see a cat subprocess of any writer process in the
output of ps, top, etc.

See? It's a simple fcntl() lock!

That said, I'm against adding this kind of kludge to notmuch-deliver or
any other tool accessing the database via libnotmuch. Until the issue is
fixed properly I, and I suppose you, can live with a simple shell script
using flock(1) on the file .notmuch/xapian/flintlock.

One possible solution is described by Austin in the mail:
id:AANLkTi=kox8atjipkiarfvjehe6zt_jypoasmiiaw...@mail.gmail.com
which I quite like.


Regards,
David


-alip


David Riebenbauer (3):
 notmuch-deliver: wait for the database to become unlocked
 notmuch-deliver: test wait for database to become available
 notmuch-deliver: Convert test program to glib main loop.

contrib/notmuch-deliver/.gitignore  |2 +
contrib/notmuch-deliver/Makefile.am |2 +-
contrib/notmuch-deliver/configure.ac|1 +
contrib/notmuch-deliver/src/main.c  |   25 +++-
contrib/notmuch-deliver/test/Makefile.am|   26 +++
contrib/notmuch-deliver/test/nm-test.sh |9 +
contrib/notmuch-deliver/test/nm-testconfig  |   12 ++
contrib/notmuch-deliver/test/notmuch-lock.c |  226 +++
contrib/notmuch-deliver/test/testmail   |7 +
9 files changed, 306 insertions(+), 4 deletions(-)
create mode 100644 contrib/notmuch-deliver/test/Makefile.am
create mode 100755 contrib/notmuch-deliver/test/nm-test.sh
create mode 100644 contrib/notmuch-deliver/test/nm-testconfig
create mode 100644 contrib/notmuch-deliver/test/notmuch-lock.c
create mode 100644 contrib/notmuch-deliver/test/testmail

--
1.7.7.1

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


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


notmuch-deliver under contrib/

2011-11-05 Thread Ali Polatel
Hello,

I have just moved the notmuch-deliver repository to main notmuch
repository under contrib/notmuch-deliver/.

David, please send your github pull requests as patches to the mailing
list for discussion. I have a few comments on them before I can apply.

Personal Note: Below is the script I have written to move the
repository. Just to make sure it does not get lost:

#!/bin/sh

set -e
set -x

mkdir -p contrib/notmuch-deliver
git filter-branch \
 --msg-filter \
 'sed -e "1s/^\([^(Merge)]\)/notmuch-deliver: \1/"' \
 --index-filter \
 'git ls-files -s | sed "s~\t\"*~/notmuch-deliver/~" |
 GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
 git update-index --index-info &&
  mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD

cd ../notmuch
git pull "$OLDPWD"
git pull --rebase

-alip


notmuch-deliver under contrib/

2011-11-04 Thread Ali Polatel

Hello,

I have just moved the notmuch-deliver repository to main notmuch
repository under contrib/notmuch-deliver/.

David, please send your github pull requests as patches to the mailing
list for discussion. I have a few comments on them before I can apply.

Personal Note: Below is the script I have written to move the
repository. Just to make sure it does not get lost:

#!/bin/sh

set -e
set -x

mkdir -p contrib/notmuch-deliver
git filter-branch \
--msg-filter \
'sed -e 1s/^\([^(Merge)]\)/notmuch-deliver: \1/' \
--index-filter \
'git ls-files -s | sed s~\t\*~contrib/notmuch-deliver/~ |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info 
 mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD

cd ../notmuch
git pull $OLDPWD
git pull --rebase

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


set test prereqs (Emacs, GDB, GPG) v4

2011-11-01 Thread Ali Polatel
On Tue, Nov 01, 2011 at 08:49:10PM +0100, Pieter Praet wrote:
>Rebased to current master.
>
>Previous version:
>  id:"1307016220-17509-1-git-send-email-pieter at praet.org"
>
>Discussion:
>  id:"1317660447-27520-1-git-send-email-schnouki at schnouki.net"
>

Thanks for the nice work!
I want to share one thing which came up to my mind during reading
through them. Since we require bash for tests, we might go for using
bash's builtin 'type -P foo' instead of 'which foo'. Not that it's
important, just wondered "why not?"

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



Re: set test prereqs (Emacs, GDB, GPG) v4

2011-11-01 Thread Ali Polatel

On Tue, Nov 01, 2011 at 08:49:10PM +0100, Pieter Praet wrote:

Rebased to current master.

Previous version:
 id:1307016220-17509-1-git-send-email-pie...@praet.org

Discussion:
 id:1317660447-27520-1-git-send-email-schno...@schnouki.net



Thanks for the nice work!
I want to share one thing which came up to my mind during reading
through them. Since we require bash for tests, we might go for using
bash's builtin 'type -P foo' instead of 'which foo'. Not that it's
important, just wondered why not?

-alip


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


Re: [PATCH] contrib/nmbug: new script for sharing tags with prefix notmuch::

2011-10-29 Thread Ali Polatel

On Sat, Oct 29, 2011 at 01:45:07PM -0300, David Bremner wrote:

From: David Bremner brem...@debian.org

In this initial version, we take care of only the base import and
export of the appropriate tags in line oriented format amenable to
easy merging.

The current plan to use git to share tags and resolve conflicts.
---
contrib/nmbug |   69 +
1 files changed, 69 insertions(+), 0 deletions(-)
create mode 100755 contrib/nmbug

diff --git a/contrib/nmbug b/contrib/nmbug
new file mode 100755
index 000..e9d1b14
--- /dev/null
+++ b/contrib/nmbug
@@ -0,0 +1,69 @@
+#!/bin/bash


^^ I'd make that:
#!/usr/bin/env bash
for systems where bash is not the default shell.


+# Copyright (c) 2011 David Bremner
+# License: same as notmuch
+
+NMHOME=${HOME}/.nmbug
+
+NMTAGS=($(notmuch search --output=tags *|grep ^notmuch::))
+
+function dump() {
+notmuch dump -- $(printf   tag:%s ${NMTAGS[*]}) |\
+while read  -r msgid rest
+do
+   outfile=$NMHOME/tags/$(echo $msgid | sha1sum - | cut -f1 -d' ')
+   echo $outfile
+   printf msg-id: %s\n $msgid  $outfile
+   tmp=${rest#\(}
+   read -r -a tags ${tmp%\)};
+   for tag in ${tags[@]}; do
+   case $tag in
+   notmuch::*)
+   echo tag: $tag  $outfile
+   ;;
+   *)
+   # nothing
+   esac
+   done
+done
+
+}
+
+function cat_file() {
+tags=
+id=
+cat $1 |\
+while read -r what data
+do
+   case $what in
+   msg-id:)
+   printf %s ( $data
+   ;;
+   tag:)
+   printf %s  $data
+   ;;
+   *)
+   echo Syntax error $what
+   exit 1
+   esac
+done
+echo )
+}
+
+function restore() {
+find $NMHOME/tags -type f |\
+while read -r filename
+do
+   cat_file $filename
+done | notmuch restore --match=notmuch::
+}
+case $1 in
+dump)
+   dump
+   ;;
+restore)
+   restore
+   ;;
+*)
+   echo unknown command $1;
+esac
+
--
1.7.6.3

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


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


Re: [PATCH] contrib/nmbug: new script for sharing tags with prefix notmuch::

2011-10-29 Thread Ali Polatel

On Sat, Oct 29, 2011 at 07:12:52PM -0300, David Bremner wrote:

On Sun, 30 Oct 2011 00:11:35 +0300, Ali Polatel pola...@gmail.com wrote:

^^ I'd make that:
#!/usr/bin/env bash
for systems where bash is not the default shell.



OK, I'll do that in the next version. I always forget about those people
who install bash in funny places.


Cool!
Just to note, it's the standards, not the people, which are funny...


d


-alip


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


[python] set rpath in setup.cfg

2011-10-12 Thread Ali Polatel
On Wed, Oct 12, 2011 at 04:55:30PM +0200, dtk wrote:
>
>Hey guys,
>
>I installed notmuch locally (~/.local) and now the python bindings fail to
>find the .so.
>
>Anyone happens to know how to set the rpath in the setup.cfg? Putting it
>in the [build] section doesn't work:
>
>~~~snip~~~
>$ python setup.py install --prefix=$STOW/notmuch_python
>running install
>error: error in setup.cfg: command 'build' has no such option 'rpath'
>$
>~~~snip~~~
>
>Putting it in [build_ext] works but neither that nor building with
>
>~~~snip~~~
>$ python setup.py build_ext --rpath=/home/dtk/.local/lib
>running build_ext
>$ python setup.py install --prefix=$STOW/notmuch_python/
>running install
>running build
>running build_py
>copying notmuch/database.py -> build/lib.linux-x86_64-2.7/notmuch
>copying notmuch/thread.py -> build/lib.linux-x86_64-2.7/notmuch
>copying notmuch/tag.py -> build/lib.linux-x86_64-2.7/notmuch
>copying notmuch/globals.py -> build/lib.linux-x86_64-2.7/notmuch
>copying notmuch/version.py -> build/lib.linux-x86_64-2.7/notmuch
>copying notmuch/message.py -> build/lib.linux-x86_64-2.7/notmuch
>copying notmuch/filename.py -> build/lib.linux-x86_64-2.7/notmuch
>copying notmuch/__init__.py -> build/lib.linux-x86_64-2.7/notmuch
>running install_lib
>running install_egg_info
>Removing
>/home/dtk/.local/stow/notmuch_python//lib/python2.7/site-packages/notmuch-0.9_rc2-py2.7.egg-info
>Writing
>/home/dtk/.local/stow/notmuch_python//lib/python2.7/site-packages/notmuch-0.9_rc2-py2.7.egg-info
>$
>~~~snip~~~
>
>seems to have any effect.
>
>Am I missing out on something? Would be great if someone happened to know
>a solution.
>/me dislikes LD_LIBRARY_PATH :/
>

May I ask why you dislike LD_LIBRARY_PATH?

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



Re: [python] set rpath in setup.cfg

2011-10-12 Thread Ali Polatel

On Wed, Oct 12, 2011 at 04:55:30PM +0200, dtk wrote:


Hey guys,

I installed notmuch locally (~/.local) and now the python bindings fail to
find the .so.

Anyone happens to know how to set the rpath in the setup.cfg? Putting it
in the [build] section doesn't work:

~~~snip~~~
$ python setup.py install --prefix=$STOW/notmuch_python
running install
error: error in setup.cfg: command 'build' has no such option 'rpath'
$
~~~snip~~~

Putting it in [build_ext] works but neither that nor building with

~~~snip~~~
$ python setup.py build_ext --rpath=/home/dtk/.local/lib
running build_ext
$ python setup.py install --prefix=$STOW/notmuch_python/
running install
running build
running build_py
copying notmuch/database.py - build/lib.linux-x86_64-2.7/notmuch
copying notmuch/thread.py - build/lib.linux-x86_64-2.7/notmuch
copying notmuch/tag.py - build/lib.linux-x86_64-2.7/notmuch
copying notmuch/globals.py - build/lib.linux-x86_64-2.7/notmuch
copying notmuch/version.py - build/lib.linux-x86_64-2.7/notmuch
copying notmuch/message.py - build/lib.linux-x86_64-2.7/notmuch
copying notmuch/filename.py - build/lib.linux-x86_64-2.7/notmuch
copying notmuch/__init__.py - build/lib.linux-x86_64-2.7/notmuch
running install_lib
running install_egg_info
Removing
/home/dtk/.local/stow/notmuch_python//lib/python2.7/site-packages/notmuch-0.9_rc2-py2.7.egg-info
Writing
/home/dtk/.local/stow/notmuch_python//lib/python2.7/site-packages/notmuch-0.9_rc2-py2.7.egg-info
$
~~~snip~~~

seems to have any effect.

Am I missing out on something? Would be great if someone happened to know
a solution.
/me dislikes LD_LIBRARY_PATH :/



May I ask why you dislike LD_LIBRARY_PATH?

-alip


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


[PATCH v3 2/2] lib: make find_message{,by_filename) report errors

2011-10-04 Thread Ali Polatel
From: Ali Polatel <a...@exherbo.org>

Previously, the functions notmuch_database_find_message() and
notmuch_database_find_message_by_filename() functions did not properly
report error condition to the library user.

For more information, read the thread on the notmuch mailing list
starting with my mail "id:871uv2unfd.fsf at gmail.com"

Make these functions accept a pointer to 'notmuch_message_t' as argument
and return notmuch_status_t which may be used to check for any error
condition.

restore: Modify for the new notmuch_database_find_message()
new: Modify for the new notmuch_database_find_message_by_filename()
---
 lib/database.cc   |   96 -
 lib/message.cc|8 +++--
 lib/notmuch.h |   58 ++--
 notmuch-new.c |4 ++-
 notmuch-restore.c |   11 --
 5 files changed, 120 insertions(+), 57 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index d43e114..e77fd53 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -360,13 +360,17 @@ _message_id_compressed (void *ctx, const char *message_id)
 return compressed;
 }

-notmuch_message_t *
+notmuch_status_t
 notmuch_database_find_message (notmuch_database_t *notmuch,
-  const char *message_id)
+  const char *message_id,
+  notmuch_message_t **message_ret)
 {
 notmuch_private_status_t status;
 unsigned int doc_id;

+if (message_ret == NULL)
+   return NOTMUCH_STATUS_NULL_POINTER;
+
 if (strlen (message_id) > NOTMUCH_MESSAGE_ID_MAX)
message_id = _message_id_compressed (notmuch, message_id);

@@ -375,14 +379,21 @@ notmuch_database_find_message (notmuch_database_t 
*notmuch,
   message_id, _id);

if (status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND)
-   return NULL;
+   *message_ret = NULL;
+   else {
+   *message_ret = _notmuch_message_create (notmuch, notmuch, doc_id,
+   NULL);
+   if (*message_ret == NULL)
+   return NOTMUCH_STATUS_OUT_OF_MEMORY;
+   }

-   return _notmuch_message_create (notmuch, notmuch, doc_id, NULL);
+   return NOTMUCH_STATUS_SUCCESS;
 } catch (const Xapian::Error ) {
fprintf (stderr, "A Xapian exception occurred finding message: %s.\n",
 error.get_msg().c_str());
notmuch->exception_reported = TRUE;
-   return NULL;
+   *message_ret = NULL;
+   return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
 }
 }

@@ -1311,7 +1322,9 @@ _get_metadata_thread_id_key (void *ctx, const char 
*message_id)

 /* Find the thread ID to which the message with 'message_id' belongs.
  *
- * Always returns a newly talloced string belonging to 'ctx'.
+ * Note: 'thread_id_ret' must not be NULL!
+ * On success '*thread_id_ret' is set to a newly talloced string belonging to
+ * 'ctx'.
  *
  * Note: If there is no message in the database with the given
  * 'message_id' then a new thread_id will be allocated for this
@@ -1319,25 +1332,30 @@ _get_metadata_thread_id_key (void *ctx, const char 
*message_id)
  * thread ID can be looked up if the message is added to the database
  * later).
  */
-static const char *
+static notmuch_status_t
 _resolve_message_id_to_thread_id (notmuch_database_t *notmuch,
  void *ctx,
- const char *message_id)
+ const char *message_id,
+ const char **thread_id_ret)
 {
+notmuch_status_t status;
 notmuch_message_t *message;
 string thread_id_string;
-const char *thread_id;
 char *metadata_key;
 Xapian::WritableDatabase *db;

-message = notmuch_database_find_message (notmuch, message_id);
+status = notmuch_database_find_message (notmuch, message_id, );
+
+if (status)
+   return status;

 if (message) {
-   thread_id = talloc_steal (ctx, notmuch_message_get_thread_id (message));
+   *thread_id_ret = talloc_steal (ctx,
+  notmuch_message_get_thread_id (message));

notmuch_message_destroy (message);

-   return thread_id;
+   return NOTMUCH_STATUS_SUCCESS;
 }

 /* Message has not been seen yet.
@@ -1351,15 +1369,16 @@ _resolve_message_id_to_thread_id (notmuch_database_t 
*notmuch,
 thread_id_string = notmuch->xapian_db->get_metadata (metadata_key);

 if (thread_id_string.empty()) {
-   thread_id = _notmuch_database_generate_thread_id (notmuch);
-   db->set_metadata (metadata_key, thread_id);
+   *thread_id_ret = talloc_strdup (ctx,
+   _notmuch_database_generate_thread_id 
(notmuch));
+   db->set_metadata (metadata_key, *thread_id_ret);
 } else {
-   thread_id = thre

[PATCH v3 1/2] lib: destroy message object after message removal

2011-10-04 Thread Ali Polatel
From: Ali Polatel <a...@exherbo.org>

notmuch_database_remove_message() must call notmuch_message_destroy()
once it is done handling message removal.
---
 lib/database.cc |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 9299c8d..d43e114 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1769,6 +1769,8 @@ notmuch_database_remove_message (notmuch_database_t 
*notmuch,
_notmuch_message_delete (message);
else if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
_notmuch_message_sync (message);
+
+   notmuch_message_destroy (message);
 }

 return status;
-- 
1.7.6.1



[PATCH v3 0/2] Better error handling

2011-10-04 Thread Ali Polatel
From: Ali Polatel <a...@exherbo.org>

New set of patches addressing the issues in the mail
"id:8739f9muhp.fsf at zancas.localnet"

You may also find the commits in my notmuch repository:
git://github.com/alip/notmuch.git branch: find_message-v3

Ali Polatel (2):
  lib: destroy message object after message removal
  lib: make find_message{,by_filename) report errors

 lib/database.cc   |   98 -
 lib/message.cc|8 +++--
 lib/notmuch.h |   58 +--
 notmuch-new.c |4 ++-
 notmuch-restore.c |   11 --
 5 files changed, 122 insertions(+), 57 deletions(-)

-- 
1.7.6.1



[PATCH] lib: make find_message{,by_filename) report errors

2011-10-04 Thread Ali Polatel
David Bremner yazm??:
>On Sat,  1 Oct 2011 11:12:23 +0300, Ali Polatel  wrote:
>> From: Ali Polatel 
>>
>> Looks like the patch did not make it correctly the first time.
>> Resending using git-send-email?
>>
>> You may also find the commit in my notmuch repository:
>> git://github.com/alip/notmuch.git branch: find_message
>
>
>Hi Ali;
>
>Thanks for reworking this patch. I looked at branch find_message-v2
>in your repo. I have a few comments.

Thanks for going over the patch, expect a new set of patches soon!

>- In the comments for _resolve_message_id_to_thread_id I guess thread_id
>  should be thread_id_ret?

Fixed.

>- in notmuch_database_find_message_by_file_name, I'm not sure why you
>  set status to NOTMUCH_STATUS_OUT_OF_MEMORY in the catch block. Is this
>  a typo?

Looks like a copy & paste error. I must have blindly copied the error
from the previous block. Fixed.

>- after the DONE: label of the same routine, how is *message_ret destroyed?
>  does it need to wait until the talloc context "notmuch" is freed?

Yes, I have modified it to call notmuch_message_destroy() in case
'*message_ret' is non-NULL after the DONE:

>- I don't really get the change of user to caller around notmuch.h:286
>  It is not a big deal, but I guess we should try to be consistent.

I don't get what you mean by consistency here but this hunk is unrelated
to the problem which the patch is trying to address.
Reverted.

>David
>
>

 -alip
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20111004/940ff67d/attachment.pgp>


[RFC/PATCH] notmuch link

2011-10-04 Thread Ali Polatel
Ali Polatel yazm??:
>From: Ali Polatel 
>
>Hello,
>
>I have been working on a new notmuch command namely 'link'. This command
>aims to help integrating notmuch with different mail agents. Basically
>it (sym)links messages matching the given search terms to the specified
>target maildir. You may use this maildir as a so-called "virtual"
>folder. After applying the patch call "notmuch help link" for basic
>help.
>
>The patch is also available on links branch under my notmuch repository:
>https://github.com/alip/notmuch
>
>Beware this is pretty experimental, I have been using it for a couple of
>days fixing the issues along the way. I will be sharing my workflow
>using this command with mutt after I'm done polishing my scripts.
>
>This mail is merely a request for comments and testing.

Sigh...
I have just noticed "notmuch show" learned --format=mbox which makes
this patch rather pointless for me. This changeset will keep living
under my notmuch repository possibly without receiving any updates.

>Ali Polatel (1):
>  link: Add new command
>
> Makefile.local   |2 +
> maildir.c|  262 +
> maildir.h|   53 +
> notmuch-client.h |4 +
> notmuch-link.c   |  339 ++
> notmuch.c|   44 +++
> 6 files changed, 704 insertions(+), 0 deletions(-)
> create mode 100644 maildir.c
> create mode 100644 maildir.h
> create mode 100644 notmuch-link.c
>
>-- 
>1.7.6.1
>


 -alip
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20111004/61e0610f/attachment.pgp>


[PATCH v2 0/2] Better error handling

2011-10-04 Thread Ali Polatel
Ali Polatel yazm??:
>From: Ali Polatel 
>
>New set of patches addressing the issues in the mail
>"id:20111003174308.GD17905 at mit.edu"

You may also find the commits in my notmuch repository:
git://github.com/alip/notmuch.git branch: find_message-v2

>Ali Polatel (2):
>  lib: destroy message object after message removal
>  lib: make find_message{,by_filename) report errors
>
> lib/database.cc   |   95 +++-
> lib/message.cc|8 +++--
> lib/notmuch.h |   60 +++--
> notmuch-new.c |4 ++-
> notmuch-restore.c |   11 --
> 5 files changed, 120 insertions(+), 58 deletions(-)
>
>-- 
>1.7.6.1
>


 -alip
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20111003/2962a317/attachment-0001.pgp>


[PATCH v2 2/2] lib: make find_message{,by_filename) report errors

2011-10-04 Thread Ali Polatel
From: Ali Polatel <a...@exherbo.org>

Previously, the functions notmuch_database_find_message() and
notmuch_database_find_message_by_filename() functions did not properly
report error condition to the library user.

For more information, read the thread on the notmuch mailing list
starting with my mail "id:871uv2unfd.fsf at gmail.com"

Make these functions accept a pointer to 'notmuch_message_t' as argument
and return notmuch_status_t which may be used to check for any error
condition.

restore: Modify for the new notmuch_database_find_message()
new: Modify for the new notmuch_database_find_message_by_filename()
---
 lib/database.cc   |   93 +++-
 lib/message.cc|8 +++--
 lib/notmuch.h |   60 +++---
 notmuch-new.c |4 ++-
 notmuch-restore.c |   11 --
 5 files changed, 118 insertions(+), 58 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index d43e114..cf0cc8a 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -360,13 +360,17 @@ _message_id_compressed (void *ctx, const char *message_id)
 return compressed;
 }

-notmuch_message_t *
+notmuch_status_t
 notmuch_database_find_message (notmuch_database_t *notmuch,
-  const char *message_id)
+  const char *message_id,
+  notmuch_message_t **message_ret)
 {
 notmuch_private_status_t status;
 unsigned int doc_id;

+if (message_ret == NULL)
+   return NOTMUCH_STATUS_NULL_POINTER;
+
 if (strlen (message_id) > NOTMUCH_MESSAGE_ID_MAX)
message_id = _message_id_compressed (notmuch, message_id);

@@ -375,14 +379,21 @@ notmuch_database_find_message (notmuch_database_t 
*notmuch,
   message_id, _id);

if (status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND)
-   return NULL;
+   *message_ret = NULL;
+   else {
+   *message_ret = _notmuch_message_create (notmuch, notmuch, doc_id,
+   NULL);
+   if (*message_ret == NULL)
+   return NOTMUCH_STATUS_OUT_OF_MEMORY;
+   }

-   return _notmuch_message_create (notmuch, notmuch, doc_id, NULL);
+   return NOTMUCH_STATUS_SUCCESS;
 } catch (const Xapian::Error ) {
fprintf (stderr, "A Xapian exception occurred finding message: %s.\n",
 error.get_msg().c_str());
notmuch->exception_reported = TRUE;
-   return NULL;
+   *message_ret = NULL;
+   return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
 }
 }

@@ -1311,7 +1322,8 @@ _get_metadata_thread_id_key (void *ctx, const char 
*message_id)

 /* Find the thread ID to which the message with 'message_id' belongs.
  *
- * Always returns a newly talloced string belonging to 'ctx'.
+ * Note: 'thread_id' must not be NULL!
+ * On success '*thread_id' is set to a newly talloced string belonging to 
'ctx'.
  *
  * Note: If there is no message in the database with the given
  * 'message_id' then a new thread_id will be allocated for this
@@ -1319,25 +1331,30 @@ _get_metadata_thread_id_key (void *ctx, const char 
*message_id)
  * thread ID can be looked up if the message is added to the database
  * later).
  */
-static const char *
+static notmuch_status_t
 _resolve_message_id_to_thread_id (notmuch_database_t *notmuch,
  void *ctx,
- const char *message_id)
+ const char *message_id,
+ const char **thread_id_ret)
 {
+notmuch_status_t status;
 notmuch_message_t *message;
 string thread_id_string;
-const char *thread_id;
 char *metadata_key;
 Xapian::WritableDatabase *db;

-message = notmuch_database_find_message (notmuch, message_id);
+status = notmuch_database_find_message (notmuch, message_id, );
+
+if (status)
+   return status;

 if (message) {
-   thread_id = talloc_steal (ctx, notmuch_message_get_thread_id (message));
+   *thread_id_ret = talloc_steal (ctx,
+  notmuch_message_get_thread_id (message));

notmuch_message_destroy (message);

-   return thread_id;
+   return NOTMUCH_STATUS_SUCCESS;
 }

 /* Message has not been seen yet.
@@ -1351,15 +1368,16 @@ _resolve_message_id_to_thread_id (notmuch_database_t 
*notmuch,
 thread_id_string = notmuch->xapian_db->get_metadata (metadata_key);

 if (thread_id_string.empty()) {
-   thread_id = _notmuch_database_generate_thread_id (notmuch);
-   db->set_metadata (metadata_key, thread_id);
+   *thread_id_ret = talloc_strdup (ctx,
+   _notmuch_database_generate_thread_id 
(notmuch));
+   db->set_metadata (metadata_key, *thread_id_ret);
 } else {
-   thread_id = thread_id_string.c_str();

[PATCH v2 1/2] lib: destroy message object after message removal

2011-10-04 Thread Ali Polatel
From: Ali Polatel <a...@exherbo.org>

notmuch_database_remove_message() must call notmuch_message_destroy()
once it is done handling message removal.
---
 lib/database.cc |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 9299c8d..d43e114 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1769,6 +1769,8 @@ notmuch_database_remove_message (notmuch_database_t 
*notmuch,
_notmuch_message_delete (message);
else if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
_notmuch_message_sync (message);
+
+   notmuch_message_destroy (message);
 }

 return status;
-- 
1.7.6.1



[PATCH v1 1/1] lib: make find_message{, by_filename) report errors

2011-10-04 Thread Ali Polatel
Austin Clements yazm??:
>All of the code looks good to me (and improving error handling is
>always a good thing).  Some style nits are inline below.

Thanks for the review, comments below and a new set of patches follow...

>The changes to _resolve_message_id_to_thread_id and
>_notmuch_database_link_message_to_parents seem like just plain better
>error handling and unrelated to the find_message API changes.  Perhaps
>these should be in a separate patch?

I don't think this is wise considering the fact that the prototypes of
the functions change. Separating this into two patches will leave the
state of the tree broken between the two patches which is bad for
git-bisect. In addition, considering the small size and compactness of
the patch, I don't think it's worth the effort.

>Quoth Ali Polatel on Oct 03 at  7:49 pm:
>> Previously, the functions notmuch_database_find_message() and
>> notmuch_database_find_message_by_filename() functions did not properly
>> report error condition to the library user.
>>
>> For more information, read the thread on the notmuch mailing list
>> starting with my mail "id:871uv2unfd.fsf at gmail.com"
>>
>> Make these functions accept a pointer to 'notmuch_message_t' as argument
>> and return notmuch_status_t which may be used to check for any error
>> condition.
>>
>> restore: Modify for the new notmuch_database_find_message()
>> new: Modify for the new notmuch_database_find_message_by_filename()
>> ---
>>  lib/database.cc   |   90 
>> ++--
>>  lib/message.cc|6 ++--
>>  lib/notmuch.h |   61 +--
>>  notmuch-new.c |4 ++-
>>  notmuch-restore.c |   11 --
>>  5 files changed, 115 insertions(+), 57 deletions(-)
>>
>> diff --git a/lib/database.cc b/lib/database.cc
>> index 9299c8d..1705232 100644
>> --- a/lib/database.cc
>> +++ b/lib/database.cc
>> @@ -360,13 +360,17 @@ _message_id_compressed (void *ctx, const char 
>> *message_id)
>>  return compressed;
>>  }
>>
>> -notmuch_message_t *
>> +notmuch_status_t
>>  notmuch_database_find_message (notmuch_database_t *notmuch,
>> -   const char *message_id)
>> +   const char *message_id,
>> +   notmuch_message_t **message)
>
>Perhaps this should be message_ret to clearly distinguish it as an
>out-argument?

This crossed my mind while working on the initial patch but I guess I
was just being lazy. Fixed.

>>  {
>>  notmuch_private_status_t status;
>>  unsigned int doc_id;
>>
>> +if (message == NULL)
>> +return NOTMUCH_STATUS_NULL_POINTER;
>> +
>>  if (strlen (message_id) > NOTMUCH_MESSAGE_ID_MAX)
>>  message_id = _message_id_compressed (notmuch, message_id);
>>
>> @@ -375,14 +379,21 @@ notmuch_database_find_message (notmuch_database_t 
>> *notmuch,
>> message_id, _id);
>>
>>  if (status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND)
>> -return NULL;
>> +*message = NULL;
>> +else {
>> +*message = _notmuch_message_create (notmuch, notmuch, doc_id,
>> +NULL);
>> +if (*message == NULL)
>> +return NOTMUCH_STATUS_OUT_OF_MEMORY;
>> +}
>>
>> -return _notmuch_message_create (notmuch, notmuch, doc_id, NULL);
>> +return NOTMUCH_STATUS_SUCCESS;
>>  } catch (const Xapian::Error ) {
>>  fprintf (stderr, "A Xapian exception occurred finding message: %s.\n",
>>   error.get_msg().c_str());
>>  notmuch->exception_reported = TRUE;
>> -return NULL;
>> +*message = NULL;
>> +return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
>>  }
>>  }
>>
>> @@ -1311,7 +1322,8 @@ _get_metadata_thread_id_key (void *ctx, const char 
>> *message_id)
>>
>>  /* Find the thread ID to which the message with 'message_id' belongs.
>>   *
>> - * Always returns a newly talloced string belonging to 'ctx'.
>> + * Note: 'thread_id' must not be NULL!
>> + * On success '*thread_id' is set to a newly talloced string belonging to 
>> 'ctx'.
>>   *
>>   * Note: If there is no message in the database with the given
>>   * 'message_id' then a new thread_id will be allocated for this
>> @@ -1319,25 +1331,29 @@ _get_metadata_thread_id_key (void *ctx, const char 
>> *message_id)
>>   * thread ID can be looked up if the message is added to

Re: [PATCH v1 1/1] lib: make find_message{, by_filename) report errors

2011-10-04 Thread Ali Polatel

Austin Clements yazmış:

All of the code looks good to me (and improving error handling is
always a good thing).  Some style nits are inline below.


Thanks for the review, comments below and a new set of patches follow...


The changes to _resolve_message_id_to_thread_id and
_notmuch_database_link_message_to_parents seem like just plain better
error handling and unrelated to the find_message API changes.  Perhaps
these should be in a separate patch?


I don't think this is wise considering the fact that the prototypes of
the functions change. Separating this into two patches will leave the
state of the tree broken between the two patches which is bad for
git-bisect. In addition, considering the small size and compactness of
the patch, I don't think it's worth the effort.


Quoth Ali Polatel on Oct 03 at  7:49 pm:

Previously, the functions notmuch_database_find_message() and
notmuch_database_find_message_by_filename() functions did not properly
report error condition to the library user.

For more information, read the thread on the notmuch mailing list
starting with my mail id:871uv2unfd@gmail.com

Make these functions accept a pointer to 'notmuch_message_t' as argument
and return notmuch_status_t which may be used to check for any error
condition.

restore: Modify for the new notmuch_database_find_message()
new: Modify for the new notmuch_database_find_message_by_filename()
---
 lib/database.cc   |   90 ++--
 lib/message.cc|6 ++--
 lib/notmuch.h |   61 +--
 notmuch-new.c |4 ++-
 notmuch-restore.c |   11 --
 5 files changed, 115 insertions(+), 57 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 9299c8d..1705232 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -360,13 +360,17 @@ _message_id_compressed (void *ctx, const char *message_id)
 return compressed;
 }

-notmuch_message_t *
+notmuch_status_t
 notmuch_database_find_message (notmuch_database_t *notmuch,
-  const char *message_id)
+  const char *message_id,
+  notmuch_message_t **message)


Perhaps this should be message_ret to clearly distinguish it as an
out-argument?


This crossed my mind while working on the initial patch but I guess I
was just being lazy. Fixed.


 {
 notmuch_private_status_t status;
 unsigned int doc_id;

+if (message == NULL)
+   return NOTMUCH_STATUS_NULL_POINTER;
+
 if (strlen (message_id)  NOTMUCH_MESSAGE_ID_MAX)
message_id = _message_id_compressed (notmuch, message_id);

@@ -375,14 +379,21 @@ notmuch_database_find_message (notmuch_database_t 
*notmuch,
   message_id, doc_id);

if (status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND)
-   return NULL;
+   *message = NULL;
+   else {
+   *message = _notmuch_message_create (notmuch, notmuch, doc_id,
+   NULL);
+   if (*message == NULL)
+   return NOTMUCH_STATUS_OUT_OF_MEMORY;
+   }

-   return _notmuch_message_create (notmuch, notmuch, doc_id, NULL);
+   return NOTMUCH_STATUS_SUCCESS;
 } catch (const Xapian::Error error) {
fprintf (stderr, A Xapian exception occurred finding message: %s.\n,
 error.get_msg().c_str());
notmuch-exception_reported = TRUE;
-   return NULL;
+   *message = NULL;
+   return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
 }
 }

@@ -1311,7 +1322,8 @@ _get_metadata_thread_id_key (void *ctx, const char 
*message_id)

 /* Find the thread ID to which the message with 'message_id' belongs.
  *
- * Always returns a newly talloced string belonging to 'ctx'.
+ * Note: 'thread_id' must not be NULL!
+ * On success '*thread_id' is set to a newly talloced string belonging to 
'ctx'.
  *
  * Note: If there is no message in the database with the given
  * 'message_id' then a new thread_id will be allocated for this
@@ -1319,25 +1331,29 @@ _get_metadata_thread_id_key (void *ctx, const char 
*message_id)
  * thread ID can be looked up if the message is added to the database
  * later).
  */
-static const char *
+static notmuch_status_t
 _resolve_message_id_to_thread_id (notmuch_database_t *notmuch,
  void *ctx,
- const char *message_id)
+ const char *message_id,
+ const char **thread_id)


thread_id_ret?


Same as above, fixed.




 {
+notmuch_status_t status;
 notmuch_message_t *message;
 string thread_id_string;
-const char *thread_id;
 char *metadata_key;
 Xapian::WritableDatabase *db;

-message = notmuch_database_find_message (notmuch, message_id);
+status = notmuch_database_find_message (notmuch, message_id, message);
+
+if (status)
+   return status

[PATCH v2 0/2] Better error handling

2011-10-04 Thread Ali Polatel
From: Ali Polatel a...@exherbo.org

New set of patches addressing the issues in the mail
id:20111003174308.gd17...@mit.edu

Ali Polatel (2):
  lib: destroy message object after message removal
  lib: make find_message{,by_filename) report errors

 lib/database.cc   |   95 +++-
 lib/message.cc|8 +++--
 lib/notmuch.h |   60 +++--
 notmuch-new.c |4 ++-
 notmuch-restore.c |   11 --
 5 files changed, 120 insertions(+), 58 deletions(-)

-- 
1.7.6.1

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


[PATCH v2 1/2] lib: destroy message object after message removal

2011-10-04 Thread Ali Polatel
From: Ali Polatel a...@exherbo.org

notmuch_database_remove_message() must call notmuch_message_destroy()
once it is done handling message removal.
---
 lib/database.cc |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 9299c8d..d43e114 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1769,6 +1769,8 @@ notmuch_database_remove_message (notmuch_database_t 
*notmuch,
_notmuch_message_delete (message);
else if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
_notmuch_message_sync (message);
+
+   notmuch_message_destroy (message);
 }
 
 return status;
-- 
1.7.6.1

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


Re: [PATCH v2 0/2] Better error handling

2011-10-04 Thread Ali Polatel

Ali Polatel yazmış:

From: Ali Polatel a...@exherbo.org

New set of patches addressing the issues in the mail
id:20111003174308.gd17...@mit.edu


You may also find the commits in my notmuch repository:
git://github.com/alip/notmuch.git branch: find_message-v2


Ali Polatel (2):
 lib: destroy message object after message removal
 lib: make find_message{,by_filename) report errors

lib/database.cc   |   95 +++-
lib/message.cc|8 +++--
lib/notmuch.h |   60 +++--
notmuch-new.c |4 ++-
notmuch-restore.c |   11 --
5 files changed, 120 insertions(+), 58 deletions(-)

--
1.7.6.1




-alip


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


Re: [RFC/PATCH] notmuch link

2011-10-04 Thread Ali Polatel

Ali Polatel yazmış:

From: Ali Polatel a...@exherbo.org

Hello,

I have been working on a new notmuch command namely 'link'. This command
aims to help integrating notmuch with different mail agents. Basically
it (sym)links messages matching the given search terms to the specified
target maildir. You may use this maildir as a so-called virtual
folder. After applying the patch call notmuch help link for basic
help.

The patch is also available on links branch under my notmuch repository:
https://github.com/alip/notmuch

Beware this is pretty experimental, I have been using it for a couple of
days fixing the issues along the way. I will be sharing my workflow
using this command with mutt after I'm done polishing my scripts.

This mail is merely a request for comments and testing.


Sigh...
I have just noticed notmuch show learned --format=mbox which makes
this patch rather pointless for me. This changeset will keep living
under my notmuch repository possibly without receiving any updates.


Ali Polatel (1):
 link: Add new command

Makefile.local   |2 +
maildir.c|  262 +
maildir.h|   53 +
notmuch-client.h |4 +
notmuch-link.c   |  339 ++
notmuch.c|   44 +++
6 files changed, 704 insertions(+), 0 deletions(-)
create mode 100644 maildir.c
create mode 100644 maildir.h
create mode 100644 notmuch-link.c

--
1.7.6.1




-alip


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


Re: [PATCH] lib: make find_message{,by_filename) report errors

2011-10-04 Thread Ali Polatel

David Bremner yazmış:

On Sat,  1 Oct 2011 11:12:23 +0300, Ali Polatel pola...@gmail.com wrote:

From: Ali Polatel a...@exherbo.org

Looks like the patch did not make it correctly the first time.
Resending using git-send-email™

You may also find the commit in my notmuch repository:
git://github.com/alip/notmuch.git branch: find_message



Hi Ali;

Thanks for reworking this patch. I looked at branch find_message-v2
in your repo. I have a few comments.


Thanks for going over the patch, expect a new set of patches soon!


- In the comments for _resolve_message_id_to_thread_id I guess thread_id
 should be thread_id_ret?


Fixed.


- in notmuch_database_find_message_by_file_name, I'm not sure why you
 set status to NOTMUCH_STATUS_OUT_OF_MEMORY in the catch block. Is this
 a typo?


Looks like a copy  paste error. I must have blindly copied the error
from the previous block. Fixed.


- after the DONE: label of the same routine, how is *message_ret destroyed?
 does it need to wait until the talloc context notmuch is freed?


Yes, I have modified it to call notmuch_message_destroy() in case
'*message_ret' is non-NULL after the DONE:


- I don't really get the change of user to caller around notmuch.h:286
 It is not a big deal, but I guess we should try to be consistent.


I don't get what you mean by consistency here but this hunk is unrelated
to the problem which the patch is trying to address.
Reverted.


David




-alip


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


[PATCH v3 0/2] Better error handling

2011-10-04 Thread Ali Polatel
From: Ali Polatel a...@exherbo.org

New set of patches addressing the issues in the mail
id:8739f9muhp.fsf@zancas.localnet

You may also find the commits in my notmuch repository:
git://github.com/alip/notmuch.git branch: find_message-v3

Ali Polatel (2):
  lib: destroy message object after message removal
  lib: make find_message{,by_filename) report errors

 lib/database.cc   |   98 -
 lib/message.cc|8 +++--
 lib/notmuch.h |   58 +--
 notmuch-new.c |4 ++-
 notmuch-restore.c |   11 --
 5 files changed, 122 insertions(+), 57 deletions(-)

-- 
1.7.6.1

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


[PATCH v3 1/2] lib: destroy message object after message removal

2011-10-04 Thread Ali Polatel
From: Ali Polatel a...@exherbo.org

notmuch_database_remove_message() must call notmuch_message_destroy()
once it is done handling message removal.
---
 lib/database.cc |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 9299c8d..d43e114 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1769,6 +1769,8 @@ notmuch_database_remove_message (notmuch_database_t 
*notmuch,
_notmuch_message_delete (message);
else if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
_notmuch_message_sync (message);
+
+   notmuch_message_destroy (message);
 }
 
 return status;
-- 
1.7.6.1

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


[PATCH v3 2/2] lib: make find_message{,by_filename) report errors

2011-10-04 Thread Ali Polatel
From: Ali Polatel a...@exherbo.org

Previously, the functions notmuch_database_find_message() and
notmuch_database_find_message_by_filename() functions did not properly
report error condition to the library user.

For more information, read the thread on the notmuch mailing list
starting with my mail id:871uv2unfd@gmail.com

Make these functions accept a pointer to 'notmuch_message_t' as argument
and return notmuch_status_t which may be used to check for any error
condition.

restore: Modify for the new notmuch_database_find_message()
new: Modify for the new notmuch_database_find_message_by_filename()
---
 lib/database.cc   |   96 -
 lib/message.cc|8 +++--
 lib/notmuch.h |   58 ++--
 notmuch-new.c |4 ++-
 notmuch-restore.c |   11 --
 5 files changed, 120 insertions(+), 57 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index d43e114..e77fd53 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -360,13 +360,17 @@ _message_id_compressed (void *ctx, const char *message_id)
 return compressed;
 }
 
-notmuch_message_t *
+notmuch_status_t
 notmuch_database_find_message (notmuch_database_t *notmuch,
-  const char *message_id)
+  const char *message_id,
+  notmuch_message_t **message_ret)
 {
 notmuch_private_status_t status;
 unsigned int doc_id;
 
+if (message_ret == NULL)
+   return NOTMUCH_STATUS_NULL_POINTER;
+
 if (strlen (message_id)  NOTMUCH_MESSAGE_ID_MAX)
message_id = _message_id_compressed (notmuch, message_id);
 
@@ -375,14 +379,21 @@ notmuch_database_find_message (notmuch_database_t 
*notmuch,
   message_id, doc_id);
 
if (status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND)
-   return NULL;
+   *message_ret = NULL;
+   else {
+   *message_ret = _notmuch_message_create (notmuch, notmuch, doc_id,
+   NULL);
+   if (*message_ret == NULL)
+   return NOTMUCH_STATUS_OUT_OF_MEMORY;
+   }
 
-   return _notmuch_message_create (notmuch, notmuch, doc_id, NULL);
+   return NOTMUCH_STATUS_SUCCESS;
 } catch (const Xapian::Error error) {
fprintf (stderr, A Xapian exception occurred finding message: %s.\n,
 error.get_msg().c_str());
notmuch-exception_reported = TRUE;
-   return NULL;
+   *message_ret = NULL;
+   return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
 }
 }
 
@@ -1311,7 +1322,9 @@ _get_metadata_thread_id_key (void *ctx, const char 
*message_id)
 
 /* Find the thread ID to which the message with 'message_id' belongs.
  *
- * Always returns a newly talloced string belonging to 'ctx'.
+ * Note: 'thread_id_ret' must not be NULL!
+ * On success '*thread_id_ret' is set to a newly talloced string belonging to
+ * 'ctx'.
  *
  * Note: If there is no message in the database with the given
  * 'message_id' then a new thread_id will be allocated for this
@@ -1319,25 +1332,30 @@ _get_metadata_thread_id_key (void *ctx, const char 
*message_id)
  * thread ID can be looked up if the message is added to the database
  * later).
  */
-static const char *
+static notmuch_status_t
 _resolve_message_id_to_thread_id (notmuch_database_t *notmuch,
  void *ctx,
- const char *message_id)
+ const char *message_id,
+ const char **thread_id_ret)
 {
+notmuch_status_t status;
 notmuch_message_t *message;
 string thread_id_string;
-const char *thread_id;
 char *metadata_key;
 Xapian::WritableDatabase *db;
 
-message = notmuch_database_find_message (notmuch, message_id);
+status = notmuch_database_find_message (notmuch, message_id, message);
+
+if (status)
+   return status;
 
 if (message) {
-   thread_id = talloc_steal (ctx, notmuch_message_get_thread_id (message));
+   *thread_id_ret = talloc_steal (ctx,
+  notmuch_message_get_thread_id (message));
 
notmuch_message_destroy (message);
 
-   return thread_id;
+   return NOTMUCH_STATUS_SUCCESS;
 }
 
 /* Message has not been seen yet.
@@ -1351,15 +1369,16 @@ _resolve_message_id_to_thread_id (notmuch_database_t 
*notmuch,
 thread_id_string = notmuch-xapian_db-get_metadata (metadata_key);
 
 if (thread_id_string.empty()) {
-   thread_id = _notmuch_database_generate_thread_id (notmuch);
-   db-set_metadata (metadata_key, thread_id);
+   *thread_id_ret = talloc_strdup (ctx,
+   _notmuch_database_generate_thread_id 
(notmuch));
+   db-set_metadata (metadata_key, *thread_id_ret);
 } else {
-   thread_id = thread_id_string.c_str();
+   *thread_id_ret

[PATCH v1 0/1] lib: make find_message{,by_filename) report errors

2011-10-04 Thread Ali Polatel
Here is an updated patch fixing style issues addressed by amdragon on
IRC. I plan to submit a patch documenting how to configure VIM to code
using notmuch's style guidelines as well.

You may also find the commit in my notmuch repository:
git://github.com/alip/notmuch.git branch: find_message-v1

Ali Polatel (1):
  lib: make find_message{,by_filename) report errors

 lib/database.cc   |   90 ++--
 lib/message.cc|6 ++--
 lib/notmuch.h |   61 +--
 notmuch-new.c |4 ++-
 notmuch-restore.c |   11 --
 5 files changed, 115 insertions(+), 57 deletions(-)

-- 
1.7.6.1

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


[PATCH v1 1/1] lib: make find_message{,by_filename) report errors

2011-10-03 Thread Ali Polatel
Previously, the functions notmuch_database_find_message() and
notmuch_database_find_message_by_filename() functions did not properly
report error condition to the library user.

For more information, read the thread on the notmuch mailing list
starting with my mail "id:871uv2unfd.fsf at gmail.com"

Make these functions accept a pointer to 'notmuch_message_t' as argument
and return notmuch_status_t which may be used to check for any error
condition.

restore: Modify for the new notmuch_database_find_message()
new: Modify for the new notmuch_database_find_message_by_filename()
---
 lib/database.cc   |   90 ++--
 lib/message.cc|6 ++--
 lib/notmuch.h |   61 +--
 notmuch-new.c |4 ++-
 notmuch-restore.c |   11 --
 5 files changed, 115 insertions(+), 57 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 9299c8d..1705232 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -360,13 +360,17 @@ _message_id_compressed (void *ctx, const char *message_id)
 return compressed;
 }

-notmuch_message_t *
+notmuch_status_t
 notmuch_database_find_message (notmuch_database_t *notmuch,
-  const char *message_id)
+  const char *message_id,
+  notmuch_message_t **message)
 {
 notmuch_private_status_t status;
 unsigned int doc_id;

+if (message == NULL)
+   return NOTMUCH_STATUS_NULL_POINTER;
+
 if (strlen (message_id) > NOTMUCH_MESSAGE_ID_MAX)
message_id = _message_id_compressed (notmuch, message_id);

@@ -375,14 +379,21 @@ notmuch_database_find_message (notmuch_database_t 
*notmuch,
   message_id, _id);

if (status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND)
-   return NULL;
+   *message = NULL;
+   else {
+   *message = _notmuch_message_create (notmuch, notmuch, doc_id,
+   NULL);
+   if (*message == NULL)
+   return NOTMUCH_STATUS_OUT_OF_MEMORY;
+   }

-   return _notmuch_message_create (notmuch, notmuch, doc_id, NULL);
+   return NOTMUCH_STATUS_SUCCESS;
 } catch (const Xapian::Error ) {
fprintf (stderr, "A Xapian exception occurred finding message: %s.\n",
 error.get_msg().c_str());
notmuch->exception_reported = TRUE;
-   return NULL;
+   *message = NULL;
+   return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
 }
 }

@@ -1311,7 +1322,8 @@ _get_metadata_thread_id_key (void *ctx, const char 
*message_id)

 /* Find the thread ID to which the message with 'message_id' belongs.
  *
- * Always returns a newly talloced string belonging to 'ctx'.
+ * Note: 'thread_id' must not be NULL!
+ * On success '*thread_id' is set to a newly talloced string belonging to 
'ctx'.
  *
  * Note: If there is no message in the database with the given
  * 'message_id' then a new thread_id will be allocated for this
@@ -1319,25 +1331,29 @@ _get_metadata_thread_id_key (void *ctx, const char 
*message_id)
  * thread ID can be looked up if the message is added to the database
  * later).
  */
-static const char *
+static notmuch_status_t
 _resolve_message_id_to_thread_id (notmuch_database_t *notmuch,
  void *ctx,
- const char *message_id)
+ const char *message_id,
+ const char **thread_id)
 {
+notmuch_status_t status;
 notmuch_message_t *message;
 string thread_id_string;
-const char *thread_id;
 char *metadata_key;
 Xapian::WritableDatabase *db;

-message = notmuch_database_find_message (notmuch, message_id);
+status = notmuch_database_find_message (notmuch, message_id, );
+
+if (status)
+   return status;

 if (message) {
-   thread_id = talloc_steal (ctx, notmuch_message_get_thread_id (message));
+   *thread_id = talloc_steal (ctx, notmuch_message_get_thread_id 
(message));

notmuch_message_destroy (message);

-   return thread_id;
+   return NOTMUCH_STATUS_SUCCESS;
 }

 /* Message has not been seen yet.
@@ -1351,15 +1367,15 @@ _resolve_message_id_to_thread_id (notmuch_database_t 
*notmuch,
 thread_id_string = notmuch->xapian_db->get_metadata (metadata_key);

 if (thread_id_string.empty()) {
-   thread_id = _notmuch_database_generate_thread_id (notmuch);
-   db->set_metadata (metadata_key, thread_id);
+   *thread_id = talloc_strdup (ctx, _notmuch_database_generate_thread_id 
(notmuch));
+   db->set_metadata (metadata_key, *thread_id);
 } else {
-   thread_id = thread_id_string.c_str();
+   *thread_id = talloc_strdup(ctx, thread_id_string.c_str());
 }

 talloc_free (metadata_key);

-return talloc_strdup (ctx, thread_id);
+return NOTMUCH_STATUS_SUCCESS;
 }

 static 

[PATCH v1 0/1] lib: make find_message{,by_filename) report errors

2011-10-03 Thread Ali Polatel
Here is an updated patch fixing style issues addressed by amdragon on
IRC. I plan to submit a patch documenting how to configure VIM to code
using notmuch's style guidelines as well.

You may also find the commit in my notmuch repository:
git://github.com/alip/notmuch.git branch: find_message-v1

Ali Polatel (1):
  lib: make find_message{,by_filename) report errors

 lib/database.cc   |   90 ++--
 lib/message.cc|6 ++--
 lib/notmuch.h |   61 +--
 notmuch-new.c |4 ++-
 notmuch-restore.c |   11 --
 5 files changed, 115 insertions(+), 57 deletions(-)

-- 
1.7.6.1



[RFC/PATCH] link: Add new command

2011-10-01 Thread Ali Polatel
From: Ali Polatel <a...@exherbo.org>

'link' is a new command to create links to specified target maildirs.
This is especially useful for integration with other mail agents.
---
 Makefile.local   |2 +
 maildir.c|  262 +
 maildir.h|   53 +
 notmuch-client.h |4 +
 notmuch-link.c   |  339 ++
 notmuch.c|   44 +++
 6 files changed, 704 insertions(+), 0 deletions(-)
 create mode 100644 maildir.c
 create mode 100644 maildir.h
 create mode 100644 notmuch-link.c

diff --git a/Makefile.local b/Makefile.local
index 38f6c17..a613a4b 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -278,6 +278,7 @@ notmuch_client_srcs =   \
notmuch-config.c\
notmuch-count.c \
notmuch-dump.c  \
+   notmuch-link.c  \
notmuch-new.c   \
notmuch-reply.c \
notmuch-restore.c   \
@@ -289,6 +290,7 @@ notmuch_client_srcs =   \
query-string.c  \
show-message.c  \
json.c  \
+   maildir.c   \
xutil.c

 notmuch_client_modules = $(notmuch_client_srcs:.c=.o)
diff --git a/maildir.c b/maildir.c
new file mode 100644
index 000..b8c48b3
--- /dev/null
+++ b/maildir.c
@@ -0,0 +1,262 @@
+/* Maildir utilities for the notmuch mail library
+ *
+ * Copyright ? 2011 Ali Polatel
+ * Based in part upon mu which is:
+ *   Copyright ? 2008-2011 Dirk-Jan C. Binnema 
+ *
+ * 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/ .
+ *
+ * Author: Ali Polatel 
+ */
+
+#include "maildir.h"
+
+static const char *const maildir_subdirs_array[] = {"new", "cur", "tmp"};
+
+/* FIXME: The two functions below, dirent_sort_inode and get_dtype duplicate
+ * code from notmuch-new.c
+ */
+static int
+dirent_sort_inode (const struct dirent **a, const struct dirent **b)
+{
+return ((*a)->d_ino < (*b)->d_ino) ? -1 : 1;
+}
+
+static unsigned char
+get_dtype(const char *fullpath, struct dirent *entry)
+{
+struct stat buf;
+
+if (entry->d_type != DT_UNKNOWN)
+   return entry->d_type;
+
+if (lstat(fullpath, ) == -1) {
+   fprintf (stderr, "Warning: stat failed on `%s': %s\n",
+fullpath, strerror(errno));
+   return DT_UNKNOWN;
+}
+
+if (S_ISREG (buf.st_mode)) {
+   return DT_REG;
+} else if (S_ISDIR (buf.st_mode)) {
+   return DT_DIR;
+} else if (S_ISLNK (buf.st_mode)) {
+   return DT_LNK;
+}
+
+return DT_UNKNOWN;
+}
+
+static notmuch_bool_t
+maildir_access (const char *path)
+{
+struct stat buf;
+
+if (access (path, R_OK | W_OK | X_OK) == -1) {
+   fprintf (stderr, "Failed to access path `%s': %s\n",
+path, strerror(errno));
+   return FALSE;
+}
+
+if (lstat(path, ) == -1) {
+   fprintf (stderr, "Failed to access path `%s': %s\n",
+path, strerror(errno));
+   return FALSE;
+}
+
+if (!S_ISDIR(buf.st_mode)) {
+   fprintf (stderr, "Path `%s' is not a directory\n", path);
+   return FALSE;
+}
+
+return TRUE;
+}
+
+/* Determine whether the source message is in 'new' or in 'cur';
+ * we ignore messages in 'tmp' for obvious reasons
+ */
+static notmuch_bool_t
+maildir_subdir (const char *src, notmuch_bool_t *in_cur)
+{
+char *srcpath;
+
+srcpath = g_path_get_dirname (src);
+
+if (g_str_has_suffix (srcpath, "new"))
+   *in_cur = FALSE;
+else if (g_str_has_suffix (srcpath, "cur"))
+   *in_cur = TRUE;
+else {
+   g_free (srcpath);
+   errno = EINVAL;
+   return FALSE;
+}
+
+g_free(srcpath);
+return TRUE;
+}
+
+static char *
+maildir_transform_path (const char *src, const char *targetpath)
+{
+char *targetfullpath, *srcfile;
+notmuch_bool_t in_cur;
+
+if (!maildir_subdir (src, _cur)) {
+   fprintf (stderr, "Invalid maildir subdirectory `%s': %s\n",
+src, strerror(errno));
+   return NULL;
+}
+
+srcfile = g_path_get_basename (src);
+targetfullpath = g_strdup_printf ("%s%c%s%c%s",
+ targetpath,
+

[RFC/PATCH] notmuch link

2011-10-01 Thread Ali Polatel
From: Ali Polatel <a...@exherbo.org>

Hello,

I have been working on a new notmuch command namely 'link'. This command
aims to help integrating notmuch with different mail agents. Basically
it (sym)links messages matching the given search terms to the specified
target maildir. You may use this maildir as a so-called "virtual"
folder. After applying the patch call "notmuch help link" for basic
help.

The patch is also available on links branch under my notmuch repository:
https://github.com/alip/notmuch

Beware this is pretty experimental, I have been using it for a couple of
days fixing the issues along the way. I will be sharing my workflow
using this command with mutt after I'm done polishing my scripts.

This mail is merely a request for comments and testing.

Ali Polatel (1):
  link: Add new command

 Makefile.local   |2 +
 maildir.c|  262 +
 maildir.h|   53 +
 notmuch-client.h |4 +
 notmuch-link.c   |  339 ++
 notmuch.c|   44 +++
 6 files changed, 704 insertions(+), 0 deletions(-)
 create mode 100644 maildir.c
 create mode 100644 maildir.h
 create mode 100644 notmuch-link.c

-- 
1.7.6.1



[PATCH] lib: make find_message{,by_filename) report errors

2011-10-01 Thread Ali Polatel
From: Ali Polatel <a...@exherbo.org>

Looks like the patch did not make it correctly the first time.
Resending using git-send-email?

You may also find the commit in my notmuch repository:
git://github.com/alip/notmuch.git branch: find_message

Ali Polatel (1):
  lib: make find_message{,by_filename) report errors

 lib/database.cc   |   89 ++--
 lib/message.cc|6 ++--
 lib/notmuch.h |   61 +---
 notmuch-new.c |4 ++-
 notmuch-restore.c |   11 --
 5 files changed, 114 insertions(+), 57 deletions(-)

-- 
1.7.6.1



[PATCH] lib: make find_message{,by_filename) report errors

2011-10-01 Thread Ali Polatel
From: Ali Polatel a...@exherbo.org

Looks like the patch did not make it correctly the first time.
Resending using git-send-email™

You may also find the commit in my notmuch repository:
git://github.com/alip/notmuch.git branch: find_message

Ali Polatel (1):
  lib: make find_message{,by_filename) report errors

 lib/database.cc   |   89 ++--
 lib/message.cc|6 ++--
 lib/notmuch.h |   61 +---
 notmuch-new.c |4 ++-
 notmuch-restore.c |   11 --
 5 files changed, 114 insertions(+), 57 deletions(-)

-- 
1.7.6.1

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


[PATCH] lib: make find_message{,by_filename) report errors

2011-10-01 Thread Ali Polatel
Previously, the functions notmuch_database_find_message() and
notmuch_database_find_message_by_filename() functions did not properly
report error condition to the library user.

For more information, read the thread on the notmuch mailing list
starting with my mail id:871uv2unfd@gmail.com

Make these functions accept a pointer to 'notmuch_message_t' as argument
and return notmuch_status_t which may be used to check for any error
condition.

restore: Modify for the new notmuch_database_find_message()
new: Modify for the new notmuch_database_find_message_by_filename()
---
 lib/database.cc   |   89 ++--
 lib/message.cc|6 ++--
 lib/notmuch.h |   61 +---
 notmuch-new.c |4 ++-
 notmuch-restore.c |   11 --
 5 files changed, 114 insertions(+), 57 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 9299c8d..6641aa5 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -360,13 +360,17 @@ _message_id_compressed (void *ctx, const char *message_id)
 return compressed;
 }
 
-notmuch_message_t *
+notmuch_status_t
 notmuch_database_find_message (notmuch_database_t *notmuch,
-  const char *message_id)
+  const char *message_id,
+  notmuch_message_t **message)
 {
 notmuch_private_status_t status;
 unsigned int doc_id;
 
+if (message == NULL)
+   return NOTMUCH_STATUS_NULL_POINTER;
+
 if (strlen (message_id)  NOTMUCH_MESSAGE_ID_MAX)
message_id = _message_id_compressed (notmuch, message_id);
 
@@ -375,14 +379,20 @@ notmuch_database_find_message (notmuch_database_t 
*notmuch,
   message_id, doc_id);
 
if (status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND)
-   return NULL;
+   *message = NULL;
+   else {
+   *message = _notmuch_message_create (notmuch, notmuch, doc_id, NULL);
+   if (*message == NULL)
+   return NOTMUCH_STATUS_OUT_OF_MEMORY;
+   }
 
-   return _notmuch_message_create (notmuch, notmuch, doc_id, NULL);
+   return NOTMUCH_STATUS_SUCCESS;
 } catch (const Xapian::Error error) {
fprintf (stderr, A Xapian exception occurred finding message: %s.\n,
 error.get_msg().c_str());
notmuch-exception_reported = TRUE;
-   return NULL;
+   *message = NULL;
+   return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
 }
 }
 
@@ -1311,7 +1321,8 @@ _get_metadata_thread_id_key (void *ctx, const char 
*message_id)
 
 /* Find the thread ID to which the message with 'message_id' belongs.
  *
- * Always returns a newly talloced string belonging to 'ctx'.
+ * Note: 'thread_id' must not be NULL!
+ * On success '*thread_id' is set to a newly talloced string belonging to 
'ctx'.
  *
  * Note: If there is no message in the database with the given
  * 'message_id' then a new thread_id will be allocated for this
@@ -1319,25 +1330,29 @@ _get_metadata_thread_id_key (void *ctx, const char 
*message_id)
  * thread ID can be looked up if the message is added to the database
  * later).
  */
-static const char *
+static notmuch_status_t
 _resolve_message_id_to_thread_id (notmuch_database_t *notmuch,
  void *ctx,
- const char *message_id)
+ const char *message_id,
+ const char **thread_id)
 {
+notmuch_status_t status;
 notmuch_message_t *message;
 string thread_id_string;
-const char *thread_id;
 char *metadata_key;
 Xapian::WritableDatabase *db;
 
-message = notmuch_database_find_message (notmuch, message_id);
+status = notmuch_database_find_message (notmuch, message_id, message);
+
+if (status)
+   return status;
 
 if (message) {
-   thread_id = talloc_steal (ctx, notmuch_message_get_thread_id (message));
+   *thread_id = talloc_steal (ctx, notmuch_message_get_thread_id 
(message));
 
notmuch_message_destroy (message);
 
-   return thread_id;
+   return NOTMUCH_STATUS_SUCCESS;
 }
 
 /* Message has not been seen yet.
@@ -1351,15 +1366,15 @@ _resolve_message_id_to_thread_id (notmuch_database_t 
*notmuch,
 thread_id_string = notmuch-xapian_db-get_metadata (metadata_key);
 
 if (thread_id_string.empty()) {
-   thread_id = _notmuch_database_generate_thread_id (notmuch);
-   db-set_metadata (metadata_key, thread_id);
+   *thread_id = talloc_strdup(ctx, _notmuch_database_generate_thread_id 
(notmuch));
+   db-set_metadata (metadata_key, *thread_id);
 } else {
-   thread_id = thread_id_string.c_str();
+   *thread_id = talloc_strdup(ctx, thread_id_string.c_str());
 }
 
 talloc_free (metadata_key);
 
-return talloc_strdup (ctx, thread_id);
+return NOTMUCH_STATUS_SUCCESS;
 }
 
 static notmuch_status_t
@@ 

[RFC/PATCH] notmuch link

2011-10-01 Thread Ali Polatel
From: Ali Polatel a...@exherbo.org

Hello,

I have been working on a new notmuch command namely 'link'. This command
aims to help integrating notmuch with different mail agents. Basically
it (sym)links messages matching the given search terms to the specified
target maildir. You may use this maildir as a so-called virtual
folder. After applying the patch call notmuch help link for basic
help.

The patch is also available on links branch under my notmuch repository:
https://github.com/alip/notmuch

Beware this is pretty experimental, I have been using it for a couple of
days fixing the issues along the way. I will be sharing my workflow
using this command with mutt after I'm done polishing my scripts.

This mail is merely a request for comments and testing.

Ali Polatel (1):
  link: Add new command

 Makefile.local   |2 +
 maildir.c|  262 +
 maildir.h|   53 +
 notmuch-client.h |4 +
 notmuch-link.c   |  339 ++
 notmuch.c|   44 +++
 6 files changed, 704 insertions(+), 0 deletions(-)
 create mode 100644 maildir.c
 create mode 100644 maildir.h
 create mode 100644 notmuch-link.c

-- 
1.7.6.1

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


[RFC/PATCH] link: Add new command

2011-10-01 Thread Ali Polatel
From: Ali Polatel a...@exherbo.org

'link' is a new command to create links to specified target maildirs.
This is especially useful for integration with other mail agents.
---
 Makefile.local   |2 +
 maildir.c|  262 +
 maildir.h|   53 +
 notmuch-client.h |4 +
 notmuch-link.c   |  339 ++
 notmuch.c|   44 +++
 6 files changed, 704 insertions(+), 0 deletions(-)
 create mode 100644 maildir.c
 create mode 100644 maildir.h
 create mode 100644 notmuch-link.c

diff --git a/Makefile.local b/Makefile.local
index 38f6c17..a613a4b 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -278,6 +278,7 @@ notmuch_client_srcs =   \
notmuch-config.c\
notmuch-count.c \
notmuch-dump.c  \
+   notmuch-link.c  \
notmuch-new.c   \
notmuch-reply.c \
notmuch-restore.c   \
@@ -289,6 +290,7 @@ notmuch_client_srcs =   \
query-string.c  \
show-message.c  \
json.c  \
+   maildir.c   \
xutil.c
 
 notmuch_client_modules = $(notmuch_client_srcs:.c=.o)
diff --git a/maildir.c b/maildir.c
new file mode 100644
index 000..b8c48b3
--- /dev/null
+++ b/maildir.c
@@ -0,0 +1,262 @@
+/* Maildir utilities for the notmuch mail library
+ *
+ * Copyright © 2011 Ali Polatel
+ * Based in part upon mu which is:
+ *   Copyright © 2008-2011 Dirk-Jan C. Binnema d...@djcbsoftware.nl
+ *
+ * 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/ .
+ *
+ * Author: Ali Polatel pola...@gmail.com
+ */
+
+#include maildir.h
+
+static const char *const maildir_subdirs_array[] = {new, cur, tmp};
+
+/* FIXME: The two functions below, dirent_sort_inode and get_dtype duplicate
+ * code from notmuch-new.c
+ */
+static int
+dirent_sort_inode (const struct dirent **a, const struct dirent **b)
+{
+return ((*a)-d_ino  (*b)-d_ino) ? -1 : 1;
+}
+
+static unsigned char
+get_dtype(const char *fullpath, struct dirent *entry)
+{
+struct stat buf;
+
+if (entry-d_type != DT_UNKNOWN)
+   return entry-d_type;
+
+if (lstat(fullpath, buf) == -1) {
+   fprintf (stderr, Warning: stat failed on `%s': %s\n,
+fullpath, strerror(errno));
+   return DT_UNKNOWN;
+}
+
+if (S_ISREG (buf.st_mode)) {
+   return DT_REG;
+} else if (S_ISDIR (buf.st_mode)) {
+   return DT_DIR;
+} else if (S_ISLNK (buf.st_mode)) {
+   return DT_LNK;
+}
+
+return DT_UNKNOWN;
+}
+
+static notmuch_bool_t
+maildir_access (const char *path)
+{
+struct stat buf;
+
+if (access (path, R_OK | W_OK | X_OK) == -1) {
+   fprintf (stderr, Failed to access path `%s': %s\n,
+path, strerror(errno));
+   return FALSE;
+}
+
+if (lstat(path, buf) == -1) {
+   fprintf (stderr, Failed to access path `%s': %s\n,
+path, strerror(errno));
+   return FALSE;
+}
+
+if (!S_ISDIR(buf.st_mode)) {
+   fprintf (stderr, Path `%s' is not a directory\n, path);
+   return FALSE;
+}
+
+return TRUE;
+}
+
+/* Determine whether the source message is in 'new' or in 'cur';
+ * we ignore messages in 'tmp' for obvious reasons
+ */
+static notmuch_bool_t
+maildir_subdir (const char *src, notmuch_bool_t *in_cur)
+{
+char *srcpath;
+
+srcpath = g_path_get_dirname (src);
+
+if (g_str_has_suffix (srcpath, new))
+   *in_cur = FALSE;
+else if (g_str_has_suffix (srcpath, cur))
+   *in_cur = TRUE;
+else {
+   g_free (srcpath);
+   errno = EINVAL;
+   return FALSE;
+}
+
+g_free(srcpath);
+return TRUE;
+}
+
+static char *
+maildir_transform_path (const char *src, const char *targetpath)
+{
+char *targetfullpath, *srcfile;
+notmuch_bool_t in_cur;
+
+if (!maildir_subdir (src, in_cur)) {
+   fprintf (stderr, Invalid maildir subdirectory `%s': %s\n,
+src, strerror(errno));
+   return NULL;
+}
+
+srcfile = g_path_get_basename (src);
+targetfullpath = g_strdup_printf (%s%c%s%c%s,
+ targetpath,
+ G_DIR_SEPARATOR,
+ in_cur ? cur : new,
+ G_DIR_SEPARATOR

Concerns regarding some library functions

2011-09-30 Thread Ali Polatel
Austin Clements yazm??:
>Quoth Ali Polatel on Sep 28 at 10:53 am:
>> On Tue, 27 Sep 2011 18:46:22 -0400, Austin Clements  
>> wrote:
>> > Quoth David Bremner on Sep 27 at  1:59 pm:
>> > > On Tue, 27 Sep 2011 16:25:58 +0300, Ali Polatel  
>> > > wrote:
>> > >
>> > > > The problem with their design is NULL return may both mean an error
>> > > > condition and "message not found". However, we already have a similar
>> > > > function which does not have such a flaw, namely 
>> > > > notmuch_database_add_message().
>> > >
>> > > So, I take there is no way to distinguish those two outcomes? That does
>> > > sound bad. Looking at the code for notmuch-new, it looks like the return
>> > > value of notmuch_database_find_message_by_filename is used without
>> > > checking it for NULL.  Austin, can you comment on that at all?
>> >
>> > I'd be happy to distinguish these outcomes.  I did
>> > notmuch_database_find_message_by_filename the way I did only to be
>> > consistent with notmuch_database_find_message.  Since ndfmbf isn't
>> > entrenched yet, now is a good time to change it.
>>
>> What about notmuch_database_find_message()? If we leave it as it is,
>> this will lead to inconsistency and if we change it, we need to think
>> about API breakage issues.
>
>Yes.  We could just deal with that (there aren't *that* many API
>consumers).  For binary compatibility, I suppose we could even use
>symbol versioning.
>
>> > The call in notmuch-new should check the return, though if it can't
>> > find the message at that point, something has gone terribly wrong.
>> > Segfaulting is never the answer, though.
>>
>> Indeed, just not to step on each other's feet, are you going to write a
>> patch or shall I start writing one?
>
>Please feel free to write a patch.

Below is a quick patch, which compiles and passes tests.
Please comment.

 -alip

-- >8 --
Subject: [PATCH] lib: make find_message{,by_filename) report errors

Previously, the functions notmuch_database_find_message() and
notmuch_database_find_message_by_filename() functions did not properly
report error condition to the library user.

For more information, read the thread on the notmuch mailing list
starting with my mail "id:871uv2unfd.fsf at gmail.com"

Make these functions accept a pointer to 'notmuch_message_t' as argument
and return notmuch_status_t which may be used to check for any error
condition.

restore: Modify for the new notmuch_database_find_message()
new: Modify for the new notmuch_database_find_message_by_filename()
---
  lib/database.cc   |   89 ++--
  lib/message.cc|6 ++--
  lib/notmuch.h |   61 +---
  notmuch-new.c |4 ++-
  notmuch-restore.c |   11 --
  5 files changed, 114 insertions(+), 57 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 9299c8d..6641aa5 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -360,13 +360,17 @@ _message_id_compressed (void *ctx, const char *message_id)
  return compressed;
  }

-notmuch_message_t *
+notmuch_status_t
  notmuch_database_find_message (notmuch_database_t *notmuch,
-  const char *message_id)
+  const char *message_id,
+  notmuch_message_t **message)
  {
  notmuch_private_status_t status;
  unsigned int doc_id;

+if (message == NULL)
+   return NOTMUCH_STATUS_NULL_POINTER;
+
  if (strlen (message_id) > NOTMUCH_MESSAGE_ID_MAX)
message_id = _message_id_compressed (notmuch, message_id);

@@ -375,14 +379,20 @@ notmuch_database_find_message (notmuch_database_t 
*notmuch,
   message_id, _id);

if (status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND)
-   return NULL;
+   *message = NULL;
+   else {
+   *message = _notmuch_message_create (notmuch, notmuch, doc_id, NULL);
+   if (*message == NULL)
+   return NOTMUCH_STATUS_OUT_OF_MEMORY;
+   }

-   return _notmuch_message_create (notmuch, notmuch, doc_id, NULL);
+   return NOTMUCH_STATUS_SUCCESS;
  } catch (const Xapian::Error ) {
fprintf (stderr, "A Xapian exception occurred finding message: %s.\n",
 error.get_msg().c_str());
notmuch->exception_reported = TRUE;
-   return NULL;
+   *message = NULL;
+   return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
  }
  }

@@ -1311,7 +1321,8 @@ _get_metadata_thread_id_key (void *ctx, const char 
*message_id)

  /* Find the thread ID to which the message with 'message_id' be

Re: Concerns regarding some library functions

2011-09-30 Thread Ali Polatel

Austin Clements yazmış:

Quoth Ali Polatel on Sep 28 at 10:53 am:

On Tue, 27 Sep 2011 18:46:22 -0400, Austin Clements amdra...@mit.edu wrote:
 Quoth David Bremner on Sep 27 at  1:59 pm:
  On Tue, 27 Sep 2011 16:25:58 +0300, Ali Polatel pola...@gmail.com wrote:
 
   The problem with their design is NULL return may both mean an error
   condition and message not found. However, we already have a similar
   function which does not have such a flaw, namely 
notmuch_database_add_message().
 
  So, I take there is no way to distinguish those two outcomes? That does
  sound bad. Looking at the code for notmuch-new, it looks like the return
  value of notmuch_database_find_message_by_filename is used without
  checking it for NULL.  Austin, can you comment on that at all?

 I'd be happy to distinguish these outcomes.  I did
 notmuch_database_find_message_by_filename the way I did only to be
 consistent with notmuch_database_find_message.  Since ndfmbf isn't
 entrenched yet, now is a good time to change it.

What about notmuch_database_find_message()? If we leave it as it is,
this will lead to inconsistency and if we change it, we need to think
about API breakage issues.


Yes.  We could just deal with that (there aren't *that* many API
consumers).  For binary compatibility, I suppose we could even use
symbol versioning.


 The call in notmuch-new should check the return, though if it can't
 find the message at that point, something has gone terribly wrong.
 Segfaulting is never the answer, though.

Indeed, just not to step on each other's feet, are you going to write a
patch or shall I start writing one?


Please feel free to write a patch.


Below is a quick patch, which compiles and passes tests.
Please comment.

-alip

-- 8 --
Subject: [PATCH] lib: make find_message{,by_filename) report errors

Previously, the functions notmuch_database_find_message() and
notmuch_database_find_message_by_filename() functions did not properly
report error condition to the library user.

For more information, read the thread on the notmuch mailing list
starting with my mail id:871uv2unfd@gmail.com

Make these functions accept a pointer to 'notmuch_message_t' as argument
and return notmuch_status_t which may be used to check for any error
condition.

restore: Modify for the new notmuch_database_find_message()
new: Modify for the new notmuch_database_find_message_by_filename()
---
 lib/database.cc   |   89 ++--
 lib/message.cc|6 ++--
 lib/notmuch.h |   61 +---
 notmuch-new.c |4 ++-
 notmuch-restore.c |   11 --
 5 files changed, 114 insertions(+), 57 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 9299c8d..6641aa5 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -360,13 +360,17 @@ _message_id_compressed (void *ctx, const char *message_id)
 return compressed;
 }
 
-notmuch_message_t *

+notmuch_status_t
 notmuch_database_find_message (notmuch_database_t *notmuch,
-  const char *message_id)
+  const char *message_id,
+  notmuch_message_t **message)
 {
 notmuch_private_status_t status;
 unsigned int doc_id;
 
+if (message == NULL)

+   return NOTMUCH_STATUS_NULL_POINTER;
+
 if (strlen (message_id)  NOTMUCH_MESSAGE_ID_MAX)
message_id = _message_id_compressed (notmuch, message_id);
 
@@ -375,14 +379,20 @@ notmuch_database_find_message (notmuch_database_t *notmuch,

   message_id, doc_id);
 
 	if (status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND)

-   return NULL;
+   *message = NULL;
+   else {
+   *message = _notmuch_message_create (notmuch, notmuch, doc_id, NULL);
+   if (*message == NULL)
+   return NOTMUCH_STATUS_OUT_OF_MEMORY;
+   }
 
-	return _notmuch_message_create (notmuch, notmuch, doc_id, NULL);

+   return NOTMUCH_STATUS_SUCCESS;
 } catch (const Xapian::Error error) {
fprintf (stderr, A Xapian exception occurred finding message: %s.\n,
 error.get_msg().c_str());
notmuch-exception_reported = TRUE;
-   return NULL;
+   *message = NULL;
+   return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
 }
 }
 
@@ -1311,7 +1321,8 @@ _get_metadata_thread_id_key (void *ctx, const char *message_id)
 
 /* Find the thread ID to which the message with 'message_id' belongs.

  *
- * Always returns a newly talloced string belonging to 'ctx'.
+ * Note: 'thread_id' must not be NULL!
+ * On success '*thread_id' is set to a newly talloced string belonging to 
'ctx'.
  *
  * Note: If there is no message in the database with the given
  * 'message_id' then a new thread_id will be allocated for this
@@ -1319,25 +1330,29 @@ _get_metadata_thread_id_key (void *ctx, const char 
*message_id)
  * thread ID can be looked up if the message is added

Concerns regarding some library functions

2011-09-28 Thread Ali Polatel
On Tue, 27 Sep 2011 18:46:22 -0400, Austin Clements  wrote:
> Quoth David Bremner on Sep 27 at  1:59 pm:
> > On Tue, 27 Sep 2011 16:25:58 +0300, Ali Polatel  
> > wrote:
> > 
> > > The problem with their design is NULL return may both mean an error
> > > condition and "message not found". However, we already have a similar
> > > function which does not have such a flaw, namely 
> > > notmuch_database_add_message().
> > 
> > So, I take there is no way to distinguish those two outcomes? That does
> > sound bad. Looking at the code for notmuch-new, it looks like the return
> > value of notmuch_database_find_message_by_filename is used without
> > checking it for NULL.  Austin, can you comment on that at all?
> 
> I'd be happy to distinguish these outcomes.  I did
> notmuch_database_find_message_by_filename the way I did only to be
> consistent with notmuch_database_find_message.  Since ndfmbf isn't
> entrenched yet, now is a good time to change it.

What about notmuch_database_find_message()? If we leave it as it is,
this will lead to inconsistency and if we change it, we need to think
about API breakage issues.

> The call in notmuch-new should check the return, though if it can't
> find the message at that point, something has gone terribly wrong.
> Segfaulting is never the answer, though.

Indeed, just not to step on each other's feet, are you going to write a
patch or shall I start writing one?

 -alip
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20110928/7bfddc7b/attachment.pgp>


Re: NEWS for 0.9

2011-09-27 Thread Ali Polatel
On Mon, 26 Sep 2011 20:32:32 -0300, David Bremner da...@tethera.net wrote:
 On Mon, 26 Sep 2011 18:07:01 -0400, Austin Clements amdra...@mit.edu wrote:
  
  In fact, I've been looking forward to writing some NEWS items!
  
 
 Thanks, I have officially (and atomically) stolen your NEWS items. ;).
 
 Sebastian, Ali:
 
 I also threw in my best guess as to python and Ruby changes.  Changes
 are welcome of course.

I'm fine with how the Ruby changes are described in the ChangeLog.
However I have other concerns regarding the recent changes which I will
mention in an upcoming e-mail.

 d

-alip


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


Concerns regarding some library functions

2011-09-27 Thread Ali Polatel
Hello,

Being the maintainer of Ruby bindings, I've been watching the
development of API changes closely. Ruby bindings are nearly complete
with the exception of two functions which I think are poorly implemented
in terms of error handling.

The two functions I've mentioned above are
notmuch_database_find_message() and
notmuch_database_find_message_by_filename().

The problem with their design is NULL return may both mean an error
condition and message not found. However, we already have a similar
function which does not have such a flaw, namely notmuch_database_add_message().

In my humble opinion it is a good idea to modify these functions to
return 'notmuch_status_t' and add an argument 'notmuch_message_t **'
which will be initialized to the message object upon successful return.
This is just like notmuch_database_add_message() which provides both
consistency and proper error reporting.

I vaguely remember this question was raised on the list for
notmuch_database_find_message() before. Seeing the recent addition of
notmuch_database_find_message_by_filename(), I wanted to bring this up
again in the hope to get it fixed as soon as possible.

I am not providing a patch here considering the simplicity of the
problem but if anyone needs elaboration, I will be happy to submit a
patch.

P.S.: Ruby bindings don't have wrappers for these functions but I am not
sure about Python bindings and how they solve, or 'hack around', this
problem. CC'ing Sebastian for comments so we can have consistency
between bindings.

-alip


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


About Ruby bindings

2011-07-29 Thread Ali Polatel

Hi everyone,

I've updated Ruby documentation which is nearly complete now. The
generated documentation is on http://dev.exherbo.org/~alip/notmuch/ruby/
as usual. It seems not many people know about this link though. Maybe we
can move this documentation to notmuchmail.org or add a link from the
wiki. I've checked out the wiki but could not decide where exactly to
add the information on the Ruby bindings.

Just wanted to get your ideas on this, I have some free time and can
write some more documentation or examples which may prove especially
useful to people who come from the world of Sup, which is also written
in Ruby.

In addition, someone told me in #notmuch sometime that providing a gem
would be a good idea. I agree with this but I must admit I do not know
much about gems. If someone is eager to give me a hand with this, we can
work this out too.

Peace and Love!

  -alip


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


[PATCH 4/4] ruby: Add generated files to gitignore

2011-02-03 Thread Ali Polatel
On Mon, 31 Jan 2011 23:48:57 +0100, Thomas Schwinge  
wrote:
> Hallo!
> 
> On Mon, 10 Jan 2011 16:39:28 +0200, Ali Polatel  wrote:
> > --- a/.gitignore
> > +++ b/.gitignore
> > @@ -13,3 +13,7 @@ libnotmuch.so*
> >  .*.swp
> >  *.elc
> >  releases
> > +
> > +bindings/ruby/mkmf.log
> > +bindings/ruby/notmuch.so
> > +bindings/ruby/Makefile
> 
> These should rather be put into bindings/ruby/.gitignore, I'd say.

Good idea!
Just pushed ca69ce2397c0bb9b0e590a80b898ab4d58bb

> 
> Gr??e,
>  Thomas

-- 
Regards,
Ali Polatel
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20110203/a4a9be91/attachment.pgp>


Re: [PATCH 4/4] ruby: Add generated files to gitignore

2011-02-03 Thread Ali Polatel
On Mon, 31 Jan 2011 23:48:57 +0100, Thomas Schwinge tho...@schwinge.name 
wrote:
 Hallo!
 
 On Mon, 10 Jan 2011 16:39:28 +0200, Ali Polatel a...@exherbo.org wrote:
  --- a/.gitignore
  +++ b/.gitignore
  @@ -13,3 +13,7 @@ libnotmuch.so*
   .*.swp
   *.elc
   releases
  +
  +bindings/ruby/mkmf.log
  +bindings/ruby/notmuch.so
  +bindings/ruby/Makefile
 
 These should rather be put into bindings/ruby/.gitignore, I'd say.

Good idea!
Just pushed ca69ce2397c0bb9b0e590a80b898ab4d58bb

 
 Grüße,
  Thomas

-- 
Regards,
Ali Polatel


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


[PATCH 4/4] ruby: Add generated files to gitignore

2011-01-10 Thread Ali Polatel
---
 .gitignore |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore
index 217440d..9786d4d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,3 +13,7 @@ libnotmuch.so*
 .*.swp
 *.elc
 releases
+
+bindings/ruby/mkmf.log
+bindings/ruby/notmuch.so
+bindings/ruby/Makefile
-- 
1.7.3.5



[PATCH 3/4] ruby: Add wrapper for message_get_filenames

2011-01-10 Thread Ali Polatel
---
 bindings/ruby/defs.h|3 +++
 bindings/ruby/init.c|1 +
 bindings/ruby/message.c |   18 ++
 3 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index 1f52988..f00afef 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -269,6 +269,9 @@ VALUE
 notmuch_rb_message_get_filename(VALUE self);

 VALUE
+notmuch_rb_message_get_filenames(VALUE self);
+
+VALUE
 notmuch_rb_message_get_flag(VALUE self, VALUE flagv);

 VALUE
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index 4a63ba0..aa09c8d 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -263,6 +263,7 @@ Init_notmuch(void)
 rb_define_method(notmuch_rb_cMessage, "thread_id", 
notmuch_rb_message_get_thread_id, 0);
 rb_define_method(notmuch_rb_cMessage, "replies", 
notmuch_rb_message_get_replies, 0);
 rb_define_method(notmuch_rb_cMessage, "filename", 
notmuch_rb_message_get_filename, 0);
+rb_define_method(notmuch_rb_cMessage, "filenames", 
notmuch_rb_message_get_filenames, 0);
 rb_define_method(notmuch_rb_cMessage, "get_flag", 
notmuch_rb_message_get_flag, 1);
 rb_define_method(notmuch_rb_cMessage, "set_flag", 
notmuch_rb_message_set_flag, 2);
 rb_define_method(notmuch_rb_cMessage, "date", notmuch_rb_message_get_date, 
0);
diff --git a/bindings/ruby/message.c b/bindings/ruby/message.c
index 1b2c01e..49dbace 100644
--- a/bindings/ruby/message.c
+++ b/bindings/ruby/message.c
@@ -111,6 +111,24 @@ notmuch_rb_message_get_filename(VALUE self)
 }

 /*
+ * call-seq: MESSAGE.filanames => FILENAMES
+ *
+ * Get all filenames for the email corresponding to MESSAGE.
+ */
+VALUE
+notmuch_rb_message_get_filenames(VALUE self)
+{
+notmuch_filenames_t *fnames;
+notmuch_message_t *message;
+
+Data_Get_Notmuch_Message(self, message);
+
+fnames = notmuch_message_get_filenames(message);
+
+return Data_Wrap_Struct(notmuch_rb_cFileNames, NULL, NULL, fnames);
+}
+
+/*
  * call-seq: MESSAGE.get_flag(flag) => true or false
  *
  * Get a value of a flag for the email corresponding to 'message'
-- 
1.7.3.5



[PATCH 2/4] ruby: Add wrappers for maildir sync. interface

2011-01-10 Thread Ali Polatel
New wrappers:
notmuch_message_maildir_flags_to_tags(): MESSAGE.maildir_flags_to_tags
notmuch_message_tags_to_maildir_flags(): MESSAGE.tags_to_maildir_flags
---
 bindings/ruby/defs.h|6 ++
 bindings/ruby/init.c|2 ++
 bindings/ruby/message.c |   38 ++
 3 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index db53096..1f52988 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -293,6 +293,12 @@ VALUE
 notmuch_rb_message_remove_all_tags(VALUE self);

 VALUE
+notmuch_rb_message_maildir_flags_to_tags(VALUE self);
+
+VALUE
+notmuch_rb_message_tags_to_maildir_flags(VALUE self);
+
+VALUE
 notmuch_rb_message_freeze(VALUE self);

 VALUE
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index 63ab205..4a63ba0 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -273,6 +273,8 @@ Init_notmuch(void)
 rb_define_alias(notmuch_rb_cMessage, "<<", "add_tag");
 rb_define_method(notmuch_rb_cMessage, "remove_tag", 
notmuch_rb_message_remove_tag, 1);
 rb_define_method(notmuch_rb_cMessage, "remove_all_tags", 
notmuch_rb_message_remove_all_tags, 0);
+rb_define_method(notmuch_rb_cMessage, "maildir_flags_to_tags", 
notmuch_rb_message_maildir_flags_to_tags, 0);
+rb_define_method(notmuch_rb_cMessage, "tags_to_maildir_flags", 
notmuch_rb_message_tags_to_maildir_flags, 0);
 rb_define_method(notmuch_rb_cMessage, "freeze", notmuch_rb_message_freeze, 
0);
 rb_define_method(notmuch_rb_cMessage, "thaw", notmuch_rb_message_thaw, 0);

diff --git a/bindings/ruby/message.c b/bindings/ruby/message.c
index f97e1a4..1b2c01e 100644
--- a/bindings/ruby/message.c
+++ b/bindings/ruby/message.c
@@ -284,6 +284,44 @@ notmuch_rb_message_remove_all_tags(VALUE self)
 }

 /*
+ * call-seq: MESSAGE.maildir_flags_to_tags => true
+ *
+ * Add/remove tags according to maildir flags in the message filename(s)
+ */
+VALUE
+notmuch_rb_message_maildir_flags_to_tags(VALUE self)
+{
+notmuch_status_t ret;
+notmuch_message_t *message;
+
+Data_Get_Notmuch_Message(self, message);
+
+ret = notmuch_message_maildir_flags_to_tags(message);
+notmuch_rb_status_raise(ret);
+
+return Qtrue;
+}
+
+/*
+ * call-seq: MESSAGE.tags_to_maildir_flags => true
+ *
+ * Rename message filename(s) to encode tags as maildir flags
+ */
+VALUE
+notmuch_rb_message_tags_to_maildir_flags(VALUE self)
+{
+notmuch_status_t ret;
+notmuch_message_t *message;
+
+Data_Get_Notmuch_Message(self, message);
+
+ret = notmuch_message_tags_to_maildir_flags(message);
+notmuch_rb_status_raise(ret);
+
+return Qtrue;
+}
+
+/*
  * call-seq: MESSAGE.freeze => true
  *
  * Freeze the 'message'
-- 
1.7.3.5



[PATCH 1/4] ruby: Add wrappers for query_get_s{ort,tring}

2011-01-10 Thread Ali Polatel
New wrappers:
notmuch_query_get_sort(): QUERY.sort
notmuch_query_get_query_string(): QUERY.to_s
---
 bindings/ruby/defs.h  |6 ++
 bindings/ruby/init.c  |2 ++
 bindings/ruby/query.c |   30 ++
 3 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index b1be5a3..db53096 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -190,9 +190,15 @@ VALUE
 notmuch_rb_query_destroy(VALUE self);

 VALUE
+notmuch_rb_query_get_sort(VALUE self);
+
+VALUE
 notmuch_rb_query_set_sort(VALUE self, VALUE sortv);

 VALUE
+notmuch_rb_query_get_string(VALUE self);
+
+VALUE
 notmuch_rb_query_search_threads(VALUE self);

 VALUE
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index e19b035..63ab205 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -224,7 +224,9 @@ Init_notmuch(void)
 notmuch_rb_cQuery = rb_define_class_under(mod, "Query", rb_cData);
 rb_undef_method(notmuch_rb_cQuery, "initialize");
 rb_define_method(notmuch_rb_cQuery, "destroy", notmuch_rb_query_destroy, 
0);
+rb_define_method(notmuch_rb_cQuery, "sort", notmuch_rb_query_get_sort, 0);
 rb_define_method(notmuch_rb_cQuery, "sort=", notmuch_rb_query_set_sort, 1);
+rb_define_method(notmuch_rb_cQuery, "to_s", notmuch_rb_query_get_string, 
0);
 rb_define_method(notmuch_rb_cQuery, "search_threads", 
notmuch_rb_query_search_threads, 0);
 rb_define_method(notmuch_rb_cQuery, "search_messages", 
notmuch_rb_query_search_messages, 0);

diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c
index c5b8a4c..ef9e1a0 100644
--- a/bindings/ruby/query.c
+++ b/bindings/ruby/query.c
@@ -39,6 +39,21 @@ notmuch_rb_query_destroy(VALUE self)
 }

 /*
+ * call-seq: QUERY.sort => fixnum
+ *
+ * Get sort type of the +QUERY+
+ */
+VALUE
+notmuch_rb_query_get_sort(VALUE self)
+{
+notmuch_query_t *query;
+
+Data_Get_Notmuch_Query(self, query);
+
+return FIX2INT(notmuch_query_get_sort(query));
+}
+
+/*
  * call-seq: QUERY.sort=(fixnum) => nil
  *
  * Set sort type of the +QUERY+
@@ -59,6 +74,21 @@ notmuch_rb_query_set_sort(VALUE self, VALUE sortv)
 }

 /*
+ * call-seq: QUERY.to_s => string
+ *
+ * Get query string of the +QUERY+
+ */
+VALUE
+notmuch_rb_query_get_string(VALUE self)
+{
+notmuch_query_t *query;
+
+Data_Get_Notmuch_Query(self, query);
+
+return rb_str_new2(notmuch_query_get_query_string(query));
+}
+
+/*
  * call-seq: QUERY.search_threads => THREADS
  *
  * Search for threads
-- 
1.7.3.5



[PATCH 0/4] Update Ruby bindings

2011-01-10 Thread Ali Polatel
Hello all,

This patchset updates Ruby bindings to cover all the recent
functionality of the notmuch library.

Ali Polatel (4):
  ruby: Add wrappers for query_get_s{ort,tring}
  ruby: Add wrappers for maildir sync. interface
  ruby: Add wrapper for message_get_filenames
  ruby: Add generated files to gitignore

 .gitignore  |4 +++
 bindings/ruby/defs.h|   15 
 bindings/ruby/init.c|5 
 bindings/ruby/message.c |   56 +++
 bindings/ruby/query.c   |   30 +
 5 files changed, 110 insertions(+), 0 deletions(-)

-- 
1.7.3.5



[PATCH 0/4] Update Ruby bindings

2011-01-10 Thread Ali Polatel
Hello all,

This patchset updates Ruby bindings to cover all the recent
functionality of the notmuch library.

Ali Polatel (4):
  ruby: Add wrappers for query_get_s{ort,tring}
  ruby: Add wrappers for maildir sync. interface
  ruby: Add wrapper for message_get_filenames
  ruby: Add generated files to gitignore

 .gitignore  |4 +++
 bindings/ruby/defs.h|   15 
 bindings/ruby/init.c|5 
 bindings/ruby/message.c |   56 +++
 bindings/ruby/query.c   |   30 +
 5 files changed, 110 insertions(+), 0 deletions(-)

-- 
1.7.3.5

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


[PATCH 1/4] ruby: Add wrappers for query_get_s{ort,tring}

2011-01-10 Thread Ali Polatel
New wrappers:
notmuch_query_get_sort(): QUERY.sort
notmuch_query_get_query_string(): QUERY.to_s
---
 bindings/ruby/defs.h  |6 ++
 bindings/ruby/init.c  |2 ++
 bindings/ruby/query.c |   30 ++
 3 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index b1be5a3..db53096 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -190,9 +190,15 @@ VALUE
 notmuch_rb_query_destroy(VALUE self);
 
 VALUE
+notmuch_rb_query_get_sort(VALUE self);
+
+VALUE
 notmuch_rb_query_set_sort(VALUE self, VALUE sortv);
 
 VALUE
+notmuch_rb_query_get_string(VALUE self);
+
+VALUE
 notmuch_rb_query_search_threads(VALUE self);
 
 VALUE
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index e19b035..63ab205 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -224,7 +224,9 @@ Init_notmuch(void)
 notmuch_rb_cQuery = rb_define_class_under(mod, Query, rb_cData);
 rb_undef_method(notmuch_rb_cQuery, initialize);
 rb_define_method(notmuch_rb_cQuery, destroy, notmuch_rb_query_destroy, 
0);
+rb_define_method(notmuch_rb_cQuery, sort, notmuch_rb_query_get_sort, 0);
 rb_define_method(notmuch_rb_cQuery, sort=, notmuch_rb_query_set_sort, 1);
+rb_define_method(notmuch_rb_cQuery, to_s, notmuch_rb_query_get_string, 
0);
 rb_define_method(notmuch_rb_cQuery, search_threads, 
notmuch_rb_query_search_threads, 0);
 rb_define_method(notmuch_rb_cQuery, search_messages, 
notmuch_rb_query_search_messages, 0);
 
diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c
index c5b8a4c..ef9e1a0 100644
--- a/bindings/ruby/query.c
+++ b/bindings/ruby/query.c
@@ -39,6 +39,21 @@ notmuch_rb_query_destroy(VALUE self)
 }
 
 /*
+ * call-seq: QUERY.sort = fixnum
+ *
+ * Get sort type of the +QUERY+
+ */
+VALUE
+notmuch_rb_query_get_sort(VALUE self)
+{
+notmuch_query_t *query;
+
+Data_Get_Notmuch_Query(self, query);
+
+return FIX2INT(notmuch_query_get_sort(query));
+}
+
+/*
  * call-seq: QUERY.sort=(fixnum) = nil
  *
  * Set sort type of the +QUERY+
@@ -59,6 +74,21 @@ notmuch_rb_query_set_sort(VALUE self, VALUE sortv)
 }
 
 /*
+ * call-seq: QUERY.to_s = string
+ *
+ * Get query string of the +QUERY+
+ */
+VALUE
+notmuch_rb_query_get_string(VALUE self)
+{
+notmuch_query_t *query;
+
+Data_Get_Notmuch_Query(self, query);
+
+return rb_str_new2(notmuch_query_get_query_string(query));
+}
+
+/*
  * call-seq: QUERY.search_threads = THREADS
  *
  * Search for threads
-- 
1.7.3.5

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


[PATCH 4/4] ruby: Add generated files to gitignore

2011-01-10 Thread Ali Polatel
---
 .gitignore |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore
index 217440d..9786d4d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,3 +13,7 @@ libnotmuch.so*
 .*.swp
 *.elc
 releases
+
+bindings/ruby/mkmf.log
+bindings/ruby/notmuch.so
+bindings/ruby/Makefile
-- 
1.7.3.5

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


[PATCH 2/4] ruby: Add wrappers for maildir sync. interface

2011-01-10 Thread Ali Polatel
New wrappers:
notmuch_message_maildir_flags_to_tags(): MESSAGE.maildir_flags_to_tags
notmuch_message_tags_to_maildir_flags(): MESSAGE.tags_to_maildir_flags
---
 bindings/ruby/defs.h|6 ++
 bindings/ruby/init.c|2 ++
 bindings/ruby/message.c |   38 ++
 3 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index db53096..1f52988 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -293,6 +293,12 @@ VALUE
 notmuch_rb_message_remove_all_tags(VALUE self);
 
 VALUE
+notmuch_rb_message_maildir_flags_to_tags(VALUE self);
+
+VALUE
+notmuch_rb_message_tags_to_maildir_flags(VALUE self);
+
+VALUE
 notmuch_rb_message_freeze(VALUE self);
 
 VALUE
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index 63ab205..4a63ba0 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -273,6 +273,8 @@ Init_notmuch(void)
 rb_define_alias(notmuch_rb_cMessage, , add_tag);
 rb_define_method(notmuch_rb_cMessage, remove_tag, 
notmuch_rb_message_remove_tag, 1);
 rb_define_method(notmuch_rb_cMessage, remove_all_tags, 
notmuch_rb_message_remove_all_tags, 0);
+rb_define_method(notmuch_rb_cMessage, maildir_flags_to_tags, 
notmuch_rb_message_maildir_flags_to_tags, 0);
+rb_define_method(notmuch_rb_cMessage, tags_to_maildir_flags, 
notmuch_rb_message_tags_to_maildir_flags, 0);
 rb_define_method(notmuch_rb_cMessage, freeze, notmuch_rb_message_freeze, 
0);
 rb_define_method(notmuch_rb_cMessage, thaw, notmuch_rb_message_thaw, 0);
 
diff --git a/bindings/ruby/message.c b/bindings/ruby/message.c
index f97e1a4..1b2c01e 100644
--- a/bindings/ruby/message.c
+++ b/bindings/ruby/message.c
@@ -284,6 +284,44 @@ notmuch_rb_message_remove_all_tags(VALUE self)
 }
 
 /*
+ * call-seq: MESSAGE.maildir_flags_to_tags = true
+ *
+ * Add/remove tags according to maildir flags in the message filename(s)
+ */
+VALUE
+notmuch_rb_message_maildir_flags_to_tags(VALUE self)
+{
+notmuch_status_t ret;
+notmuch_message_t *message;
+
+Data_Get_Notmuch_Message(self, message);
+
+ret = notmuch_message_maildir_flags_to_tags(message);
+notmuch_rb_status_raise(ret);
+
+return Qtrue;
+}
+
+/*
+ * call-seq: MESSAGE.tags_to_maildir_flags = true
+ *
+ * Rename message filename(s) to encode tags as maildir flags
+ */
+VALUE
+notmuch_rb_message_tags_to_maildir_flags(VALUE self)
+{
+notmuch_status_t ret;
+notmuch_message_t *message;
+
+Data_Get_Notmuch_Message(self, message);
+
+ret = notmuch_message_tags_to_maildir_flags(message);
+notmuch_rb_status_raise(ret);
+
+return Qtrue;
+}
+
+/*
  * call-seq: MESSAGE.freeze = true
  *
  * Freeze the 'message'
-- 
1.7.3.5

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


[PATCH 3/4] ruby: Add wrapper for message_get_filenames

2011-01-10 Thread Ali Polatel
---
 bindings/ruby/defs.h|3 +++
 bindings/ruby/init.c|1 +
 bindings/ruby/message.c |   18 ++
 3 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index 1f52988..f00afef 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -269,6 +269,9 @@ VALUE
 notmuch_rb_message_get_filename(VALUE self);
 
 VALUE
+notmuch_rb_message_get_filenames(VALUE self);
+
+VALUE
 notmuch_rb_message_get_flag(VALUE self, VALUE flagv);
 
 VALUE
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index 4a63ba0..aa09c8d 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -263,6 +263,7 @@ Init_notmuch(void)
 rb_define_method(notmuch_rb_cMessage, thread_id, 
notmuch_rb_message_get_thread_id, 0);
 rb_define_method(notmuch_rb_cMessage, replies, 
notmuch_rb_message_get_replies, 0);
 rb_define_method(notmuch_rb_cMessage, filename, 
notmuch_rb_message_get_filename, 0);
+rb_define_method(notmuch_rb_cMessage, filenames, 
notmuch_rb_message_get_filenames, 0);
 rb_define_method(notmuch_rb_cMessage, get_flag, 
notmuch_rb_message_get_flag, 1);
 rb_define_method(notmuch_rb_cMessage, set_flag, 
notmuch_rb_message_set_flag, 2);
 rb_define_method(notmuch_rb_cMessage, date, notmuch_rb_message_get_date, 
0);
diff --git a/bindings/ruby/message.c b/bindings/ruby/message.c
index 1b2c01e..49dbace 100644
--- a/bindings/ruby/message.c
+++ b/bindings/ruby/message.c
@@ -111,6 +111,24 @@ notmuch_rb_message_get_filename(VALUE self)
 }
 
 /*
+ * call-seq: MESSAGE.filanames = FILENAMES
+ *
+ * Get all filenames for the email corresponding to MESSAGE.
+ */
+VALUE
+notmuch_rb_message_get_filenames(VALUE self)
+{
+notmuch_filenames_t *fnames;
+notmuch_message_t *message;
+
+Data_Get_Notmuch_Message(self, message);
+
+fnames = notmuch_message_get_filenames(message);
+
+return Data_Wrap_Struct(notmuch_rb_cFileNames, NULL, NULL, fnames);
+}
+
+/*
  * call-seq: MESSAGE.get_flag(flag) = true or false
  *
  * Get a value of a flag for the email corresponding to 'message'
-- 
1.7.3.5

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


[ANN] notmuch-deliver

2010-11-09 Thread Ali Polatel
On Mon, 08 Nov 2010 09:50:46 -0800, Carl Worth  wrote:
> On Wed, 26 May 2010 17:01:34 +0300, Ali Polatel  wrote:
> > notmuch-deliver is a maildir delivery tool for notmuch mail indexer. It
> > reads from standard input, delivers the mail to the specified maildir
> > and adds it to the notmuch database. This is meant as a convenient
> > alternative to running notmuch new after mail delivery.
> 
> Thanks for sharing this, Ali.

You're welcome!

> What's the best way to advertise this to potential users?

Never thought about it honestly, I've just been using for sometime now
and I'm quite happy with the results.

> Should we include a separate utils directory in the notmuch repository
> with auxiliary programs like this?

Well, such programs should live in their own repositories. One big git
repository with everything in it is just against the idea of distributed
source control management imo.

> Or should we implement this functionality within the notmuch binary
> itself?

We can think about this when the tool gets enough testing in my opinion.
At this stage I don't think it's worth the hassle to include the
functionality into the notmuch binary itself, but this is my personal
opinion and I don't really know how many people in the outer-space uses
this program.

> I'm open to suggestions.

Oh well, I'm open to more vodka.

> If nothing else, the notmuchmail.org web page should grow a section to
> point to auxiliary programs like this that users might find helpful.

+1, but I won't be writing any documentation since I'm a mighty slacker.

> Thanks again,

You're welcome again!

> -Carl
> 
> -- 
> carl.d.worth at intel.com

-- 
Regards,
Ali Polatel
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20101109/3057e81f/attachment.pgp>


notmuch-haskell

2010-10-10 Thread Ali Polatel
On Sat, 09 Oct 2010 00:24:41 -0700, Bart Massey  wrote:
> > On Sat, 18 Sep 2010 15:05:07 -0700, Bart Massey  wrote:
> > > I've posted notmuch-haskell, Haskell FFI bindings for libnotmuch, on
> > > Hackage (http://hackage.haskell.org).  They're quite preliminary, have
> > > no documentation, and probably are a bit buggy.  However, they should
> > > let you get started working with notmuch from Haskell code.
> > >
> > 
> > I've written haskell bindings for notmuch using c2hs sometime ago but
> > didn't post them on Hackage. These bindings are well documented as far
> > as I can tell.
> 
> Cool!  Why don't you look over what I've put up and what you have, and
> see if you can get a "best of both worlds" version.  I have no
> particular attachment to what I did---though I learned a lot---other
> than that I needed a decent set of Haskell bindings.  My bindings are a
> bit above the literal c2hs level in some places, so maybe that work is
> useful to you?
>

I've read it a bit and it definitely looks useful. I have plans to
convert my version of hs-notmuch from c2hs to hsc which is easier to
maintain and less likely to break when switching ghc versions.

> > I've also started writing a notmuch email reader in Haskell, called
> > Qoropa. It can't do much right now, you can only view search results
> > with it.
> 
> Good start!
> 
> > Due to lack of time, I couldn't work on these projects in the previous
> > months, but I'm willing to start coding again.
> > 
> > My knowledge of Haskell is primitive, which you can understand if you
> > read the code but if you want to cooperate anyway, I'd really be more
> > than happy to give you push access to these repositories.
> > 
> > http://github.com/alip/hs-notmuch
> > http://github.com/alip/qoropa
> 
> I honestly won't have time to look at stuff for a few weeks, so whatever
> you can figure out is great.  I'm happy to cooperate in any way that
> seems useful to you, time permitting.

That's great news! Let's see what the next weeks bring. :)

> Thanks much for the note and the work!  Feel free to forward this
> message to the list.

Added notmuch at notmuchmail.org to Cc.

> Bart Mass
> bart at cs.pdx.edu
> 

-- 
Regards,
Ali Polatel
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20101010/7126269a/attachment.pgp>


notmuch-haskell

2010-10-02 Thread Ali Polatel
On Sat, 18 Sep 2010 15:05:07 -0700, Bart Massey  wrote:
> I've posted notmuch-haskell, Haskell FFI bindings for libnotmuch, on
> Hackage (http://hackage.haskell.org).  They're quite preliminary, have
> no documentation, and probably are a bit buggy.  However, they should
> let you get started working with notmuch from Haskell code.
>

I've written haskell bindings? for notmuch using c2hs sometime ago but
didn't post them on Hackage. These bindings are well documented as far
as I can tell.

I've also started writing a notmuch email reader in Haskell, called
Qoropa?. It can't do much right now, you can only view search results
with it.

Due to lack of time, I couldn't work on these projects in the previous
months, but I'm willing to start coding again.

My knowledge of Haskell is primitive, which you can understand if you
read the code but if you want to cooperate anyway, I'd really be more
than happy to give you push access to these repositories.

?: http://github.com/alip/hs-notmuch
?: http://github.com/alip/qoropa

> Bart Massey
> bart at cs.pdx.edu
> 

-- 
Regards,
Ali Polatel
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20101002/f7273c97/attachment.pgp>


Re: notmuch-haskell

2010-10-02 Thread Ali Polatel
On Sat, 18 Sep 2010 15:05:07 -0700, Bart Massey b...@po8.org wrote:
 I've posted notmuch-haskell, Haskell FFI bindings for libnotmuch, on
 Hackage (http://hackage.haskell.org).  They're quite preliminary, have
 no documentation, and probably are a bit buggy.  However, they should
 let you get started working with notmuch from Haskell code.


I've written haskell bindings¹ for notmuch using c2hs sometime ago but
didn't post them on Hackage. These bindings are well documented as far
as I can tell.

I've also started writing a notmuch email reader in Haskell, called
Qoropa². It can't do much right now, you can only view search results
with it.

Due to lack of time, I couldn't work on these projects in the previous
months, but I'm willing to start coding again.

My knowledge of Haskell is primitive, which you can understand if you
read the code but if you want to cooperate anyway, I'd really be more
than happy to give you push access to these repositories.

¹: http://github.com/alip/hs-notmuch
²: http://github.com/alip/qoropa

 Bart Massey
 b...@cs.pdx.edu
 

-- 
Regards,
Ali Polatel


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


[GIT PULL] Ruby bindings

2010-06-06 Thread Ali Polatel

Hey Carl,

Here's a pull request for ruby bindings as you requested on #notmuch.
I've only tested them briefly and I hope more people will test it and
contribute to it if it's merged with master. So here goes:

The following changes since commit 2ead072e85315387c0cc3c2236cdedb59503881e:

  Fix minor style issues in show_part_content function. (2010-06-05 08:47:13 
-0700)

are available in the git repository at:
  git://github.com/alip/notmuch.git ruby

Ali Polatel (6):
  Initial ruby bindings
  ruby: fix documentation of DB.upgrade!
  ruby: First attempt at fixing gc for ruby-1.9
  ruby: Kill garbage collection related cruft.
  ruby: Use rb_scan_args()
  ruby: Don't barf if an object is destroyed more than once

 bindings/ruby/database.c  |  321 
 bindings/ruby/defs.h  |  306 ++
 bindings/ruby/directory.c |  115 
 bindings/ruby/extconf.rb  |   15 ++
 bindings/ruby/filenames.c |   58 
 bindings/ruby/init.c  |  282 +++
 bindings/ruby/message.c   |  322 +
 bindings/ruby/messages.c  |   80 +++
 bindings/ruby/query.c |   99 ++
 bindings/ruby/rdoc.sh |   10 ++
 bindings/ruby/status.c|   49 +++
 bindings/ruby/tags.c  |   61 +
 bindings/ruby/thread.c|  193 +++
 bindings/ruby/threads.c   |   60 +
 14 files changed, 1971 insertions(+), 0 deletions(-)
 create mode 100644 bindings/ruby/database.c
 create mode 100644 bindings/ruby/defs.h
 create mode 100644 bindings/ruby/directory.c
 create mode 100644 bindings/ruby/extconf.rb
 create mode 100644 bindings/ruby/filenames.c
 create mode 100644 bindings/ruby/init.c
 create mode 100644 bindings/ruby/message.c
 create mode 100644 bindings/ruby/messages.c
 create mode 100644 bindings/ruby/query.c
 create mode 100755 bindings/ruby/rdoc.sh
 create mode 100644 bindings/ruby/status.c
 create mode 100644 bindings/ruby/tags.c
 create mode 100644 bindings/ruby/thread.c
 create mode 100644 bindings/ruby/threads.c

-- 
Regards,
Ali Polatel
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20100606/0c0c41ff/attachment.pgp>


[GIT PULL] Ruby bindings

2010-06-06 Thread Ali Polatel

Hey Carl,

Here's a pull request for ruby bindings as you requested on #notmuch.
I've only tested them briefly and I hope more people will test it and
contribute to it if it's merged with master. So here goes:

The following changes since commit 2ead072e85315387c0cc3c2236cdedb59503881e:
 
  Fix minor style issues in show_part_content function. (2010-06-05 08:47:13 
-0700)

are available in the git repository at:
  git://github.com/alip/notmuch.git ruby

Ali Polatel (6):
  Initial ruby bindings
  ruby: fix documentation of DB.upgrade!
  ruby: First attempt at fixing gc for ruby-1.9
  ruby: Kill garbage collection related cruft.
  ruby: Use rb_scan_args()
  ruby: Don't barf if an object is destroyed more than once

 bindings/ruby/database.c  |  321 
 bindings/ruby/defs.h  |  306 ++
 bindings/ruby/directory.c |  115 
 bindings/ruby/extconf.rb  |   15 ++
 bindings/ruby/filenames.c |   58 
 bindings/ruby/init.c  |  282 +++
 bindings/ruby/message.c   |  322 +
 bindings/ruby/messages.c  |   80 +++
 bindings/ruby/query.c |   99 ++
 bindings/ruby/rdoc.sh |   10 ++
 bindings/ruby/status.c|   49 +++
 bindings/ruby/tags.c  |   61 +
 bindings/ruby/thread.c|  193 +++
 bindings/ruby/threads.c   |   60 +
 14 files changed, 1971 insertions(+), 0 deletions(-)
 create mode 100644 bindings/ruby/database.c
 create mode 100644 bindings/ruby/defs.h
 create mode 100644 bindings/ruby/directory.c
 create mode 100644 bindings/ruby/extconf.rb
 create mode 100644 bindings/ruby/filenames.c
 create mode 100644 bindings/ruby/init.c
 create mode 100644 bindings/ruby/message.c
 create mode 100644 bindings/ruby/messages.c
 create mode 100644 bindings/ruby/query.c
 create mode 100755 bindings/ruby/rdoc.sh
 create mode 100644 bindings/ruby/status.c
 create mode 100644 bindings/ruby/tags.c
 create mode 100644 bindings/ruby/thread.c
 create mode 100644 bindings/ruby/threads.c

-- 
Regards,
Ali Polatel


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


[ANN] notmuch-deliver

2010-05-26 Thread Ali Polatel

notmuch-deliver is a maildir delivery tool for notmuch mail indexer. It
reads from standard input, delivers the mail to the specified maildir
and adds it to the notmuch database. This is meant as a convenient
alternative to running notmuch new after mail delivery.

Git: git://github.com/alip/notmuch-deliver.git
Readme: http://github.com/alip/notmuch-deliver/blob/master/README.mkd

-- 
Regards,
Ali Polatel
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20100526/63e23d2a/attachment.pgp>


[ANN] notmuch-deliver

2010-05-26 Thread Ali Polatel

notmuch-deliver is a maildir delivery tool for notmuch mail indexer. It
reads from standard input, delivers the mail to the specified maildir
and adds it to the notmuch database. This is meant as a convenient
alternative to running notmuch new after mail delivery.

Git: git://github.com/alip/notmuch-deliver.git
Readme: http://github.com/alip/notmuch-deliver/blob/master/README.mkd

-- 
Regards,
Ali Polatel


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


Notmuch Ruby bindings

2010-05-22 Thread Ali Polatel

Hey all,
I've written Ruby bindings for the notmuch library.

Here are related links:
Gitweb: http://github.com/alip/notmuch/tree/ruby
Git: git://github.com/alip/notmuch.git (branch ruby)
API documentation: http://dev.exherbo.org/~alip/notmuch/ruby/

Building is simple:
- Clone the git url mentioned above and switch to the ruby branch.
- Build the notmuch library
- cd bindings/ruby
- ruby extconf.rb
- make

This is written in pure C, unlike Python bindings, which uses
ctypes. This means it should be a bit faster but possibly more buggy,
especially the garbage collection routines. I've tried hard to make
Ruby's GC play nice with notmuch's talloc based memory allocation but I
can't be sure if it's bug-free.

I haven't written any examples yet but the API documentation should be
clear enough for one to understand and dive in.

As usual, any comments, patches welcome.

-- 
Regards,
Ali Polatel
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20100522/2f3461f1/attachment.pgp>


Notmuch Ruby bindings

2010-05-22 Thread Ali Polatel

Hey all,
I've written Ruby bindings for the notmuch library.

Here are related links:
Gitweb: http://github.com/alip/notmuch/tree/ruby
Git: git://github.com/alip/notmuch.git (branch ruby)
API documentation: http://dev.exherbo.org/~alip/notmuch/ruby/

Building is simple:
- Clone the git url mentioned above and switch to the ruby branch.
- Build the notmuch library
- cd bindings/ruby
- ruby extconf.rb
- make

This is written in pure C, unlike Python bindings, which uses
ctypes. This means it should be a bit faster but possibly more buggy,
especially the garbage collection routines. I've tried hard to make
Ruby's GC play nice with notmuch's talloc based memory allocation but I
can't be sure if it's bug-free.

I haven't written any examples yet but the API documentation should be
clear enough for one to understand and dive in.

As usual, any comments, patches welcome.

-- 
Regards,
Ali Polatel


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


[notmuch] Thoughts on notmuch and Lua

2010-01-16 Thread Ali Polatel
Carl Worth yazm??:
> On Fri, 15 Jan 2010 23:09:34 +0200, Ali Polatel  wrote:
> > Carl Worth yazm??:
> > > What do you think, Ali? Would an approach like that satisfy the things
> > > you had in mind for hooks?
> > 
> > It might, here are some thoughts and questions to help you elaborate:
> > 
> > - How will these scripts manipulate data?
> >   e.g.: A "tagger" script may get the new mail from stdin and print out
> >   the new tags which notmuch will read and apply to the message.
> 
> This can happen with current notmuch entirely with no real "hook"
> support.
> 
> We've talked about switching from default tags of "inbox" and "unread"
> to simply having new mail tagged with a "new" tag. So a "tagger" script
> could operate simply by doing a "notmuch search" for messages with the
> "new" tag and could iterate over the filenames to process actual
> messages. (We don't have support now for emitting just filenames from a
> "notmuch search", but we have patches for that, and I'll be applying one
> soon.)
> 

This is one of the reasons I wanted hook support in the beginning.
I'm looking forward to seeing this in notmuch.

> So that's a taste for the "scriptability" I see in the current notmuch
> system that makes it really much more flexible than any "hooks"
> system. Additional flexibility comes from:
> 
>   * User can run a script like this at any point---not merely when
> messages are added.
> 
>   * User script isn't restricted to dealing only with "new" messages,
> but can act on any set of messages based on any search constraint,
> (or even all messages in the database).
> 
> The results can then be applied by simply calling "notmuch tag" as
> needed.
> 

+1. I totally agree.

> And if there are any performance problems there we can fix them, (such
> as, perhaps we'll end up wanting this script to be able to invoke a
> single process for all of its tagging rather than calling "notmuch tag"
> over and over).
> 
> >   A "search-filter" script may get search results from stdin and filter
> >   them. Just my initial thoughts.
> 
> And how would this search functionality and filtering be different than
> the search functionality provided by notmuch itself?
> 

I accept, this search-filter idea is kinda stupid now that I think about
it.

> I can think of at least a couple of ways it might be different:
> 
>   1. It would be nice to be able to filter based on tags that are
>  present in a thread, though perhaps not present in any message
>  matching the original search.
> 
>  An obvious application of this is the "thread muting" feature,
>  where once a message is tagged as "muted", no messages delivered to
>  that thread in the future will appear in the inbox.
> 
>  This is a feature I'd like to put into the core of notmuch such
>  that one passes a query to match messages and then also a second
>  query to filter based on the collected tags in threads. Something
>  like:
> 
>   notmuch search tag:inbox --filter="not tag:muted"
> 

Looks like a good idea indeed.

>  2. There are other details available at the thread level that are not
> available at the level at which message-based searching happens.
> 
> A simple example of this would be the ability to search for threads
> with a single message, (perhaps checking to ensure that all requests
> had gotten at least one reply). But one can imagine more complex
> things as well, "Show me all threads where ImportantPerson sent a
> message and where I never replied in the thread."
> 
> For this kind of thing, I think we simply want to build on the
> output of "notmuch search". The current output isn't very usable for
> this, but with things like the structured json output, etc. (which,
> again, I hope to be merging soon), it would be quite easy to write
> new tools that accept that output and provide additional searching
> and filtering, etc. And that tool could provide lua-based scripting
> or whatever else is desired.
> 

Makes sense. Structured output would make things really simpler.

> So my feeling is that if anything can live outside of notmuch, then it
> should, and should simply build on top of notmuch output. (And we should
> fix notmuch output to support that well.)
> 

Works for me, as long as it solves my problems and as I stated above I
think it will.

> And anything that must live within notmuch (or is best supported there),
> we should see if we can't 

[notmuch] Thoughts on notmuch and Lua

2010-01-15 Thread Ali Polatel
Carl Worth yazm??:
> On Fri, 15 Jan 2010 13:16:00 +1300, martin f krafft  
> wrote:
> > Lua for hooks has the advantage that the hooks can be executed in
> > the context of manipulateable objects. On the other hand, hooks in
> > the style of run-parts directories are more flexible and accessible,
> > and could always be invoked as filters for the manipulateable data.
> 
> Good point.
> 
> One thing that notmuch has in its favor already is that there's a
> command-line interface that provides all of the interesting
> functionality. So it's already a fairly trivial matter to "hook" things
> like "notmuch new" by writing a script in whatever language you prefer
> to invoke things like "notmuch search" and "notmuch tag".
> 
> And that's what I'm doing already, (with a shell script), to tag
> newly-arrived messages.
> 
> The only part that's really missing here is a directory where scripts
> could be dropped in and get automatically invoked.
> 
> What do you think, Ali? Would an approach like that satisfy the things
> you had in mind for hooks?
> 

It might, here are some thoughts and questions to help you elaborate:

- How will these scripts manipulate data?
  e.g.: A "tagger" script may get the new mail from stdin and print out
  the new tags which notmuch will read and apply to the message.
  A "search-filter" script may get search results from stdin and filter
  them. Just my initial thoughts.

This script approach has both upsides and downsides. I have some
experience about this because I wrote a tool called mpdcron? which
executes hooks based on mpd events. First I thought it would be cool to
execute scripts based on events by passing data using environment
variables. However this approach didn't give hooks enough power to save
state information etc. so I decided to add module support through
GModule.

I may be going a bit off topic here but what I'm trying to explain is
scripts may not give power-users enough options and is practically
slower than having Lua, or another scripting language, support. In my
humble opinion the former is just a hack while the latter is the proper
way to do it.

P.S.: As I stated in the beginning you could have elaborated what you
meant by script support and I'm just commenting on what I've understood.

?: http://alip.github.com/mpdcron/

> -Carl

-- 
Regards,
Ali Polatel
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20100115/43640272/attachment.pgp>


Re: [notmuch] Thoughts on notmuch and Lua

2010-01-15 Thread Ali Polatel
Carl Worth yazmış:
 On Fri, 15 Jan 2010 13:16:00 +1300, martin f krafft madd...@madduck.net 
 wrote:
  Lua for hooks has the advantage that the hooks can be executed in
  the context of manipulateable objects. On the other hand, hooks in
  the style of run-parts directories are more flexible and accessible,
  and could always be invoked as filters for the manipulateable data.
 
 Good point.
 
 One thing that notmuch has in its favor already is that there's a
 command-line interface that provides all of the interesting
 functionality. So it's already a fairly trivial matter to hook things
 like notmuch new by writing a script in whatever language you prefer
 to invoke things like notmuch search and notmuch tag.
 
 And that's what I'm doing already, (with a shell script), to tag
 newly-arrived messages.
 
 The only part that's really missing here is a directory where scripts
 could be dropped in and get automatically invoked.
 
 What do you think, Ali? Would an approach like that satisfy the things
 you had in mind for hooks?
 

It might, here are some thoughts and questions to help you elaborate:

- How will these scripts manipulate data?
  e.g.: A tagger script may get the new mail from stdin and print out
  the new tags which notmuch will read and apply to the message.
  A search-filter script may get search results from stdin and filter
  them. Just my initial thoughts.

This script approach has both upsides and downsides. I have some
experience about this because I wrote a tool called mpdcron¹ which
executes hooks based on mpd events. First I thought it would be cool to
execute scripts based on events by passing data using environment
variables. However this approach didn't give hooks enough power to save
state information etc. so I decided to add module support through
GModule.

I may be going a bit off topic here but what I'm trying to explain is
scripts may not give power-users enough options and is practically
slower than having Lua, or another scripting language, support. In my
humble opinion the former is just a hack while the latter is the proper
way to do it.

P.S.: As I stated in the beginning you could have elaborated what you
meant by script support and I'm just commenting on what I've understood.

¹: http://alip.github.com/mpdcron/

 -Carl

-- 
Regards,
Ali Polatel


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


  1   2   >