[PATCH] python: update bindings for new count API

2015-09-26 Thread David Bremner
Note that any mismatches are not detected until runtime (if at all)
with the python bindings, so tests are crucial
---
 bindings/python/notmuch/query.py | 24 
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/bindings/python/notmuch/query.py b/bindings/python/notmuch/query.py
index 94773ac..378aa47 100644
--- a/bindings/python/notmuch/query.py
+++ b/bindings/python/notmuch/query.py
@@ -17,7 +17,7 @@ along with notmuch.  If not, see 
.
 Copyright 2010 Sebastian Spaeth 
 """
 
-from ctypes import c_char_p, c_uint
+from ctypes import c_char_p, c_uint, POINTER, byref
 from .globals import (
 nmlib,
 Enum,
@@ -178,8 +178,8 @@ class Query(object):
 raise NullPointerError
 return Messages(msgs_p, self)
 
-_count_messages = nmlib.notmuch_query_count_messages
-_count_messages.argtypes = [NotmuchQueryP]
+_count_messages = nmlib.notmuch_query_count_messages_st
+_count_messages.argtypes = [NotmuchQueryP, POINTER(c_uint)]
 _count_messages.restype = c_uint
 
 def count_messages(self):
@@ -191,10 +191,14 @@ class Query(object):
 :rtype:   int
 '''
 self._assert_query_is_initialized()
-return Query._count_messages(self._query)
-
-_count_threads = nmlib.notmuch_query_count_threads
-_count_threads.argtypes = [NotmuchQueryP]
+count = c_uint(0)
+status = Query._count_messages(self._query, byref(count))
+if status != 0:
+raise NotmuchError(status)
+return count.value
+
+_count_threads = nmlib.notmuch_query_count_threads_st
+_count_threads.argtypes = [NotmuchQueryP, POINTER(c_uint)]
 _count_threads.restype = c_uint
 
 def count_threads(self):
@@ -210,7 +214,11 @@ class Query(object):
 :rtype:   int
 '''
 self._assert_query_is_initialized()
-return Query._count_threads(self._query)
+count = c_uint(0)
+status = Query._count_threads(self._query, byref(count))
+if status != 0:
+raise NotmuchError(status)
+return count.value
 
 _destroy = nmlib.notmuch_query_destroy
 _destroy.argtypes = [NotmuchQueryP]
-- 
2.5.3

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


[patch v3.1] cli: update to use new count API

2015-09-26 Thread David Bremner
Essentially replace each call to notmuch_count_* with the corresponding
_st call, followed by print_status_query.
---
 notmuch-count.c  | 12 ++--
 notmuch-reply.c  |  7 ++-
 notmuch-search.c | 16 ++--
 notmuch-show.c   |  7 ++-
 4 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/notmuch-count.c b/notmuch-count.c
index be3e236..0b6e6f5 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -75,9 +75,11 @@ print_count (notmuch_database_t *notmuch, const char 
*query_str,
 notmuch_query_t *query;
 size_t i;
 int count;
+unsigned int ucount;
 unsigned long revision;
 const char *uuid;
 int ret = 0;
+notmuch_status_t status;
 
 query = notmuch_query_create (notmuch, query_str);
 if (query == NULL) {
@@ -90,10 +92,16 @@ print_count (notmuch_database_t *notmuch, const char 
*query_str,
 
 switch (output) {
 case OUTPUT_MESSAGES:
-   printf ("%u", notmuch_query_count_messages (query));
+   status = notmuch_query_count_messages_st (query, &ucount);
+   if (print_status_query ("notmuch count", query, status))
+   return -1;
+   printf ("%u", ucount);
break;
 case OUTPUT_THREADS:
-   printf ("%u", notmuch_query_count_threads (query));
+   status = notmuch_query_count_threads_st (query, &ucount);
+   if (print_status_query ("notmuch count", query, status))
+   return -1;
+   printf ("%u", ucount);
break;
 case OUTPUT_FILES:
count = count_files (query);
diff --git a/notmuch-reply.c b/notmuch-reply.c
index fd6a1ec..1357142 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -655,9 +655,14 @@ notmuch_reply_format_sprinter(void *ctx,
 notmuch_messages_t *messages;
 notmuch_message_t *message;
 mime_node_t *node;
+unsigned count;
 notmuch_status_t status;
 
-if (notmuch_query_count_messages (query) != 1) {
+status = notmuch_query_count_messages_st (query, &count);
+if (print_status_query ("notmuch reply", query, status))
+   return 1;
+
+if (count != 1) {
fprintf (stderr, "Error: search term did not match precisely one 
message.\n");
return 1;
 }
diff --git a/notmuch-search.c b/notmuch-search.c
index 44e582c..6d08c25 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -121,7 +121,13 @@ do_search_threads (search_context_t *ctx)
 notmuch_status_t status;
 
 if (ctx->offset < 0) {
-   ctx->offset += notmuch_query_count_threads (ctx->query);
+   unsigned count;
+   notmuch_status_t status;
+   status = notmuch_query_count_threads_st (ctx->query, &count);
+   if (print_status_query ("notmuch search", ctx->query, status))
+   return 1;
+
+   ctx->offset += count;
if (ctx->offset < 0)
ctx->offset = 0;
 }
@@ -521,7 +527,13 @@ do_search_messages (search_context_t *ctx)
 notmuch_status_t status;
 
 if (ctx->offset < 0) {
-   ctx->offset += notmuch_query_count_messages (ctx->query);
+   unsigned count;
+   notmuch_status_t status;
+   status = notmuch_query_count_messages_st (ctx->query, &count);
+   if (print_status_query ("notmuch search", ctx->query, status))
+   return 1;
+
+   ctx->offset += count;
if (ctx->offset < 0)
ctx->offset = 0;
 }
diff --git a/notmuch-show.c b/notmuch-show.c
index e054808..5a83c60 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -896,8 +896,13 @@ do_show_single (void *ctx,
 notmuch_messages_t *messages;
 notmuch_message_t *message;
 notmuch_status_t status;
+unsigned int count;
 
-if (notmuch_query_count_messages (query) != 1) {
+status = notmuch_query_count_messages_st (query, &count);
+if (print_status_query ("notmuch show", query, status))
+   return 1;
+
+if (count != 1) {
fprintf (stderr, "Error: search term did not match precisely one 
message.\n");
return 1;
 }
-- 
2.5.3

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


[Patch v3 1/4] cli/count: simplify and document return value of print_count

2015-09-26 Thread David Bremner
Essentially a cosmetic change.
---
 notmuch-count.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/notmuch-count.c b/notmuch-count.c
index 09613e6..be3e236 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -67,6 +67,7 @@ count_files (notmuch_query_t *query)
 return count;
 }
 
+/* return 0 on success, -1 on failure */
 static int
 print_count (notmuch_database_t *notmuch, const char *query_str,
 const char **exclude_tags, size_t exclude_tags_length, int output, 
int print_lastmod)
@@ -81,7 +82,7 @@ print_count (notmuch_database_t *notmuch, const char 
*query_str,
 query = notmuch_query_create (notmuch, query_str);
 if (query == NULL) {
fprintf (stderr, "Out of memory\n");
-   return 1;
+   return -1;
 }
 
 for (i = 0; i < exclude_tags_length; i++)
-- 
2.5.3

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


[Patch v3 3/4] cli: update to use new count API

2015-09-26 Thread David Bremner
Essentially replace each call to notmuch_count_* with the corresponding
_st call, followed by print_status_query.
---
 notmuch-count.c  | 12 ++--
 notmuch-reply.c  |  7 ++-
 notmuch-search.c | 16 ++--
 notmuch-show.c   |  7 ++-
 4 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/notmuch-count.c b/notmuch-count.c
index be3e236..0b6e6f5 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -75,9 +75,11 @@ print_count (notmuch_database_t *notmuch, const char 
*query_str,
 notmuch_query_t *query;
 size_t i;
 int count;
+unsigned int ucount;
 unsigned long revision;
 const char *uuid;
 int ret = 0;
+notmuch_status_t status;
 
 query = notmuch_query_create (notmuch, query_str);
 if (query == NULL) {
@@ -90,10 +92,16 @@ print_count (notmuch_database_t *notmuch, const char 
*query_str,
 
 switch (output) {
 case OUTPUT_MESSAGES:
-   printf ("%u", notmuch_query_count_messages (query));
+   status = notmuch_query_count_messages_st (query, &ucount);
+   if (print_status_query ("notmuch count", query, status))
+   return -1;
+   printf ("%u", ucount);
break;
 case OUTPUT_THREADS:
-   printf ("%u", notmuch_query_count_threads (query));
+   status = notmuch_query_count_threads_st (query, &ucount);
+   if (print_status_query ("notmuch count", query, status))
+   return -1;
+   printf ("%u", ucount);
break;
 case OUTPUT_FILES:
count = count_files (query);
diff --git a/notmuch-reply.c b/notmuch-reply.c
index fd6a1ec..1357142 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -655,9 +655,14 @@ notmuch_reply_format_sprinter(void *ctx,
 notmuch_messages_t *messages;
 notmuch_message_t *message;
 mime_node_t *node;
+unsigned count;
 notmuch_status_t status;
 
-if (notmuch_query_count_messages (query) != 1) {
+status = notmuch_query_count_messages_st (query, &count);
+if (print_status_query ("notmuch reply", query, status))
+   return 1;
+
+if (count != 1) {
fprintf (stderr, "Error: search term did not match precisely one 
message.\n");
return 1;
 }
diff --git a/notmuch-search.c b/notmuch-search.c
index 44e582c..56895e0 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -121,7 +121,13 @@ do_search_threads (search_context_t *ctx)
 notmuch_status_t status;
 
 if (ctx->offset < 0) {
-   ctx->offset += notmuch_query_count_threads (ctx->query);
+   unsigned count;
+   notmuch_status_t status;
+   status = notmuch_query_count_threads_st (ctx->query, &count);
+   if (print_status_query ("notmuch search", ctx->query, status)
+   return 1;
+
+   ctx->offset += count;
if (ctx->offset < 0)
ctx->offset = 0;
 }
@@ -521,7 +527,13 @@ do_search_messages (search_context_t *ctx)
 notmuch_status_t status;
 
 if (ctx->offset < 0) {
-   ctx->offset += notmuch_query_count_messages (ctx->query);
+   unsigned count;
+   notmuch_status_t status;
+   status = notmuch_query_count_messages_st (ctx->query, &count);
+   if (print_status_query ("notmuch search", ctx->query, status)
+   return 1;
+
+   ctx->offset += count;
if (ctx->offset < 0)
ctx->offset = 0;
 }
diff --git a/notmuch-show.c b/notmuch-show.c
index e054808..5a83c60 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -896,8 +896,13 @@ do_show_single (void *ctx,
 notmuch_messages_t *messages;
 notmuch_message_t *message;
 notmuch_status_t status;
+unsigned int count;
 
-if (notmuch_query_count_messages (query) != 1) {
+status = notmuch_query_count_messages_st (query, &count);
+if (print_status_query ("notmuch show", query, status))
+   return 1;
+
+if (count != 1) {
fprintf (stderr, "Error: search term did not match precisely one 
message.\n");
return 1;
 }
-- 
2.5.3

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


[Patch v3 2/4] lib: add versions of n_q_count_{message, threads} with status return

2015-09-26 Thread David Bremner
Although I think it's a pretty bad idea to continue using the old API,
this allows both a more gentle transition for clients of the library,
and allows us to break one monolithic change into a series
---
 lib/database.cc |  8 +++-
 lib/notmuch.h   | 52 ++--
 lib/query.cc| 47 +--
 3 files changed, 86 insertions(+), 21 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 6d0e5a6..cf93533 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1409,7 +1409,13 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
(NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER |
 NOTMUCH_FEATURE_LAST_MOD)) {
notmuch_query_t *query = notmuch_query_create (notmuch, "");
-   total += notmuch_query_count_messages (query);
+   unsigned msg_count;
+
+   status = notmuch_query_count_messages_st (query, &msg_count);
+   if (status)
+   goto DONE;
+
+   total += msg_count;
notmuch_query_destroy (query);
 }
 if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 8775683..5832f89 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -984,12 +984,31 @@ notmuch_threads_destroy (notmuch_threads_t *threads);
  * This function performs a search and returns the number of matching
  * messages.
  *
- * If a Xapian exception occurs, this function may return 0 (after
- * printing a message).
+ * @returns
+ *
+ * NOTMUCH_STATUS_SUCCESS: query complete successfully.
+ *
+ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The
+ *  value of *count is not defined.
  */
-unsigned
+notmuch_status_t
+notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count);
+
+/**
+ * like notmuch_query_count_messages_st, but without a status return
+ *
+ * May return 0 in the case of errors.
+ *
+ * @deprecated Deprecated since libnotmuch 4.3 (notmuch 0.21). Please
+ * use notmuch_query_count_messages_st instead.
+ */
+NOTMUCH_DEPRECATED(4,3)
+unsigned int
 notmuch_query_count_messages (notmuch_query_t *query);
 
+
+
+
 /**
  * Return the number of threads matching a search.
  *
@@ -998,13 +1017,34 @@ notmuch_query_count_messages (notmuch_query_t *query);
  * search.
  *
  * Note that this is a significantly heavier operation than
- * notmuch_query_count_messages().
+ * notmuch_query_count_messages{_st}().
  *
- * If an error occurs, this function may return 0.
+ * @returns
+ *
+ * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value
+ *  of *count is not defined
+
+ * NOTMUCH_STATUS_SUCCESS: query complete successfully.
+ *
+ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The
+ *  value of *count is not defined.
  */
-unsigned
+notmuch_status_t
+notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count);
+
+/**
+ * like notmuch_query_count_threads, but without a status return.
+ *
+ * May return 0 in case of errors.
+ *
+ * @deprecated Deprecated as of libnotmuch 4.3 (notmuch 0.21). Please
+ * use notmuch_query_count_threads_st instead.
+ */
+NOTMUCH_DEPRECATED(4,3)
+unsigned int
 notmuch_query_count_threads (notmuch_query_t *query);
 
+
 /**
  * Get the thread ID of 'thread'.
  *
diff --git a/lib/query.cc b/lib/query.cc
index 8cf0a07..8419b2e 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -541,9 +541,19 @@ notmuch_threads_destroy (notmuch_threads_t *threads)
 talloc_free (threads);
 }
 
-unsigned
+unsigned int
 notmuch_query_count_messages (notmuch_query_t *query)
 {
+notmuch_status_t status;
+unsigned int count;
+
+status = notmuch_query_count_messages_st (query, &count);
+return status ? 0 : count;
+}
+
+notmuch_status_t
+notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)
+{
 notmuch_database_t *notmuch = query->notmuch;
 const char *query_string = query->query_string;
 Xapian::doccount count = 0;
@@ -605,35 +615,44 @@ notmuch_query_count_messages (notmuch_query_t *query)
   "Query string was: %s\n",
   error.get_msg().c_str(),
   query->query_string);
-
+   return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
 }
 
-return count;
+*count_out = count;
+return NOTMUCH_STATUS_SUCCESS;
 }
 
 unsigned
 notmuch_query_count_threads (notmuch_query_t *query)
 {
+notmuch_status_t status;
+unsigned int count;
+
+status = notmuch_query_count_threads_st (query, &count);
+return status ? 0 : count;
+}
+
+notmuch_status_t
+notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count)
+{
 notmuch_messages_t *messages;
 GHashTable *hash;
-unsigned int count;
 notmuch_sort_t sort;
-notmuch_status_t status;
+notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
 
 sort = query->sort;
 query->sort = NOTMUCH_SORT_UNSORTED;
-status = notmuch_query_search_messages_

[Patch v3 4/4] ruby: use new count API

2015-09-26 Thread David Bremner
This change of replacing ignoring errors with exceptions is intended,
and indeed one of the main motivations for the libnotmuch API changes.
---
 bindings/ruby/query.c | 24 ++--
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c
index a7dacba..f87700a 100644
--- a/bindings/ruby/query.c
+++ b/bindings/ruby/query.c
@@ -173,14 +173,16 @@ VALUE
 notmuch_rb_query_count_messages (VALUE self)
 {
 notmuch_query_t *query;
+notmuch_status_t status;
+unsigned int count;
 
 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 UINT2NUM(notmuch_query_count_messages(query));
+status = notmuch_query_count_messages_st (query, &count);
+if (status)
+   notmuch_rb_status_raise (status);
+
+return UINT2NUM(count);
 }
 
 /*
@@ -192,12 +194,14 @@ VALUE
 notmuch_rb_query_count_threads (VALUE self)
 {
 notmuch_query_t *query;
+notmuch_status_t status;
+unsigned int count;
 
 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 UINT2NUM(notmuch_query_count_threads(query));
+status = notmuch_query_count_threads_st (query, &count);
+if (status)
+   notmuch_rb_status_raise (status);
+
+return UINT2NUM(count);
 }
-- 
2.5.3

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


Version 3 of count API changes

2015-09-26 Thread David Bremner
These are in some sense more urgent than than the search API changes
because the current API overloads a legitimate return value with an
error indicator.

Compared to the last version, these mainly use print_status_query.

Also, in contrast to the search API changes, these do not introduce
any new deprecation warnings (at least if the whole series is
applied).

TBH version 3 is just a guess.
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH v2] nmbug-status: add support for specifying sort order for each view

2015-09-26 Thread W. Trevor King
Looks good to me ;).

Cheers,
Trevor

-- 
This email may be signed or encrypted with GnuPG (http://www.gnupg.org).
For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy


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


Re: [PATCH 8/8] debian: add gpgsm as build dependency

2015-09-26 Thread Daniel Kahn Gillmor
On Sun 2015-08-16 13:41:16 -0400, David Bremner wrote:
> It's not needed for the actual build, but it is needed to run
> the SMIME tests.
> ---
>  debian/control | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/debian/control b/debian/control
> index 05cd04f..37ecedd 100644
> --- a/debian/control
> +++ b/debian/control
> @@ -22,6 +22,7 @@ Build-Depends:
>   emacs23-nox | emacs23 (>=23~) | emacs23-lucid (>=23~),
>   gdb [!s390x !ia64 !armel],
>   dtach (>= 0.8),
> + gpgsm, 
>   bash-completion (>=1.9.0~)
>  Standards-Version: 3.9.6
>  Homepage: http://notmuchmail.org/
> -- 
> 2.5.0
>

Apparently you can now indicate that the build-dep is only necessary for
tests with , like so:

--- a/debian/control
+++ b/debian/control
@@ -22,6 +22,7 @@ Build-Depends:
  emacs23-nox | emacs23 (>=23~) | emacs23-lucid (>=23~),
  gdb [!s390x !ia64 !armel],
  dtach (>= 0.8),
+ gpgsm , 
  bash-completion (>=1.9.0~)
 Standards-Version: 3.9.6
 Homepage: http://notmuchmail.org/


See
https://wiki.debian.org/BuildProfileSpec#Build-Depends_syntax_extension_.28restriction_formulas.29
for more details.

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


Re: [PATCH] lib: add support for date:..! to mean date:..

2015-09-26 Thread Tomi Ollila
On Sat, Sep 26 2015, David Bremner  wrote:

> Jani Nikula  writes:
>
>> It doesn't seem likely we can support simple date: expanding to
>> date:.. any time soon. (This can be done with a future
>> version of Xapian, or with a custom query query parser.) In the mean
>> time, provide shorthand date:..! to mean the same. This is
>> useful, as the expansion takes place before interpetation, and we can
>> use, for example, date:yesterday..! to match from beginning of
>> yesterday to end of yesterday.
>
> pushed. At some point we probably want a NEWS item.

If it is in the NEWS, it is perpetual, otoh if only in documentation we
could theoretically deprecate and remove it easier in the future ... ;p

> d

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


Re: [PATCH 6/8] cli: crypto: S/MIME verification support

2015-09-26 Thread Jani Nikula
On Sun, 16 Aug 2015, David Bremner  wrote:
> From: Jani Nikula 
>
> notmuch-show --verify will now also process S/MIME multiparts if
> encountered. Requires gmime-2.6 and gpgsm.
>
> Based on work by Jameson Graef Rollins .
> ---
>  crypto.c   | 50 ++
>  notmuch-client.h   |  7 +--
>  test/T355-smime.sh |  1 -
>  3 files changed, 55 insertions(+), 3 deletions(-)
>
> diff --git a/crypto.c b/crypto.c
> index 11c167e..ce683d2 100644
> --- a/crypto.c
> +++ b/crypto.c
> @@ -43,6 +43,51 @@ create_gpg_context (notmuch_crypto_t *crypto)
>  return gpgctx;
>  }
>  
> +/* Create a PKCS7 context (GMime 2.6) */
> +static notmuch_crypto_context_t *
> +create_pkcs7_context (notmuch_crypto_t *crypto)
> +{
> +notmuch_crypto_context_t *pkcs7ctx;
> +
> +if (crypto->pkcs7ctx)
> + return crypto->pkcs7ctx;
> +
> +/* TODO: GMimePasswordRequestFunc */
> +pkcs7ctx = g_mime_pkcs7_context_new (NULL);
> +if (! pkcs7ctx) {
> + fprintf (stderr, "Failed to construct pkcs7 context.\n");
> + return NULL;
> +}
> +crypto->pkcs7ctx = pkcs7ctx;
> +
> +g_mime_pkcs7_context_set_always_trust ((GMimePkcs7Context *) pkcs7ctx,
> +FALSE);
> +
> +return pkcs7ctx;
> +}
> +
> +static const struct {
> +const char *protocol;
> +notmuch_crypto_context_t *(*get_context) (notmuch_crypto_t *crypto);
> +} protocols[] = {
> +{
> + .protocol = "application/pgp-signature",
> + .get_context = create_gpg_context,
> +},
> +{
> + .protocol = "application/pgp-encrypted",
> + .get_context = create_gpg_context,
> +},
> +{
> + .protocol = "application/pkcs7-signature",
> + .get_context = create_pkcs7_context,
> +},
> +{
> + .protocol = "application/x-pkcs7-signature",
> + .get_context = create_pkcs7_context,
> +},
> +};

The array itself should be added in patch 2 as it depends on it, and
this patch should only add the pkcs7 ones. I guess this got broken at
some rebase.

BR,
Jani.


> +
>  /* for the specified protocol return the context pointer (initializing
>   * if needed) */
>  notmuch_crypto_context_t *
> @@ -81,5 +126,10 @@ notmuch_crypto_cleanup (notmuch_crypto_t *crypto)
>   crypto->gpgctx = NULL;
>  }
>  
> +if (crypto->pkcs7ctx) {
> + g_object_unref (crypto->pkcs7ctx);
> + crypto->pkcs7ctx = NULL;
> +}
> +
>  return 0;
>  }
> diff --git a/notmuch-client.h b/notmuch-client.h
> index 1f82656..774b620 100644
> --- a/notmuch-client.h
> +++ b/notmuch-client.h
> @@ -31,6 +31,8 @@
>  #include 
>  
>  typedef GMimeCryptoContext notmuch_crypto_context_t;
> +/* This is automatically included only since gmime 2.6.10 */
> +#include 
>  
>  #include "notmuch.h"
>  
> @@ -69,6 +71,7 @@ typedef struct notmuch_show_format {
>  
>  typedef struct notmuch_crypto {
>  notmuch_crypto_context_t* gpgctx;
> +notmuch_crypto_context_t* pkcs7ctx;
>  notmuch_bool_t verify;
>  notmuch_bool_t decrypt;
>  const char *gpgpath;
> @@ -406,8 +409,8 @@ struct mime_node {
>  /* Construct a new MIME node pointing to the root message part of
>   * message. If crypto->verify is true, signed child parts will be
>   * verified. If crypto->decrypt is true, encrypted child parts will be
> - * decrypted.  If crypto->gpgctx is NULL, it will be lazily
> - * initialized.
> + * decrypted.  If the crypto contexts (crypto->gpgctx or
> + * crypto->pkcs7) are NULL, they will be lazily initialized.
>   *
>   * Return value:
>   *
> diff --git a/test/T355-smime.sh b/test/T355-smime.sh
> index b3cc76e..caedf5e 100755
> --- a/test/T355-smime.sh
> +++ b/test/T355-smime.sh
> @@ -56,7 +56,6 @@ EOF
>  test_expect_equal_file OUTPUT EXPECTED
>  
>  test_begin_subtest "signature verification (notmuch CLI)"
> -test_subtest_known_broken
>  output=$(notmuch show --format=json --verify subject:"test signed message 
> 001" \
>  | notmuch_json_show_sanitize \
>  | sed -e 's|"created": [1234567890]*|"created": 946728000|' \
> -- 
> 2.5.0
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v2] nmbug-status: add support for specifying sort order for each view

2015-09-26 Thread Jani Nikula
Let each view have a "sort" key, typically used with values
"oldest-first" or "newest-first" (although all values in Query.SORT
are accepted), and sort the results accordingly. Oldest first remains
the default.

The dynamic approach of mapping sort values is as suggested by
W. Trevor King .
---
 devel/nmbug/nmbug-status | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/devel/nmbug/nmbug-status b/devel/nmbug/nmbug-status
index e845c2a5c8f7..a289798e3cc1 100755
--- a/devel/nmbug/nmbug-status
+++ b/devel/nmbug/nmbug-status
@@ -156,11 +156,20 @@ class Page (object):
 stream.write(self.footer)
 
 def _write_view(self, database, view, stream):
+# sort order, default to oldest-first
+sort_key = view.get('sort', 'oldest-first')
+# dynamically accept all values in Query.SORT
+sort_attribute = sort_key.upper().replace('-', '_')
+try:
+sort = getattr(notmuch.Query.SORT, sort_attribute)
+except AttributeError:
+raise ConfigError('Invalid sort setting for {}: {!r}'.format(
+view['title'], sort_key))
 if 'query-string' not in view:
 query = view['query']
 view['query-string'] = ' and '.join(query)
 q = notmuch.Query(database, view['query-string'])
-q.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
+q.set_sort(sort)
 threads = self._get_threads(messages=q.search_messages())
 self._write_view_header(view=view, stream=stream)
 self._write_threads(threads=threads, stream=stream)
-- 
2.1.4

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


[PATCH] completion: handle notmuch address --deduplicate= option

2015-09-26 Thread Jani Nikula
Complete notmuch address --deduplicate=(no|mailbox|address).
---
 completion/notmuch-completion.bash | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/completion/notmuch-completion.bash 
b/completion/notmuch-completion.bash
index 960275d1f672..68b069013655 100644
--- a/completion/notmuch-completion.bash
+++ b/completion/notmuch-completion.bash
@@ -369,12 +369,16 @@ _notmuch_address()
COMPREPLY=( $( compgen -W "true false flag all" -- "${cur}" ) )
return
;;
+   --deduplicate)
+   COMPREPLY=( $( compgen -W "no mailbox address" -- "${cur}" ) )
+   return
+   ;;
 esac
 
 ! $split &&
 case "${cur}" in
-*)
-   local options="--format= --output= --sort= --exclude="
+   local options="--format= --output= --sort= --exclude= 
--deduplicate="
compopt -o nospace
COMPREPLY=( $(compgen -W "$options" -- ${cur}) )
;;
-- 
2.1.4

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


Re: [PATCH v2 0/9] cli: alternative address deduplication

2015-09-26 Thread David Bremner
David Bremner  writes:

> Jani Nikula  writes:
>
>> This is v2 of id:cover.1440859765.git.j...@nikula.org addressing review
>> from the first (or rfc) version. Test are still missing, but everything
>> else should be in place. (At least patches 1, 2, and 5 could be pushed
>> without additional tests.)
>
> I pushed 1, 2, and 5.

I pushed the remaining patches in the series.

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


[PATCH 1/2] lib: content disposition values are not case-sensitive

2015-09-26 Thread Jani Nikula
Per RFC 2183, the values for Content-Disposition values are not
case-sensitive. While at it, use the gmime function for getting at the
disposition string instead of referencing the field directly.

This fixes "attachment" tagging and filename term generation for
attachments while indexing.
---
 lib/index.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/index.cc b/lib/index.cc
index e81aa8190288..f166aefd2fc1 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -377,7 +377,8 @@ _index_mime_part (notmuch_message_t *message,
 
 disposition = g_mime_object_get_content_disposition (part);
 if (disposition &&
-   strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
+   strcasecmp (g_mime_content_disposition_get_disposition (disposition),
+   GMIME_DISPOSITION_ATTACHMENT) == 0)
 {
const char *filename = g_mime_part_get_filename (GMIME_PART (part));
 
-- 
2.1.4

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


[PATCH 2/2] cli: content disposition values are not case-sensitive

2015-09-26 Thread Jani Nikula
Per RFC 2183, the values for Content-Disposition values are not
case-sensitive. While at it, use the gmime function for getting at the
disposition string instead of referencing the field directly.

This fixes attachment display and quoting in notmuch show and reply,
respectively.
---
 notmuch-reply.c | 3 ++-
 notmuch-show.c  | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index fd6a1ec1b11d..437c4ed5acc2 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -80,7 +80,8 @@ format_part_reply (mime_node_t *node)
show_text_part_content (node->part, stream_stdout, 
NOTMUCH_SHOW_TEXT_PART_REPLY);
g_object_unref(stream_stdout);
} else if (disposition &&
-  strcmp (disposition->disposition, 
GMIME_DISPOSITION_ATTACHMENT) == 0) {
+  strcasecmp (g_mime_content_disposition_get_disposition 
(disposition),
+  GMIME_DISPOSITION_ATTACHMENT) == 0) {
const char *filename = g_mime_part_get_filename (GMIME_PART 
(node->part));
printf ("Attachment: %s (%s)\n", filename,
g_mime_content_type_to_string (content_type));
diff --git a/notmuch-show.c b/notmuch-show.c
index e05480899b33..e9f4dffe0877 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -456,7 +456,8 @@ format_part_text (const void *ctx, sprinter_t *sp, 
mime_node_t *node,
g_mime_part_get_filename (GMIME_PART (node->part)) : NULL;
 
if (disposition &&
-   strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 
0)
+   strcasecmp (g_mime_content_disposition_get_disposition 
(disposition),
+   GMIME_DISPOSITION_ATTACHMENT) == 0)
part_type = "attachment";
else
part_type = "part";
-- 
2.1.4

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


Re: [bug] notmuch requires Content-Disposition mime header value to be lower case

2015-09-26 Thread Jani Nikula
On Fri, 18 Sep 2015, David Bremner  wrote:
> Johannes Schauer  writes:
>
>> Hi,
>>
>> Quoting David Bremner (2015-09-18 14:03:20)
>>> I'd recommend making your own new test, rather than modifying existing
>>> ones to test multiple things.  I'd also recommend using json / sexp
>>> output for your tests, since the ad-hoc text format is kindof
>>> semi-deprecated.
>>
>> can you take care of that? My goal was actually just to report this bug, not 
>> to
>> spend more time to develop a proper patch for it :)
>
> Consider the bug reported. At the moment I'm not completely convinced
> the patch is correct, never mind the tests. I agree it looks obvious
> enough, but the test results don't make sense to me yet.
>
>>
>> Also, a related problem occurs when the Content-Disposition header contains
>> UTF8 characters, in which case the header value gets encoded. Apparently
>> notmuch does not attempt to decode it. Example mime header:
>>
>> --===7161366892858136962==
>> Content-Type: application/pdf
>> MIME-Version: 1.0
>> Content-Transfer-Encoding: base64
>> Content-Disposition: =?utf-8?b?YXR0YWNobWVudDsgZmlsZW5hbWU9ImJlZ3LDvMOfdW5n?=
>>  =?utf-8?b?LnBkZiI=?=
>
> yes, that sounds like a distinct bug.

...in the sending end. Correct me if you think I'm wrong, but I don't
think that kind of encoding is allowed in Content-Disposition.

BR,
Jani.


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


Re: expose notmuch_database_new to libraries?

2015-09-26 Thread Jani Nikula
On Sat, 26 Sep 2015, "Wael M. Nasreddine"  wrote:
> I have a use case where I'd like to call 'notmuch new'
> programmatically via the bindings (custom Go bindings). Is it at all
> possible to expose notmuch_new_command[0] through lib/notmuch.h? The
> logic of notmuch_new_command would probably have to extracted to
> lib/database.cc for the exposure.

Short answer, no.

I'm afraid we don't have any documentation describing the split between
the library and the cli, apart from the library API. IIUC the history is
that it was originally all lumped together, and then the library was
abstracted as a toolbox for creating email programs on top. The cli
could be considered one such email program (and notmuch-emacs builds on
top of the cli).

I don't think the notmuch new command would be a good fit in the
library. It has too much application level policy that doesn't belong in
the library. That said, I could imagine coming up with another, higher
level library consisting of the main building blocks of the cli, and
having bindings to that. It's just that it's a non-trivial amount of
work, requiring a significant programming *and* review effort.

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