On Sat, 24 Oct 2015, David Bremner <david@tethera.net> wrote: > No attempt is made to optimize anything here, just drop in the new > command. In particular the use of --output=recipients is known to be > slower than --output=senders, but it fit the existing logic better. Would it be useful to (optionally) use --deduplicate=address here? Having a dozen name variants with the same address part bugs me most about the completions. Another thing that might be useful as a follow-up is adding an optional date: search filter to only take into account recent emails. This would gradually phase out obsolete addresses from the results. Also speeds up searches if the database is huge. BR, Jani. > --- > emacs/notmuch-address.el | 25 ++++++++----------------- > 1 file changed, 8 insertions(+), 17 deletions(-) > > diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el > index 9f6711b..d54a8bb 100644 > --- a/emacs/notmuch-address.el > +++ b/emacs/notmuch-address.el > @@ -20,7 +20,6 @@ > ;; Authors: David Edmondson <dme@dme.org> > > (require 'message) > -(require 'notmuch-query) > (require 'notmuch-parser) > > ;; > @@ -148,21 +147,12 @@ external commands." > (not (file-directory-p bin)))) > (throw 'found-command bin)))))))) > > -(defun notmuch-address-harvest-msg (msg) > - (let* ((headers (plist-get msg :headers)) > - (to (ignore-errors (mail-extract-address-components (plist-get headers :To) t))) > - (cc (ignore-errors (mail-extract-address-components (plist-get headers :Cc) t))) > - (bcc (ignore-errors (mail-extract-address-components (plist-get headers :Bcc) t)))) > - (mapc (lambda (parts) > - (let* ((name (car parts)) > - (email (cadr parts)) > - (entry (if name (format "%s <%s>" name email) email))) > - (puthash entry t notmuch-address-completions))) > - (append to cc bcc)) > - nil)) > +(defun notmuch-address-harvest-addr (result) > + (let ((name-addr (plist-get result :name-addr))) > + (puthash name-addr t notmuch-address-completions))) > > (defun notmuch-address-harvest-handle-result (obj) > - (notmuch-query-map-threads 'notmuch-address-harvest-msg (list obj))) > + (notmuch-address-harvest-addr obj)) > > (defun notmuch-address-harvest-filter (proc string) > (when (buffer-live-p (process-buffer proc)) > @@ -188,10 +178,11 @@ called when harvesting finishes." > (query (if filter-query > (format "(%s) and (%s)" from-me-query filter-query) > from-me-query)) > - (args `("show" "--format=sexp" "--format-version=2" > - "--body=false" "--entire-thread=false" ,query))) > + (args `("address" "--format=sexp" "--format-version=2" > + "--output=recipients" > + ,query))) > (if synchronous > - (notmuch-query-map-threads 'notmuch-address-harvest-msg > + (mapc #'notmuch-address-harvest-addr > (apply 'notmuch-call-notmuch-sexp args)) > ;; Asynchronous > (when notmuch-address-harvest-proc > -- > 2.6.1 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > https://notmuchmail.org/mailman/listinfo/notmuch