[PATCH 1/1] emacs: removed code attempting to support emaces prior to version 23
The support for emacs version 22 has not worked at least since September 2011 when I attempted to use it. I expanded the support in id:yf6ippgtbn0.fsf at taco2.nixu.fi but that was not enough and then I found it easier to switch to emacs 23. In case one wants to resurrect emacs 22 (or earlier!) support, pick the changes from the patch email referenced above. --- I suggested in IRC that we (first) deprecate this support, but as it has not worked like 18 months It is just simpler to drop it now. I'll do NEWS patch if this approach is accepted. emacs/notmuch-lib.el | 36 1 file changed, 36 deletions(-) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index f3ff3af..9b77379 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -203,19 +203,6 @@ user-friendly queries." (setq list (cdr list))) (nreverse out))) -;; This lets us avoid compiling these replacement functions when emacs -;; is sufficiently new enough to supply them alone. We do the macro -;; treatment rather than just wrapping our defun calls in a when form -;; specifically so that the compiler never sees the code on new emacs, -;; (since the code is triggering warnings that we don't know how to get -;; rid of. -;; -;; A more clever macro here would accept a condition and a list of forms. -(defmacro compile-on-emacs-prior-to-23 (form) - "Conditionally evaluate form only on emacs < emacs-23." - (list 'when (< emacs-major-version 23) - form)) - (defun notmuch-split-content-type (content-type) "Split content/type into 'content' and 'type'" (split-string content-type "/")) @@ -472,29 +459,6 @@ an error." (json-read))) (delete-file err-file) -;; Compatibility functions for versions of emacs before emacs 23. -;; -;; Both functions here were copied from emacs 23 with the following copyright: -;; -;; Copyright (C) 1985, 1986, 1992, 1994, 1995, 1999, 2000, 2001, 2002, 2003, -;; 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. -;; -;; and under the GPL version 3 (or later) exactly as notmuch itself. -(compile-on-emacs-prior-to-23 - (defun apply-partially (fun &rest args) - "Return a function that is a partial application of FUN to ARGS. -ARGS is a list of the first N arguments to pass to FUN. -The result is a new function which does the same as FUN, except that -the first N arguments are fixed at the values with which this function -was called." - (lexical-let ((fun fun) (args1 args)) - (lambda (&rest args2) (apply fun (append args1 args2)) - -(compile-on-emacs-prior-to-23 - (defun mouse-event-p (object) - "Return non-nil if OBJECT is a mouse click event." - (memq (event-basic-type object) '(mouse-1 mouse-2 mouse-3 mouse-movement - ;; This variable is used only buffer local, but it needs to be ;; declared globally first to avoid compiler warnings. (defvar notmuch-show-process-crypto nil) -- 1.8.0
[PATCH 1/1] emacs/notmuch.el: remove instruction to (require 'notmuch) in ~/.emacs
On Sun, Mar 31 2013, David Bremner wrote: > Tomi Ollila writes: > >> The (require 'notmuch) is unnecessary to be added to ~/.emacs for >> M-x notmuch or emacs -f notmuch to start it. >> >> If (require 'notmuch) is added to ~/.emacs it is loaded to every >> instance of emacs although it may not be used in majority of >> those instances (but if needed M-x notmuch will load it). > > Hi Tomi; > > Isn't an autoload needed if there is no require? Oh yes, you're right... A big thinko! Marked the patch 'obsolete'. I'll play with the autoload version... > d Thanks, Tomi
[PATCH] emacs: functions to import sender or recipient into BBDB
On Sun, Mar 31 2013, Daniel Bergey wrote: >>From fbaf5c568876a6f1e3d8c02446bd83331b6325f0 Mon Sep 17 00:00:00 2001 > From: Daniel Bergey > Date: Thu, 26 Jul 2012 15:44:01 -0400 > Subject: [PATCH] emacs: functions to import sender or recipients into BBDB > >>From a show buffer, notmuch-bbdb/snarf-from imports the sender into > bbdb. notmuch-bbdb/snarf-to imports all recipients. Newly imported > contacts are reported in the minibuffer / Messages buffer. > > Both functions use the BBDB parser to recognize email address formats. > --- LGTM, although git commit --amend is needed after git am to clean the junk in commit message (just deleting content). Tomi > This differs from the last version of the patch only in whitespace. In > addition to changes pointed out by Tomi Ollila, I fixed a ')' on a line > alone, and aligned the lines of notmuch-bbdb/header-by-name. > > I've been using this code (prior to whitespace changes) for a month and > a half, as far as testing goes. > > I wonder if I can get whitespace-mode to warn me about double-spacing > emacs/notmuch-address.el | 41 + > 1 file changed, 41 insertions(+) > > diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el > index 2bf762b..32c8490 100644 > --- a/emacs/notmuch-address.el > +++ b/emacs/notmuch-address.el > @@ -96,6 +96,47 @@ line." > (when (notmuch-address-locate-command notmuch-address-command) >(notmuch-address-message-insinuate)) > > +;; functions to add sender / recipients to BBDB > + > +(defun notmuch-bbdb/snarf-headers (headers) > + ;; Helper function to avoid code duplication in the two below > + ;; headers should have the same format as bbdb-get-addresses-headers > + > + ;; bbdb-get-addresses reads these > + ;; Ugh, pass-by-global > + (let ((addrs (bbdb-get-addresses nil nil 'notmuch-bbdb/get-header-content)) > + (bbdb-get-addresses-headers headers) ; headers to read > + (bbdb-gag-messages t)) ; suppress m/n processed message) > +(bbdb-update-records addrs t t)) > + > + (defun notmuch-bbdb/snarf-from () > +"Import the sender of the current message into BBDB" > +(interactive) > +(notmuch-bbdb/snarf-headers > + (list (assoc 'authors bbdb-get-addresses-headers > + > +(defun notmuch-bbdb/snarf-to () > + "Import all recipients of the current message into BBDB" > + (interactive) > + (notmuch-bbdb/snarf-headers > + (list (assoc 'recipients bbdb-get-addresses-headers > + > +(defvar notmuch-bbdb/header-by-name > + ;; both are case sensitive > + '( ("From" . :From) > + ("To" . :To) > + ("CC" . :Cc) > + ("BCC" . :Bcc) > + ("Resent-From" . nil) > + ("Reply-To" . nil) > + ("Resent-To" . nil) > + ("Resent-CC" . nil)) > + "Alist for dispatching header symbols as used by notmuch-show-get-header > +from strings as used by bbdb-get-addresses") > + > +(defun notmuch-bbdb/get-header-content (name) > + (notmuch-show-get-header (cdr (assoc name notmuch-bbdb/header-by-name > + > ;; > > (provide 'notmuch-address) > -- > 1.7.10.4 > > ___ > notmuch mailing list > notmuch at notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH 1/1] emacs/notmuch.el: remove instruction to (require 'notmuch) in ~/.emacs
The (require 'notmuch) is unnecessary to be added to ~/.emacs for M-x notmuch or emacs -f notmuch to start it. If (require 'notmuch) is added to ~/.emacs it is loaded to every instance of emacs although it may not be used in majority of those instances (but if needed M-x notmuch will load it). Preloading notmuch would speed up M-x notmuch a bit -- for emacs -f notmuch it doesn't bring any startup speed increase (if that would have mattered). --- emacs/notmuch.el | 7 +-- 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index e58c51d..ae9becd 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -34,12 +34,7 @@ ;; ;; to install it. ;; -;; Then, to actually run it, add: -;; -;; (require 'notmuch) -;; -;; to your ~/.emacs file, and then run "M-x notmuch" from within emacs, -;; or run: +;; Then, to actually run it, run "M-x notmuch" from within emacs, or run: ;; ;; emacs -f notmuch ;; -- 1.8.1.2
[PATCH v3 0/6] batch count for notmuch-hello speedup
On Sun, Mar 31 2013, Jani Nikula wrote: > This is v3 of id:cover.1362841844.git.jani at nikula.org, with the commit > messages of patches 1/6 and 3/6 fixed. No other changes. Thanks to > Jameson and Tomi for review, and of course Mark for the elisp part. +1 -- I verified there is no (accidental) changes between id:cover.1362841844.git.jani at nikula.org and id:cover.1364722841.git.jani at nikula.org > > BR, > Jani. Tomi > > Jani Nikula (5): > cli: remove useless talloc_strdup > cli: extract count printing to a separate function in notmuch count > cli: add --batch option to notmuch count > man: document notmuch count --batch and --input options > test: notmuch count --batch and --input options > > Mark Walters (1): > emacs: hello: use batch count > > emacs/notmuch-hello.el | 52 +- > man/man1/notmuch-count.1 | 20 + > notmuch-count.c | 111 > +++--- > test/count | 46 +++ > 4 files changed, 182 insertions(+), 47 deletions(-) > > -- > 1.7.10.4 > > ___ > notmuch mailing list > notmuch at notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH 1/1] emacs/notmuch.el: remove instruction to (require 'notmuch) in ~/.emacs
Tomi Ollila writes: > The (require 'notmuch) is unnecessary to be added to ~/.emacs for > M-x notmuch or emacs -f notmuch to start it. > > If (require 'notmuch) is added to ~/.emacs it is loaded to every > instance of emacs although it may not be used in majority of > those instances (but if needed M-x notmuch will load it). Hi Tomi; Isn't an autoload needed if there is no require? d
[PATCH] emacs: functions to import sender or recipient into BBDB
>From fbaf5c568876a6f1e3d8c02446bd83331b6325f0 Mon Sep 17 00:00:00 2001 From: Daniel Bergey Date: Thu, 26 Jul 2012 15:44:01 -0400 Subject: [PATCH] emacs: functions to import sender or recipients into BBDB >From a show buffer, notmuch-bbdb/snarf-from imports the sender into bbdb. notmuch-bbdb/snarf-to imports all recipients. Newly imported contacts are reported in the minibuffer / Messages buffer. Both functions use the BBDB parser to recognize email address formats. --- This differs from the last version of the patch only in whitespace. In addition to changes pointed out by Tomi Ollila, I fixed a ')' on a line alone, and aligned the lines of notmuch-bbdb/header-by-name. I've been using this code (prior to whitespace changes) for a month and a half, as far as testing goes. I wonder if I can get whitespace-mode to warn me about double-spacing emacs/notmuch-address.el | 41 + 1 file changed, 41 insertions(+) diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el index 2bf762b..32c8490 100644 --- a/emacs/notmuch-address.el +++ b/emacs/notmuch-address.el @@ -96,6 +96,47 @@ line." (when (notmuch-address-locate-command notmuch-address-command) (notmuch-address-message-insinuate)) +;; functions to add sender / recipients to BBDB + +(defun notmuch-bbdb/snarf-headers (headers) + ;; Helper function to avoid code duplication in the two below + ;; headers should have the same format as bbdb-get-addresses-headers + + ;; bbdb-get-addresses reads these + ;; Ugh, pass-by-global + (let ((addrs (bbdb-get-addresses nil nil 'notmuch-bbdb/get-header-content)) + (bbdb-get-addresses-headers headers) ; headers to read + (bbdb-gag-messages t)) ; suppress m/n processed message) +(bbdb-update-records addrs t t)) + + (defun notmuch-bbdb/snarf-from () +"Import the sender of the current message into BBDB" +(interactive) +(notmuch-bbdb/snarf-headers + (list (assoc 'authors bbdb-get-addresses-headers + +(defun notmuch-bbdb/snarf-to () + "Import all recipients of the current message into BBDB" + (interactive) + (notmuch-bbdb/snarf-headers + (list (assoc 'recipients bbdb-get-addresses-headers + +(defvar notmuch-bbdb/header-by-name + ;; both are case sensitive + '( ("From" . :From) + ("To" . :To) + ("CC" . :Cc) + ("BCC" . :Bcc) + ("Resent-From" . nil) + ("Reply-To" . nil) + ("Resent-To" . nil) + ("Resent-CC" . nil)) + "Alist for dispatching header symbols as used by notmuch-show-get-header +from strings as used by bbdb-get-addresses") + +(defun notmuch-bbdb/get-header-content (name) + (notmuch-show-get-header (cdr (assoc name notmuch-bbdb/header-by-name + ;; (provide 'notmuch-address) -- 1.7.10.4
[PATCH 1/1] emacs: removed code attempting to support emaces prior to version 23
The support for emacs version 22 has not worked at least since September 2011 when I attempted to use it. I expanded the support in id:yf6ippgtbn0@taco2.nixu.fi but that was not enough and then I found it easier to switch to emacs 23. In case one wants to resurrect emacs 22 (or earlier!) support, pick the changes from the patch email referenced above. --- I suggested in IRC that we (first) deprecate this support, but as it has not worked like 18 months It is just simpler to drop it now. I'll do NEWS patch if this approach is accepted. emacs/notmuch-lib.el | 36 1 file changed, 36 deletions(-) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index f3ff3af..9b77379 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -203,19 +203,6 @@ user-friendly queries." (setq list (cdr list))) (nreverse out))) -;; This lets us avoid compiling these replacement functions when emacs -;; is sufficiently new enough to supply them alone. We do the macro -;; treatment rather than just wrapping our defun calls in a when form -;; specifically so that the compiler never sees the code on new emacs, -;; (since the code is triggering warnings that we don't know how to get -;; rid of. -;; -;; A more clever macro here would accept a condition and a list of forms. -(defmacro compile-on-emacs-prior-to-23 (form) - "Conditionally evaluate form only on emacs < emacs-23." - (list 'when (< emacs-major-version 23) - form)) - (defun notmuch-split-content-type (content-type) "Split content/type into 'content' and 'type'" (split-string content-type "/")) @@ -472,29 +459,6 @@ an error." (json-read))) (delete-file err-file) -;; Compatibility functions for versions of emacs before emacs 23. -;; -;; Both functions here were copied from emacs 23 with the following copyright: -;; -;; Copyright (C) 1985, 1986, 1992, 1994, 1995, 1999, 2000, 2001, 2002, 2003, -;; 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. -;; -;; and under the GPL version 3 (or later) exactly as notmuch itself. -(compile-on-emacs-prior-to-23 - (defun apply-partially (fun &rest args) - "Return a function that is a partial application of FUN to ARGS. -ARGS is a list of the first N arguments to pass to FUN. -The result is a new function which does the same as FUN, except that -the first N arguments are fixed at the values with which this function -was called." - (lexical-let ((fun fun) (args1 args)) - (lambda (&rest args2) (apply fun (append args1 args2)) - -(compile-on-emacs-prior-to-23 - (defun mouse-event-p (object) - "Return non-nil if OBJECT is a mouse click event." - (memq (event-basic-type object) '(mouse-1 mouse-2 mouse-3 mouse-movement - ;; This variable is used only buffer local, but it needs to be ;; declared globally first to avoid compiler warnings. (defvar notmuch-show-process-crypto nil) -- 1.8.0 ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH v4 01/12] tag-util: move out 'tag' command-line checks
On Thu, 24 Jan 2013, Peter Wang wrote: > parse_tag_command_line checked for two error conditions which are > specific to the 'tag' command. It can be reused for the forthcoming > notmuch 'insert' command if we move the checks out, into notmuch-tag.c. FYI, this patch no longer applies to master. Jani. > --- > notmuch-tag.c | 10 ++ > tag-util.c| 11 +++ > 2 files changed, 13 insertions(+), 8 deletions(-) > > diff --git a/notmuch-tag.c b/notmuch-tag.c > index d9daf8f..a901dad 100644 > --- a/notmuch-tag.c > +++ b/notmuch-tag.c > @@ -234,6 +234,16 @@ notmuch_tag_command (void *ctx, int argc, char *argv[]) > if (parse_tag_command_line (ctx, argc - opt_index, argv + opt_index, > &query_string, tag_ops)) > return 1; > + > + if (tag_op_list_size (tag_ops) == 0) { > + fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to > add or remove.\n"); > + return 1; > + } > + > + if (*query_string == '\0') { > + fprintf (stderr, "Error: notmuch tag requires at least one search > term.\n"); > + return 1; > + } > } > > config = notmuch_config_open (ctx, NULL, NULL); > diff --git a/tag-util.c b/tag-util.c > index 701d329..743d591 100644 > --- a/tag-util.c > +++ b/tag-util.c > @@ -188,16 +188,11 @@ parse_tag_command_line (void *ctx, int argc, char > **argv, > tag_op_list_append (tag_ops, argv[i] + 1, is_remove); > } > > -if (tag_op_list_size (tag_ops) == 0) { > - fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add > or remove.\n"); > - return TAG_PARSE_INVALID; > -} > - > *query_str = query_string_from_args (ctx, argc - i, &argv[i]); > > -if (*query_str == NULL || **query_str == '\0') { > - fprintf (stderr, "Error: notmuch tag requires at least one search > term.\n"); > - return TAG_PARSE_INVALID; > +if (*query_str == NULL) { > + fprintf (stderr, "Out of memory.\n"); > + return TAG_PARSE_OUT_OF_MEMORY; > } > > return TAG_PARSE_SUCCESS; > -- > 1.7.12.1 > > ___ > notmuch mailing list > notmuch at notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch
Re: [PATCH 1/1] emacs/notmuch.el: remove instruction to (require 'notmuch) in ~/.emacs
On Sun, Mar 31 2013, David Bremner wrote: > Tomi Ollila writes: > >> The (require 'notmuch) is unnecessary to be added to ~/.emacs for >> M-x notmuch or emacs -f notmuch to start it. >> >> If (require 'notmuch) is added to ~/.emacs it is loaded to every >> instance of emacs although it may not be used in majority of >> those instances (but if needed M-x notmuch will load it). > > Hi Tomi; > > Isn't an autoload needed if there is no require? Oh yes, you're right... A big thinko! Marked the patch 'obsolete'. I'll play with the autoload version... > d Thanks, Tomi ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
Re: [PATCH 1/1] emacs/notmuch.el: remove instruction to (require 'notmuch) in ~/.emacs
Tomi Ollila writes: > The (require 'notmuch) is unnecessary to be added to ~/.emacs for > M-x notmuch or emacs -f notmuch to start it. > > If (require 'notmuch) is added to ~/.emacs it is loaded to every > instance of emacs although it may not be used in majority of > those instances (but if needed M-x notmuch will load it). Hi Tomi; Isn't an autoload needed if there is no require? d ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH v3 6/6] emacs: hello: use batch count
From: Mark Walters This modifies notmuch hello to use the new count --batch functionality. It should give exactly the same results as before but under many conditions it should be much faster. In particular it is much faster for remote use. The code is a little ugly as it has to do some working out of the query when asking the query and some when dealing with the result. However, the code path is exactly the same in both local and remote use. --- emacs/notmuch-hello.el | 52 +--- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index 00b78e1..cda79f1 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -381,26 +381,38 @@ The result is the list of elements of the form (NAME QUERY COUNT). The values :show-empty-searches, :filter and :filter-count from options will be handled as specified for `notmuch-hello-insert-searches'." - (notmuch-remove-if-not - #'identity - (mapcar -(lambda (elem) - (let* ((name (car elem)) -(query-and-count (if (consp (cdr elem)) - ;; do we have a different query for the message count? - (cons (second elem) (third elem)) - (cons (cdr elem) (cdr elem -(message-count - (string-to-number - (notmuch-saved-search-count - (notmuch-hello-filtered-query (cdr query-and-count) - (or (plist-get options :filter-count) -(plist-get options :filter))) - (and (or (plist-get options :show-empty-searches) (> message-count 0)) -(list name (notmuch-hello-filtered-query -(car query-and-count) (plist-get options :filter)) - message-count -query-alist))) + (with-temp-buffer +(dolist (elem query-alist nil) + (let ((count-query (if (consp (cdr elem)) +;; do we have a different query for the message count? +(third elem) + (cdr elem + (insert +(notmuch-hello-filtered-query count-query + (or (plist-get options :filter-count) + (plist-get options :filter))) +"\n"))) + +(call-process-region (point-min) (point-max) notmuch-command +t t nil "count" "--batch") +(goto-char (point-min)) + +(notmuch-remove-if-not + #'identity + (mapcar + (lambda (elem) + (let ((name (car elem)) + (search-query (if (consp (cdr elem)) +;; do we have a different query for the message count? +(second elem) + (cdr elem))) + (message-count (prog1 (read (current-buffer)) + (forward-line 1 + (and (or (plist-get options :show-empty-searches) (> message-count 0)) + (list name (notmuch-hello-filtered-query + search-query (plist-get options :filter)) +message-count + query-alist (defun notmuch-hello-insert-buttons (searches) "Insert buttons for SEARCHES. -- 1.7.10.4
[PATCH v3 5/6] test: notmuch count --batch and --input options
--- test/count | 46 ++ 1 file changed, 46 insertions(+) diff --git a/test/count b/test/count index 879b114..05713fd 100755 --- a/test/count +++ b/test/count @@ -38,4 +38,50 @@ test_expect_equal \ "0" \ "`notmuch count --output=threads from:cworth and not from:cworth`" +test_begin_subtest "message count is the default for batch count" +notmuch count --batch >OUTPUT>EXPECTED +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "batch message count" +notmuch count --batch --output=messages >OUTPUT >EXPECTED +notmuch count --output=messages tag:inbox >>EXPECTED +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "batch thread count" +notmuch count --batch --output=threads >OUTPUT >EXPECTED +notmuch count --output=threads from:cworth and not from:cworth >>EXPECTED +notmuch count --output=threads foo >>EXPECTED +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "batch message count with input file" +cat >INPUT
[PATCH v3 4/6] man: document notmuch count --batch and --input options
--- man/man1/notmuch-count.1 | 20 1 file changed, 20 insertions(+) diff --git a/man/man1/notmuch-count.1 b/man/man1/notmuch-count.1 index 86a67fe..7fc4378 100644 --- a/man/man1/notmuch-count.1 +++ b/man/man1/notmuch-count.1 @@ -46,6 +46,26 @@ Output the number of matching threads. Specify whether to omit messages matching search.tag_exclude from the count (the default) or not. .RE + +.RS 4 +.TP 4 +.BR \-\-batch + +Read queries from a file (stdin by default), one per line, and output +the number of matching messages (or threads) to stdout, one per +line. On an empty input line the count of all messages (or threads) in +the database will be output. This option is not compatible with +specifying search terms on the command line. +.RE + +.RS 4 +.TP 4 +.BR "\-\-input=" + +Read input from given file, instead of from stdin. Implies +.BR --batch . +.RE + .RE .RE -- 1.7.10.4
[PATCH v3 3/6] cli: add --batch option to notmuch count
Add support for reading queries from stdin, one per line, and writing results to stdout, one per line. This will bring considerable performance improvements when utilized in Emacs notmuch-hello, especially so when running remote notmuch. --- notmuch-count.c | 52 ++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/notmuch-count.c b/notmuch-count.c index 630f036..8772cff 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -62,6 +62,27 @@ print_count (notmuch_database_t *notmuch, const char *query_str, return 0; } +static int +count_file (notmuch_database_t *notmuch, FILE *input, const char **exclude_tags, + size_t exclude_tags_length, int output) +{ +char *line = NULL; +ssize_t line_len; +size_t line_size; +int ret = 0; + +while (!ret && (line_len = getline (&line, &line_size, input)) != -1) { + chomp_newline (line); + ret = print_count (notmuch, line, exclude_tags, exclude_tags_length, + output); +} + +if (line) + free (line); + +return ret; +} + int notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) { @@ -72,6 +93,9 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) int exclude = EXCLUDE_TRUE; const char **search_exclude_tags = NULL; size_t search_exclude_tags_length = 0; +notmuch_bool_t batch = FALSE; +FILE *input = stdin; +char *input_file_name = NULL; int ret; notmuch_opt_desc_t options[] = { @@ -83,6 +107,8 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE }, { "false", EXCLUDE_FALSE }, { 0, 0 } } }, + { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 }, + { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 }, { 0, 0, 0, 0, 0 } }; @@ -92,6 +118,21 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) return 1; } +if (input_file_name) { + batch = TRUE; + input = fopen (input_file_name, "r"); + if (input == NULL) { + fprintf (stderr, "Error opening %s for reading: %s\n", +input_file_name, strerror (errno)); + return 1; + } +} + +if (batch && opt_index != argc) { + fprintf (stderr, "--batch and query string are not compatible\n"); + return 1; +} + if (notmuch_database_open (notmuch_config_get_database_path (config), NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much)) return 1; @@ -107,10 +148,17 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) (config, &search_exclude_tags_length); } -ret = print_count (notmuch, query_str, search_exclude_tags, - search_exclude_tags_length, output); +if (batch) + ret = count_file (notmuch, input, search_exclude_tags, + search_exclude_tags_length, output); +else + ret = print_count (notmuch, query_str, search_exclude_tags, + search_exclude_tags_length, output); notmuch_database_destroy (notmuch); +if (input != stdin) + fclose (input); + return ret; } -- 1.7.10.4
[PATCH v3 2/6] cli: extract count printing to a separate function in notmuch count
Make count printing on a query string reusable. No functional changes. --- notmuch-count.c | 59 +-- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/notmuch-count.c b/notmuch-count.c index c2f1b7d..630f036 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -32,16 +32,47 @@ enum { EXCLUDE_FALSE, }; +static int +print_count (notmuch_database_t *notmuch, const char *query_str, +const char **exclude_tags, size_t exclude_tags_length, int output) +{ +notmuch_query_t *query; +size_t i; + +query = notmuch_query_create (notmuch, query_str); +if (query == NULL) { + fprintf (stderr, "Out of memory\n"); + return 1; +} + +for (i = 0; i < exclude_tags_length; i++) + notmuch_query_add_tag_exclude (query, exclude_tags[i]); + +switch (output) { +case OUTPUT_MESSAGES: + printf ("%u\n", notmuch_query_count_messages (query)); + break; +case OUTPUT_THREADS: + printf ("%u\n", notmuch_query_count_threads (query)); + break; +} + +notmuch_query_destroy (query); + +return 0; +} + int notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) { notmuch_database_t *notmuch; -notmuch_query_t *query; char *query_str; int opt_index; int output = OUTPUT_MESSAGES; int exclude = EXCLUDE_TRUE; -unsigned int i; +const char **search_exclude_tags = NULL; +size_t search_exclude_tags_length = 0; +int ret; notmuch_opt_desc_t options[] = { { NOTMUCH_OPT_KEYWORD, &output, "output", 'o', @@ -71,33 +102,15 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) return 1; } -query = notmuch_query_create (notmuch, query_str); -if (query == NULL) { - fprintf (stderr, "Out of memory\n"); - return 1; -} - if (exclude == EXCLUDE_TRUE) { - const char **search_exclude_tags; - size_t search_exclude_tags_length; - search_exclude_tags = notmuch_config_get_search_exclude_tags (config, &search_exclude_tags_length); - for (i = 0; i < search_exclude_tags_length; i++) - notmuch_query_add_tag_exclude (query, search_exclude_tags[i]); } -switch (output) { -case OUTPUT_MESSAGES: - printf ("%u\n", notmuch_query_count_messages (query)); - break; -case OUTPUT_THREADS: - printf ("%u\n", notmuch_query_count_threads (query)); - break; -} +ret = print_count (notmuch, query_str, search_exclude_tags, + search_exclude_tags_length, output); -notmuch_query_destroy (query); notmuch_database_destroy (notmuch); -return 0; +return ret; } -- 1.7.10.4
[PATCH v3 1/6] cli: remove useless talloc_strdup
If the condition holds, query_string_from_args() has already returned a talloc allocated empty string. There's no need to duplicate that. --- notmuch-count.c |4 1 file changed, 4 deletions(-) diff --git a/notmuch-count.c b/notmuch-count.c index 390794f..c2f1b7d 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -71,10 +71,6 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) return 1; } -if (*query_str == '\0') { - query_str = talloc_strdup (config, ""); -} - query = notmuch_query_create (notmuch, query_str); if (query == NULL) { fprintf (stderr, "Out of memory\n"); -- 1.7.10.4
[PATCH v3 0/6] batch count for notmuch-hello speedup
This is v3 of id:cover.1362841844.git.jani at nikula.org, with the commit messages of patches 1/6 and 3/6 fixed. No other changes. Thanks to Jameson and Tomi for review, and of course Mark for the elisp part. BR, Jani. Jani Nikula (5): cli: remove useless talloc_strdup cli: extract count printing to a separate function in notmuch count cli: add --batch option to notmuch count man: document notmuch count --batch and --input options test: notmuch count --batch and --input options Mark Walters (1): emacs: hello: use batch count emacs/notmuch-hello.el | 52 +- man/man1/notmuch-count.1 | 20 + notmuch-count.c | 111 +++--- test/count | 46 +++ 4 files changed, 182 insertions(+), 47 deletions(-) -- 1.7.10.4
[PATCH v2 0/3] cli: clean up gmime 2.4 vs. 2.6 conditional build
On Sun, Mar 31 2013, Tomi Ollila wrote: > On Sat, Mar 30 2013, Jani Nikula wrote: > >> This is v2 of [1]. Added comments per David's request, and while at it, >> added a third patch to conform the existing conditional build in notmuch >> show to the same style. The whole series should have no functional >> changes, and thus v2 should have no functional changes since v1. ;) >> >> I have not tested this on gmime 2.4. > > I have gmime 2.4(.24) on this system. The code compiles and > exactly the same set of tests pass/fail as without this patch > (unfortunately this system cannot cope with just some of the > crypto patches, so I cannot give absolute guarantee: Ok, the failure cases below are just those which are changed in this patch. So I had to dig further... ... actually this 'PASS emacs delivery of encrypted message with attachment' fails to deliver the message. After the following change: --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -442,7 +442,8 @@ emacs_deliver_message () test_emacs \ "(let ((message-send-mail-function 'message-smtpmail-send-it) - (smtpmail-smtp-server \"localhost\") + (smtpmail-smtp-server 'local) + ;;(smtpmail-smtp-server \"localhost\") (smtpmail-smtp-service \"25025\")) (notmuch-hello) (notmuch-mua-mail) The failured cases below PASSes. (I've stumbled the same problem a few cases before but haven't figured out a good patch so far...) > > crypto: Testing PGP/MIME signature verification and decryption > PASS emacs delivery of signed message > PASS signature verification > PASS signature verification with full owner trust > PASS signature verification with signer key unavailable > PASS emacs delivery of encrypted message with attachment > FAIL decryption, --format=text > FAIL decryption, --format=json > FAIL decryption, --format=json, --part=4 > FAIL decrypt attachment (--part=5 --format=raw) > FAIL decryption failure with missing key > PASS emacs delivery of encrypted + signed message > FAIL decryption + signature verification > FAIL reply to encrypted message > FAIL signature verification with revoked key > > anyway, as said, exactly the same set fails without these pathes > > The reason for failure is most probably in my system and not something > w/ notmuch crypto support -- If I run `emacs foo.org.gpg` this just > hangs waiting me to give passphrase in (invisible?) curses request) > > So, bottom line: LGTM. > >> BR, >> Jani. > > Tomi > > >> [1] id:a9f12ba474fc51df71e2fd2b7a20a8d101729c6e.1362319765.git.jani at >> nikula.org >> >> Jani Nikula (3): >> cli: crypto: abstract gpg context creation for clarity >> cli: mime node: abstract decryption and signature verification >> cli: conform to same conditional build style as elsewhere in >> notmuch-show >> >> crypto.c | 66 - >> mime-node.c| 218 >> >> notmuch-show.c | 46 ++-- >> 3 files changed, 215 insertions(+), 115 deletions(-) >> >> -- >> 1.7.10.4
[PATCH v2 0/3] cli: clean up gmime 2.4 vs. 2.6 conditional build
On Sat, Mar 30 2013, Jani Nikula wrote: > This is v2 of [1]. Added comments per David's request, and while at it, > added a third patch to conform the existing conditional build in notmuch > show to the same style. The whole series should have no functional > changes, and thus v2 should have no functional changes since v1. ;) > > I have not tested this on gmime 2.4. I have gmime 2.4(.24) on this system. The code compiles and exactly the same set of tests pass/fail as without this patch (unfortunately this system cannot cope with just some of the crypto patches, so I cannot give absolute guarantee: crypto: Testing PGP/MIME signature verification and decryption PASS emacs delivery of signed message PASS signature verification PASS signature verification with full owner trust PASS signature verification with signer key unavailable PASS emacs delivery of encrypted message with attachment FAIL decryption, --format=text FAIL decryption, --format=json FAIL decryption, --format=json, --part=4 FAIL decrypt attachment (--part=5 --format=raw) FAIL decryption failure with missing key PASS emacs delivery of encrypted + signed message FAIL decryption + signature verification FAIL reply to encrypted message FAIL signature verification with revoked key anyway, as said, exactly the same set fails without these pathes The reason for failure is most probably in my system and not something w/ notmuch crypto support -- If I run `emacs foo.org.gpg` this just hangs waiting me to give passphrase in (invisible?) curses request) So, bottom line: LGTM. > BR, > Jani. Tomi > [1] id:a9f12ba474fc51df71e2fd2b7a20a8d101729c6e.1362319765.git.jani at > nikula.org > > Jani Nikula (3): > cli: crypto: abstract gpg context creation for clarity > cli: mime node: abstract decryption and signature verification > cli: conform to same conditional build style as elsewhere in > notmuch-show > > crypto.c | 66 - > mime-node.c| 218 > > notmuch-show.c | 46 ++-- > 3 files changed, 215 insertions(+), 115 deletions(-) > > -- > 1.7.10.4 > > ___ > notmuch mailing list > notmuch at notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch
Re: [PATCH] emacs: functions to import sender or recipient into BBDB
On Sun, Mar 31 2013, Daniel Bergey wrote: >>From fbaf5c568876a6f1e3d8c02446bd83331b6325f0 Mon Sep 17 00:00:00 2001 > From: Daniel Bergey > Date: Thu, 26 Jul 2012 15:44:01 -0400 > Subject: [PATCH] emacs: functions to import sender or recipients into BBDB > >>From a show buffer, notmuch-bbdb/snarf-from imports the sender into > bbdb. notmuch-bbdb/snarf-to imports all recipients. Newly imported > contacts are reported in the minibuffer / Messages buffer. > > Both functions use the BBDB parser to recognize email address formats. > --- LGTM, although git commit --amend is needed after git am to clean the junk in commit message (just deleting content). Tomi > This differs from the last version of the patch only in whitespace. In > addition to changes pointed out by Tomi Ollila, I fixed a ')' on a line > alone, and aligned the lines of notmuch-bbdb/header-by-name. > > I've been using this code (prior to whitespace changes) for a month and > a half, as far as testing goes. > > I wonder if I can get whitespace-mode to warn me about double-spacing > emacs/notmuch-address.el | 41 + > 1 file changed, 41 insertions(+) > > diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el > index 2bf762b..32c8490 100644 > --- a/emacs/notmuch-address.el > +++ b/emacs/notmuch-address.el > @@ -96,6 +96,47 @@ line." > (when (notmuch-address-locate-command notmuch-address-command) >(notmuch-address-message-insinuate)) > > +;; functions to add sender / recipients to BBDB > + > +(defun notmuch-bbdb/snarf-headers (headers) > + ;; Helper function to avoid code duplication in the two below > + ;; headers should have the same format as bbdb-get-addresses-headers > + > + ;; bbdb-get-addresses reads these > + ;; Ugh, pass-by-global > + (let ((addrs (bbdb-get-addresses nil nil 'notmuch-bbdb/get-header-content)) > + (bbdb-get-addresses-headers headers) ; headers to read > + (bbdb-gag-messages t)) ; suppress m/n processed message) > +(bbdb-update-records addrs t t)) > + > + (defun notmuch-bbdb/snarf-from () > +"Import the sender of the current message into BBDB" > +(interactive) > +(notmuch-bbdb/snarf-headers > + (list (assoc 'authors bbdb-get-addresses-headers > + > +(defun notmuch-bbdb/snarf-to () > + "Import all recipients of the current message into BBDB" > + (interactive) > + (notmuch-bbdb/snarf-headers > + (list (assoc 'recipients bbdb-get-addresses-headers > + > +(defvar notmuch-bbdb/header-by-name > + ;; both are case sensitive > + '( ("From" . :From) > + ("To" . :To) > + ("CC" . :Cc) > + ("BCC" . :Bcc) > + ("Resent-From" . nil) > + ("Reply-To" . nil) > + ("Resent-To" . nil) > + ("Resent-CC" . nil)) > + "Alist for dispatching header symbols as used by notmuch-show-get-header > +from strings as used by bbdb-get-addresses") > + > +(defun notmuch-bbdb/get-header-content (name) > + (notmuch-show-get-header (cdr (assoc name notmuch-bbdb/header-by-name > + > ;; > > (provide 'notmuch-address) > -- > 1.7.10.4 > > ___ > 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: [PATCH] emacs: functions to import sender or recipient into BBDB
>From fbaf5c568876a6f1e3d8c02446bd83331b6325f0 Mon Sep 17 00:00:00 2001 From: Daniel Bergey Date: Thu, 26 Jul 2012 15:44:01 -0400 Subject: [PATCH] emacs: functions to import sender or recipients into BBDB >From a show buffer, notmuch-bbdb/snarf-from imports the sender into bbdb. notmuch-bbdb/snarf-to imports all recipients. Newly imported contacts are reported in the minibuffer / Messages buffer. Both functions use the BBDB parser to recognize email address formats. --- This differs from the last version of the patch only in whitespace. In addition to changes pointed out by Tomi Ollila, I fixed a ')' on a line alone, and aligned the lines of notmuch-bbdb/header-by-name. I've been using this code (prior to whitespace changes) for a month and a half, as far as testing goes. I wonder if I can get whitespace-mode to warn me about double-spacing emacs/notmuch-address.el | 41 + 1 file changed, 41 insertions(+) diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el index 2bf762b..32c8490 100644 --- a/emacs/notmuch-address.el +++ b/emacs/notmuch-address.el @@ -96,6 +96,47 @@ line." (when (notmuch-address-locate-command notmuch-address-command) (notmuch-address-message-insinuate)) +;; functions to add sender / recipients to BBDB + +(defun notmuch-bbdb/snarf-headers (headers) + ;; Helper function to avoid code duplication in the two below + ;; headers should have the same format as bbdb-get-addresses-headers + + ;; bbdb-get-addresses reads these + ;; Ugh, pass-by-global + (let ((addrs (bbdb-get-addresses nil nil 'notmuch-bbdb/get-header-content)) + (bbdb-get-addresses-headers headers) ; headers to read + (bbdb-gag-messages t)) ; suppress m/n processed message) +(bbdb-update-records addrs t t)) + + (defun notmuch-bbdb/snarf-from () +"Import the sender of the current message into BBDB" +(interactive) +(notmuch-bbdb/snarf-headers + (list (assoc 'authors bbdb-get-addresses-headers + +(defun notmuch-bbdb/snarf-to () + "Import all recipients of the current message into BBDB" + (interactive) + (notmuch-bbdb/snarf-headers + (list (assoc 'recipients bbdb-get-addresses-headers + +(defvar notmuch-bbdb/header-by-name + ;; both are case sensitive + '( ("From" . :From) + ("To" . :To) + ("CC" . :Cc) + ("BCC" . :Bcc) + ("Resent-From" . nil) + ("Reply-To" . nil) + ("Resent-To" . nil) + ("Resent-CC" . nil)) + "Alist for dispatching header symbols as used by notmuch-show-get-header +from strings as used by bbdb-get-addresses") + +(defun notmuch-bbdb/get-header-content (name) + (notmuch-show-get-header (cdr (assoc name notmuch-bbdb/header-by-name + ;; (provide 'notmuch-address) -- 1.7.10.4 ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH 1/1] emacs/notmuch.el: remove instruction to (require 'notmuch) in ~/.emacs
The (require 'notmuch) is unnecessary to be added to ~/.emacs for M-x notmuch or emacs -f notmuch to start it. If (require 'notmuch) is added to ~/.emacs it is loaded to every instance of emacs although it may not be used in majority of those instances (but if needed M-x notmuch will load it). Preloading notmuch would speed up M-x notmuch a bit -- for emacs -f notmuch it doesn't bring any startup speed increase (if that would have mattered). --- emacs/notmuch.el | 7 +-- 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index e58c51d..ae9becd 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -34,12 +34,7 @@ ;; ;; to install it. ;; -;; Then, to actually run it, add: -;; -;; (require 'notmuch) -;; -;; to your ~/.emacs file, and then run "M-x notmuch" from within emacs, -;; or run: +;; Then, to actually run it, run "M-x notmuch" from within emacs, or run: ;; ;; emacs -f notmuch ;; -- 1.8.1.2 ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH v2 0/6] batch count for notmuch-hello speedup
On Sat, Mar 09 2013, Jani Nikula wrote: > Rebased v2 of id:cover.1358273133.git.jani at nikula.org > > Jani Nikula (5): > cli: remove useless strdup > cli: extract count printing to a separate function in notmuch count > cli: add --batch option to notmuch count > man: document notmuch count --batch and --input options > test: notmuch count --batch and --input options > > Mark Walters (1): > emacs: hello: use batch count LGTM. comments in id:m2a9s0hvgy.fsf at guru.guru-group.fi and id:m27gn4htrg.fsf at guru.guru-group.fi apply. Tomi > > emacs/notmuch-hello.el | 52 +- > man/man1/notmuch-count.1 | 20 + > notmuch-count.c | 111 > +++--- > test/count | 46 +++ > 4 files changed, 182 insertions(+), 47 deletions(-) > > -- > 1.7.10.4
Re: [PATCH v3 0/6] batch count for notmuch-hello speedup
On Sun, Mar 31 2013, Jani Nikula wrote: > This is v3 of id:cover.1362841844.git.j...@nikula.org, with the commit > messages of patches 1/6 and 3/6 fixed. No other changes. Thanks to > Jameson and Tomi for review, and of course Mark for the elisp part. +1 -- I verified there is no (accidental) changes between id:cover.1362841844.git.j...@nikula.org and id:cover.1364722841.git.j...@nikula.org > > BR, > Jani. Tomi > > Jani Nikula (5): > cli: remove useless talloc_strdup > cli: extract count printing to a separate function in notmuch count > cli: add --batch option to notmuch count > man: document notmuch count --batch and --input options > test: notmuch count --batch and --input options > > Mark Walters (1): > emacs: hello: use batch count > > emacs/notmuch-hello.el | 52 +- > man/man1/notmuch-count.1 | 20 + > notmuch-count.c | 111 > +++--- > test/count | 46 +++ > 4 files changed, 182 insertions(+), 47 deletions(-) > > -- > 1.7.10.4 > > ___ > 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: [PATCH v4 01/12] tag-util: move out 'tag' command-line checks
On Thu, 24 Jan 2013, Peter Wang wrote: > parse_tag_command_line checked for two error conditions which are > specific to the 'tag' command. It can be reused for the forthcoming > notmuch 'insert' command if we move the checks out, into notmuch-tag.c. FYI, this patch no longer applies to master. Jani. > --- > notmuch-tag.c | 10 ++ > tag-util.c| 11 +++ > 2 files changed, 13 insertions(+), 8 deletions(-) > > diff --git a/notmuch-tag.c b/notmuch-tag.c > index d9daf8f..a901dad 100644 > --- a/notmuch-tag.c > +++ b/notmuch-tag.c > @@ -234,6 +234,16 @@ notmuch_tag_command (void *ctx, int argc, char *argv[]) > if (parse_tag_command_line (ctx, argc - opt_index, argv + opt_index, > &query_string, tag_ops)) > return 1; > + > + if (tag_op_list_size (tag_ops) == 0) { > + fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to > add or remove.\n"); > + return 1; > + } > + > + if (*query_string == '\0') { > + fprintf (stderr, "Error: notmuch tag requires at least one search > term.\n"); > + return 1; > + } > } > > config = notmuch_config_open (ctx, NULL, NULL); > diff --git a/tag-util.c b/tag-util.c > index 701d329..743d591 100644 > --- a/tag-util.c > +++ b/tag-util.c > @@ -188,16 +188,11 @@ parse_tag_command_line (void *ctx, int argc, char > **argv, > tag_op_list_append (tag_ops, argv[i] + 1, is_remove); > } > > -if (tag_op_list_size (tag_ops) == 0) { > - fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add > or remove.\n"); > - return TAG_PARSE_INVALID; > -} > - > *query_str = query_string_from_args (ctx, argc - i, &argv[i]); > > -if (*query_str == NULL || **query_str == '\0') { > - fprintf (stderr, "Error: notmuch tag requires at least one search > term.\n"); > - return TAG_PARSE_INVALID; > +if (*query_str == NULL) { > + fprintf (stderr, "Out of memory.\n"); > + return TAG_PARSE_OUT_OF_MEMORY; > } > > return TAG_PARSE_SUCCESS; > -- > 1.7.12.1 > > ___ > 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 v3 6/6] emacs: hello: use batch count
From: Mark Walters This modifies notmuch hello to use the new count --batch functionality. It should give exactly the same results as before but under many conditions it should be much faster. In particular it is much faster for remote use. The code is a little ugly as it has to do some working out of the query when asking the query and some when dealing with the result. However, the code path is exactly the same in both local and remote use. --- emacs/notmuch-hello.el | 52 +--- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index 00b78e1..cda79f1 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -381,26 +381,38 @@ The result is the list of elements of the form (NAME QUERY COUNT). The values :show-empty-searches, :filter and :filter-count from options will be handled as specified for `notmuch-hello-insert-searches'." - (notmuch-remove-if-not - #'identity - (mapcar -(lambda (elem) - (let* ((name (car elem)) -(query-and-count (if (consp (cdr elem)) - ;; do we have a different query for the message count? - (cons (second elem) (third elem)) - (cons (cdr elem) (cdr elem -(message-count - (string-to-number - (notmuch-saved-search-count - (notmuch-hello-filtered-query (cdr query-and-count) - (or (plist-get options :filter-count) -(plist-get options :filter))) - (and (or (plist-get options :show-empty-searches) (> message-count 0)) -(list name (notmuch-hello-filtered-query -(car query-and-count) (plist-get options :filter)) - message-count -query-alist))) + (with-temp-buffer +(dolist (elem query-alist nil) + (let ((count-query (if (consp (cdr elem)) +;; do we have a different query for the message count? +(third elem) + (cdr elem + (insert +(notmuch-hello-filtered-query count-query + (or (plist-get options :filter-count) + (plist-get options :filter))) +"\n"))) + +(call-process-region (point-min) (point-max) notmuch-command +t t nil "count" "--batch") +(goto-char (point-min)) + +(notmuch-remove-if-not + #'identity + (mapcar + (lambda (elem) + (let ((name (car elem)) + (search-query (if (consp (cdr elem)) +;; do we have a different query for the message count? +(second elem) + (cdr elem))) + (message-count (prog1 (read (current-buffer)) + (forward-line 1 + (and (or (plist-get options :show-empty-searches) (> message-count 0)) + (list name (notmuch-hello-filtered-query + search-query (plist-get options :filter)) +message-count + query-alist (defun notmuch-hello-insert-buttons (searches) "Insert buttons for SEARCHES. -- 1.7.10.4 ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH v3 5/6] test: notmuch count --batch and --input options
--- test/count | 46 ++ 1 file changed, 46 insertions(+) diff --git a/test/count b/test/count index 879b114..05713fd 100755 --- a/test/count +++ b/test/count @@ -38,4 +38,50 @@ test_expect_equal \ "0" \ "`notmuch count --output=threads from:cworth and not from:cworth`" +test_begin_subtest "message count is the default for batch count" +notmuch count --batch >OUTPUT>EXPECTED +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "batch message count" +notmuch count --batch --output=messages >OUTPUT >EXPECTED +notmuch count --output=messages tag:inbox >>EXPECTED +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "batch thread count" +notmuch count --batch --output=threads >OUTPUT >EXPECTED +notmuch count --output=threads from:cworth and not from:cworth >>EXPECTED +notmuch count --output=threads foo >>EXPECTED +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "batch message count with input file" +cat >INPUT
[PATCH v3 4/6] man: document notmuch count --batch and --input options
--- man/man1/notmuch-count.1 | 20 1 file changed, 20 insertions(+) diff --git a/man/man1/notmuch-count.1 b/man/man1/notmuch-count.1 index 86a67fe..7fc4378 100644 --- a/man/man1/notmuch-count.1 +++ b/man/man1/notmuch-count.1 @@ -46,6 +46,26 @@ Output the number of matching threads. Specify whether to omit messages matching search.tag_exclude from the count (the default) or not. .RE + +.RS 4 +.TP 4 +.BR \-\-batch + +Read queries from a file (stdin by default), one per line, and output +the number of matching messages (or threads) to stdout, one per +line. On an empty input line the count of all messages (or threads) in +the database will be output. This option is not compatible with +specifying search terms on the command line. +.RE + +.RS 4 +.TP 4 +.BR "\-\-input=" + +Read input from given file, instead of from stdin. Implies +.BR --batch . +.RE + .RE .RE -- 1.7.10.4 ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH v3 3/6] cli: add --batch option to notmuch count
Add support for reading queries from stdin, one per line, and writing results to stdout, one per line. This will bring considerable performance improvements when utilized in Emacs notmuch-hello, especially so when running remote notmuch. --- notmuch-count.c | 52 ++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/notmuch-count.c b/notmuch-count.c index 630f036..8772cff 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -62,6 +62,27 @@ print_count (notmuch_database_t *notmuch, const char *query_str, return 0; } +static int +count_file (notmuch_database_t *notmuch, FILE *input, const char **exclude_tags, + size_t exclude_tags_length, int output) +{ +char *line = NULL; +ssize_t line_len; +size_t line_size; +int ret = 0; + +while (!ret && (line_len = getline (&line, &line_size, input)) != -1) { + chomp_newline (line); + ret = print_count (notmuch, line, exclude_tags, exclude_tags_length, + output); +} + +if (line) + free (line); + +return ret; +} + int notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) { @@ -72,6 +93,9 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) int exclude = EXCLUDE_TRUE; const char **search_exclude_tags = NULL; size_t search_exclude_tags_length = 0; +notmuch_bool_t batch = FALSE; +FILE *input = stdin; +char *input_file_name = NULL; int ret; notmuch_opt_desc_t options[] = { @@ -83,6 +107,8 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE }, { "false", EXCLUDE_FALSE }, { 0, 0 } } }, + { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 }, + { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 }, { 0, 0, 0, 0, 0 } }; @@ -92,6 +118,21 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) return 1; } +if (input_file_name) { + batch = TRUE; + input = fopen (input_file_name, "r"); + if (input == NULL) { + fprintf (stderr, "Error opening %s for reading: %s\n", +input_file_name, strerror (errno)); + return 1; + } +} + +if (batch && opt_index != argc) { + fprintf (stderr, "--batch and query string are not compatible\n"); + return 1; +} + if (notmuch_database_open (notmuch_config_get_database_path (config), NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much)) return 1; @@ -107,10 +148,17 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) (config, &search_exclude_tags_length); } -ret = print_count (notmuch, query_str, search_exclude_tags, - search_exclude_tags_length, output); +if (batch) + ret = count_file (notmuch, input, search_exclude_tags, + search_exclude_tags_length, output); +else + ret = print_count (notmuch, query_str, search_exclude_tags, + search_exclude_tags_length, output); notmuch_database_destroy (notmuch); +if (input != stdin) + fclose (input); + return ret; } -- 1.7.10.4 ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH v3 2/6] cli: extract count printing to a separate function in notmuch count
Make count printing on a query string reusable. No functional changes. --- notmuch-count.c | 59 +-- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/notmuch-count.c b/notmuch-count.c index c2f1b7d..630f036 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -32,16 +32,47 @@ enum { EXCLUDE_FALSE, }; +static int +print_count (notmuch_database_t *notmuch, const char *query_str, +const char **exclude_tags, size_t exclude_tags_length, int output) +{ +notmuch_query_t *query; +size_t i; + +query = notmuch_query_create (notmuch, query_str); +if (query == NULL) { + fprintf (stderr, "Out of memory\n"); + return 1; +} + +for (i = 0; i < exclude_tags_length; i++) + notmuch_query_add_tag_exclude (query, exclude_tags[i]); + +switch (output) { +case OUTPUT_MESSAGES: + printf ("%u\n", notmuch_query_count_messages (query)); + break; +case OUTPUT_THREADS: + printf ("%u\n", notmuch_query_count_threads (query)); + break; +} + +notmuch_query_destroy (query); + +return 0; +} + int notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) { notmuch_database_t *notmuch; -notmuch_query_t *query; char *query_str; int opt_index; int output = OUTPUT_MESSAGES; int exclude = EXCLUDE_TRUE; -unsigned int i; +const char **search_exclude_tags = NULL; +size_t search_exclude_tags_length = 0; +int ret; notmuch_opt_desc_t options[] = { { NOTMUCH_OPT_KEYWORD, &output, "output", 'o', @@ -71,33 +102,15 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) return 1; } -query = notmuch_query_create (notmuch, query_str); -if (query == NULL) { - fprintf (stderr, "Out of memory\n"); - return 1; -} - if (exclude == EXCLUDE_TRUE) { - const char **search_exclude_tags; - size_t search_exclude_tags_length; - search_exclude_tags = notmuch_config_get_search_exclude_tags (config, &search_exclude_tags_length); - for (i = 0; i < search_exclude_tags_length; i++) - notmuch_query_add_tag_exclude (query, search_exclude_tags[i]); } -switch (output) { -case OUTPUT_MESSAGES: - printf ("%u\n", notmuch_query_count_messages (query)); - break; -case OUTPUT_THREADS: - printf ("%u\n", notmuch_query_count_threads (query)); - break; -} +ret = print_count (notmuch, query_str, search_exclude_tags, + search_exclude_tags_length, output); -notmuch_query_destroy (query); notmuch_database_destroy (notmuch); -return 0; +return ret; } -- 1.7.10.4 ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH v3 1/6] cli: remove useless talloc_strdup
If the condition holds, query_string_from_args() has already returned a talloc allocated empty string. There's no need to duplicate that. --- notmuch-count.c |4 1 file changed, 4 deletions(-) diff --git a/notmuch-count.c b/notmuch-count.c index 390794f..c2f1b7d 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -71,10 +71,6 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]) return 1; } -if (*query_str == '\0') { - query_str = talloc_strdup (config, ""); -} - query = notmuch_query_create (notmuch, query_str); if (query == NULL) { fprintf (stderr, "Out of memory\n"); -- 1.7.10.4 ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH v3 0/6] batch count for notmuch-hello speedup
This is v3 of id:cover.1362841844.git.j...@nikula.org, with the commit messages of patches 1/6 and 3/6 fixed. No other changes. Thanks to Jameson and Tomi for review, and of course Mark for the elisp part. BR, Jani. Jani Nikula (5): cli: remove useless talloc_strdup cli: extract count printing to a separate function in notmuch count cli: add --batch option to notmuch count man: document notmuch count --batch and --input options test: notmuch count --batch and --input options Mark Walters (1): emacs: hello: use batch count emacs/notmuch-hello.el | 52 +- man/man1/notmuch-count.1 | 20 + notmuch-count.c | 111 +++--- test/count | 46 +++ 4 files changed, 182 insertions(+), 47 deletions(-) -- 1.7.10.4 ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
Re: [PATCH v2 0/3] cli: clean up gmime 2.4 vs. 2.6 conditional build
On Sun, Mar 31 2013, Tomi Ollila wrote: > On Sat, Mar 30 2013, Jani Nikula wrote: > >> This is v2 of [1]. Added comments per David's request, and while at it, >> added a third patch to conform the existing conditional build in notmuch >> show to the same style. The whole series should have no functional >> changes, and thus v2 should have no functional changes since v1. ;) >> >> I have not tested this on gmime 2.4. > > I have gmime 2.4(.24) on this system. The code compiles and > exactly the same set of tests pass/fail as without this patch > (unfortunately this system cannot cope with just some of the > crypto patches, so I cannot give absolute guarantee: Ok, the failure cases below are just those which are changed in this patch. So I had to dig further... ... actually this 'PASS emacs delivery of encrypted message with attachment' fails to deliver the message. After the following change: --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -442,7 +442,8 @@ emacs_deliver_message () test_emacs \ "(let ((message-send-mail-function 'message-smtpmail-send-it) - (smtpmail-smtp-server \"localhost\") + (smtpmail-smtp-server 'local) + ;;(smtpmail-smtp-server \"localhost\") (smtpmail-smtp-service \"25025\")) (notmuch-hello) (notmuch-mua-mail) The failured cases below PASSes. (I've stumbled the same problem a few cases before but haven't figured out a good patch so far...) > > crypto: Testing PGP/MIME signature verification and decryption > PASS emacs delivery of signed message > PASS signature verification > PASS signature verification with full owner trust > PASS signature verification with signer key unavailable > PASS emacs delivery of encrypted message with attachment > FAIL decryption, --format=text > FAIL decryption, --format=json > FAIL decryption, --format=json, --part=4 > FAIL decrypt attachment (--part=5 --format=raw) > FAIL decryption failure with missing key > PASS emacs delivery of encrypted + signed message > FAIL decryption + signature verification > FAIL reply to encrypted message > FAIL signature verification with revoked key > > anyway, as said, exactly the same set fails without these pathes > > The reason for failure is most probably in my system and not something > w/ notmuch crypto support -- If I run `emacs foo.org.gpg` this just > hangs waiting me to give passphrase in (invisible?) curses request) > > So, bottom line: LGTM. > >> BR, >> Jani. > > Tomi > > >> [1] >> id:a9f12ba474fc51df71e2fd2b7a20a8d101729c6e.1362319765.git.j...@nikula.org >> >> Jani Nikula (3): >> cli: crypto: abstract gpg context creation for clarity >> cli: mime node: abstract decryption and signature verification >> cli: conform to same conditional build style as elsewhere in >> notmuch-show >> >> crypto.c | 66 - >> mime-node.c| 218 >> >> notmuch-show.c | 46 ++-- >> 3 files changed, 215 insertions(+), 115 deletions(-) >> >> -- >> 1.7.10.4 ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
Re: [PATCH v2 0/3] cli: clean up gmime 2.4 vs. 2.6 conditional build
On Sat, Mar 30 2013, Jani Nikula wrote: > This is v2 of [1]. Added comments per David's request, and while at it, > added a third patch to conform the existing conditional build in notmuch > show to the same style. The whole series should have no functional > changes, and thus v2 should have no functional changes since v1. ;) > > I have not tested this on gmime 2.4. I have gmime 2.4(.24) on this system. The code compiles and exactly the same set of tests pass/fail as without this patch (unfortunately this system cannot cope with just some of the crypto patches, so I cannot give absolute guarantee: crypto: Testing PGP/MIME signature verification and decryption PASS emacs delivery of signed message PASS signature verification PASS signature verification with full owner trust PASS signature verification with signer key unavailable PASS emacs delivery of encrypted message with attachment FAIL decryption, --format=text FAIL decryption, --format=json FAIL decryption, --format=json, --part=4 FAIL decrypt attachment (--part=5 --format=raw) FAIL decryption failure with missing key PASS emacs delivery of encrypted + signed message FAIL decryption + signature verification FAIL reply to encrypted message FAIL signature verification with revoked key anyway, as said, exactly the same set fails without these pathes The reason for failure is most probably in my system and not something w/ notmuch crypto support -- If I run `emacs foo.org.gpg` this just hangs waiting me to give passphrase in (invisible?) curses request) So, bottom line: LGTM. > BR, > Jani. Tomi > [1] id:a9f12ba474fc51df71e2fd2b7a20a8d101729c6e.1362319765.git.j...@nikula.org > > Jani Nikula (3): > cli: crypto: abstract gpg context creation for clarity > cli: mime node: abstract decryption and signature verification > cli: conform to same conditional build style as elsewhere in > notmuch-show > > crypto.c | 66 - > mime-node.c| 218 > > notmuch-show.c | 46 ++-- > 3 files changed, 215 insertions(+), 115 deletions(-) > > -- > 1.7.10.4 > > ___ > 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: [PATCH v2 0/6] batch count for notmuch-hello speedup
On Sat, Mar 09 2013, Jani Nikula wrote: > Rebased v2 of id:cover.1358273133.git.j...@nikula.org > > Jani Nikula (5): > cli: remove useless strdup > cli: extract count printing to a separate function in notmuch count > cli: add --batch option to notmuch count > man: document notmuch count --batch and --input options > test: notmuch count --batch and --input options > > Mark Walters (1): > emacs: hello: use batch count LGTM. comments in id:m2a9s0hvgy@guru.guru-group.fi and id:m27gn4htrg@guru.guru-group.fi apply. Tomi > > emacs/notmuch-hello.el | 52 +- > man/man1/notmuch-count.1 | 20 + > notmuch-count.c | 111 > +++--- > test/count | 46 +++ > 4 files changed, 182 insertions(+), 47 deletions(-) > > -- > 1.7.10.4 ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch