[Patch v5 2/3] emacs: convert notmuch-address-harvester to use notmuch-address
[notmuch-archives.git] / 96 / b18cf3bfed8184609127b276f643f28c99ac70
1 Return-Path: <bremner@tethera.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5  by arlo.cworth.org (Postfix) with ESMTP id 99AE06DE1384\r
6  for <notmuch@notmuchmail.org>; Fri, 23 Oct 2015 17:22:46 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.104\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.104 tagged_above=-999 required=5 tests=[AWL=0.094, \r
12  T_FILL_THIS_FORM_SHORT=0.01] autolearn=disabled\r
13 Received: from arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id Reyy8-_ZsRZF for <notmuch@notmuchmail.org>;\r
16  Fri, 23 Oct 2015 17:22:44 -0700 (PDT)\r
17 Received: from gitolite.debian.net (gitolite.debian.net [87.98.215.224])\r
18  by arlo.cworth.org (Postfix) with ESMTPS id 71D8B6DE1405\r
19  for <notmuch@notmuchmail.org>; Fri, 23 Oct 2015 17:22:44 -0700 (PDT)\r
20 Received: from remotemail by gitolite.debian.net with local (Exim 4.80)\r
21  (envelope-from <bremner@tethera.net>)\r
22  id 1Zpmav-0006nQ-VU; Sat, 24 Oct 2015 00:22:01 +0000\r
23 Received: (nullmailer pid 26053 invoked by uid 1000); Sat, 24 Oct 2015\r
24  00:20:41 -0000\r
25 From: David Bremner <david@tethera.net>\r
26 To: notmuch@notmuchmail.org\r
27 Subject: [Patch v5 2/3] emacs: convert notmuch-address-harvester to use\r
28  notmuch-address\r
29 Date: Fri, 23 Oct 2015 21:20:36 -0300\r
30 Message-Id: <1445646037-25994-3-git-send-email-david@tethera.net>\r
31 X-Mailer: git-send-email 2.6.1\r
32 In-Reply-To: <1445646037-25994-1-git-send-email-david@tethera.net>\r
33 References: <1445646037-25994-1-git-send-email-david@tethera.net>\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.20\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38  <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
40  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
45  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Sat, 24 Oct 2015 00:22:46 -0000\r
47 \r
48 No attempt is made to optimize anything here, just drop in the new\r
49 command. In particular the use of --output=recipients is known to be\r
50 slower than --output=senders, but it fit the existing logic better.\r
51 ---\r
52  emacs/notmuch-address.el | 25 ++++++++-----------------\r
53  1 file changed, 8 insertions(+), 17 deletions(-)\r
54 \r
55 diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el\r
56 index 9f6711b..d54a8bb 100644\r
57 --- a/emacs/notmuch-address.el\r
58 +++ b/emacs/notmuch-address.el\r
59 @@ -20,7 +20,6 @@\r
60  ;; Authors: David Edmondson <dme@dme.org>\r
61  \r
62  (require 'message)\r
63 -(require 'notmuch-query)\r
64  (require 'notmuch-parser)\r
65  \r
66  ;;\r
67 @@ -148,21 +147,12 @@ external commands."\r
68                            (not (file-directory-p bin))))\r
69               (throw 'found-command bin))))))))\r
70  \r
71 -(defun notmuch-address-harvest-msg (msg)\r
72 -  (let* ((headers (plist-get msg :headers))\r
73 -        (to (ignore-errors (mail-extract-address-components (plist-get headers :To) t)))\r
74 -        (cc (ignore-errors (mail-extract-address-components (plist-get headers :Cc) t)))\r
75 -        (bcc (ignore-errors (mail-extract-address-components (plist-get headers :Bcc) t))))\r
76 -    (mapc (lambda (parts)\r
77 -           (let* ((name (car parts))\r
78 -                  (email (cadr parts))\r
79 -                  (entry (if name (format "%s <%s>" name email) email)))\r
80 -             (puthash entry t notmuch-address-completions)))\r
81 -         (append to cc bcc))\r
82 -    nil))\r
83 +(defun notmuch-address-harvest-addr (result)\r
84 +  (let ((name-addr (plist-get result :name-addr)))\r
85 +    (puthash name-addr t notmuch-address-completions)))\r
86  \r
87  (defun notmuch-address-harvest-handle-result (obj)\r
88 -  (notmuch-query-map-threads 'notmuch-address-harvest-msg (list obj)))\r
89 +  (notmuch-address-harvest-addr obj))\r
90  \r
91  (defun notmuch-address-harvest-filter (proc string)\r
92    (when (buffer-live-p (process-buffer proc))\r
93 @@ -188,10 +178,11 @@ called when harvesting finishes."\r
94          (query (if filter-query\r
95                     (format "(%s) and (%s)" from-me-query filter-query)\r
96                   from-me-query))\r
97 -        (args `("show" "--format=sexp" "--format-version=2"\r
98 -                "--body=false" "--entire-thread=false" ,query)))\r
99 +        (args `("address" "--format=sexp" "--format-version=2"\r
100 +                "--output=recipients"\r
101 +                ,query)))\r
102      (if synchronous\r
103 -       (notmuch-query-map-threads 'notmuch-address-harvest-msg\r
104 +       (mapc #'notmuch-address-harvest-addr\r
105                                    (apply 'notmuch-call-notmuch-sexp args))\r
106        ;; Asynchronous\r
107        (when notmuch-address-harvest-proc\r
108 -- \r
109 2.6.1\r
110 \r