Re: Hi all
[notmuch-archives.git] / 49 / ed54060536ce8a5bad91e4434515a63196daa6
1 Return-Path: <james@hackervisions.org>\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 olra.theworths.org (Postfix) with ESMTP id B60164196F3\r
6         for <notmuch@notmuchmail.org>; Thu, 25 Mar 2010 08:20:33 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 2.782\r
10 X-Spam-Level: **\r
11 X-Spam-Status: No, score=2.782 tagged_above=-999 required=5\r
12         tests=[BAYES_50=0.8, RDNS_DYNAMIC=0.982, TO_NO_BRKTS_DYNIP=1]\r
13         autolearn=no\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id V66cuVd0x3Th for <notmuch@notmuchmail.org>;\r
17         Thu, 25 Mar 2010 08:20:33 -0700 (PDT)\r
18 Received: from hackervisions.org (67-207-143-141.slicehost.net\r
19         [67.207.143.141])\r
20         by olra.theworths.org (Postfix) with ESMTP id 513B04196F2\r
21         for <notmuch@notmuchmail.org>; Thu, 25 Mar 2010 08:20:33 -0700 (PDT)\r
22 Received: from john-marshall.sflc.info ([216.27.154.200] helo=localhost)\r
23         by hv with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.69)\r
24         (envelope-from <james@hackervisions.org>)\r
25         id 1NuorI-0008AB-Jk; Thu, 25 Mar 2010 11:20:32 -0400\r
26 From: James Vasile <james@hackervisions.org>\r
27 To: notmuch@notmuchmail.org\r
28 Date: Thu, 25 Mar 2010 11:20:23 -0400\r
29 Message-ID: <87hbo4qvgo.fsf@hackervisions.org>\r
30 MIME-Version: 1.0\r
31 Content-Type: multipart/mixed; boundary="=-=-="\r
32 Subject: [notmuch] bbdb import notmuch addresses\r
33 X-BeenThere: notmuch@notmuchmail.org\r
34 X-Mailman-Version: 2.1.13\r
35 Precedence: list\r
36 List-Id: "Use and development of the notmuch mail system."\r
37         <notmuch.notmuchmail.org>\r
38 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
39         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
41 List-Post: <mailto:notmuch@notmuchmail.org>\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
43 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
45 X-List-Received-Date: Thu, 25 Mar 2010 15:20:33 -0000\r
46 \r
47 --=-=-=\r
48 \r
49 I used notmuch_address.py to scrape email addresses from notmuch and\r
50 generate elisp to showve them into bbdb.  Tab completion via bbdb is\r
51 much faster than via notmuch_addresses.\r
52 \r
53 Run the script, execute the results in emacs.  I didn't care enough to\r
54 do any merging, so records that clash with existing records are ignored.\r
55 \r
56 \r
57 --=-=-=\r
58 Content-Type: text/x-python\r
59 Content-Disposition: inline; filename=scrape.py\r
60 Content-Description: scrape.py\r
61 \r
62 #!/usr/bin/python\r
63 \r
64 from cnotmuch import notmuch\r
65 import notmuch_addresses\r
66 \r
67 def get_matching_messages(self):\r
68         notmuch_db = notmuch.Database(self.db_path)\r
69         query_string = "(from:" + self.email\r
70 \r
71         for addr in self.other_emails:\r
72             query_string += (" OR from:" + addr)\r
73 \r
74         query_string += ")"\r
75 \r
76         query = notmuch.Query(notmuch_db, query_string)\r
77         return query.search_messages()\r
78 notmuch_addresses._get_matching_messages = get_matching_messages\r
79 \r
80 \r
81 matcher = notmuch_addresses.NotmuchAddressMatcher('')\r
82 matcher.generate_matches()\r
83 \r
84 print """\r
85 (defun bbdb-snarf-email-alias (name email)\r
86   "Import email alias into bbdb"\r
87   (condition-case nil \r
88       (unless (bbdb-search-simple nil email)\r
89         (bbdb-create-internal name nil email nil nil nil))\r
90     (error nil)))\r
91 """\r
92 \r
93 for elem in matcher.matches:\r
94     if not '@' in elem:\r
95         continue\r
96     if not '<' in elem:\r
97         print "(bbdb-snarf-email-alias \"%s\")" % elem.lower()\r
98     else:\r
99         elem = elem.replace('"', '')\r
100         elem = elem.replace(' <', '" "')\r
101         elem = elem.replace('>', '"')\r
102         if elem[0] != '"':\r
103             elem = '"%s' % elem\r
104         print "(bbdb-snarf-email-alias %s)" % elem\r
105 \r
106     \r
107 \r
108 --=-=-=--\r