[PATCH] emacs: convert notmuch-address-harvester to use notmuch-address

Subject: [PATCH] emacs: convert notmuch-address-harvester to use notmuch-address

Date: Sat, 17 Jan 2015 15:49:14 +0100

To: David Bremner, Michal Sojka, notmuch@notmuchmail.org

Cc:

From: David Bremner


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.
---
Let us never speak of the parent message again.
 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.1.4


Thread: