[notmuch] bbdb import notmuch addresses
authorJames Vasile <james@hackervisions.org>
Thu, 25 Mar 2010 15:20:23 +0000 (11:20 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:36:26 +0000 (09:36 -0800)
49/ed54060536ce8a5bad91e4434515a63196daa6 [new file with mode: 0644]

diff --git a/49/ed54060536ce8a5bad91e4434515a63196daa6 b/49/ed54060536ce8a5bad91e4434515a63196daa6
new file mode 100644 (file)
index 0000000..d5bb490
--- /dev/null
@@ -0,0 +1,108 @@
+Return-Path: <james@hackervisions.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id B60164196F3\r
+       for <notmuch@notmuchmail.org>; Thu, 25 Mar 2010 08:20:33 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 2.782\r
+X-Spam-Level: **\r
+X-Spam-Status: No, score=2.782 tagged_above=-999 required=5\r
+       tests=[BAYES_50=0.8, RDNS_DYNAMIC=0.982, TO_NO_BRKTS_DYNIP=1]\r
+       autolearn=no\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id V66cuVd0x3Th for <notmuch@notmuchmail.org>;\r
+       Thu, 25 Mar 2010 08:20:33 -0700 (PDT)\r
+Received: from hackervisions.org (67-207-143-141.slicehost.net\r
+       [67.207.143.141])\r
+       by olra.theworths.org (Postfix) with ESMTP id 513B04196F2\r
+       for <notmuch@notmuchmail.org>; Thu, 25 Mar 2010 08:20:33 -0700 (PDT)\r
+Received: from john-marshall.sflc.info ([216.27.154.200] helo=localhost)\r
+       by hv with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.69)\r
+       (envelope-from <james@hackervisions.org>)\r
+       id 1NuorI-0008AB-Jk; Thu, 25 Mar 2010 11:20:32 -0400\r
+From: James Vasile <james@hackervisions.org>\r
+To: notmuch@notmuchmail.org\r
+Date: Thu, 25 Mar 2010 11:20:23 -0400\r
+Message-ID: <87hbo4qvgo.fsf@hackervisions.org>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/mixed; boundary="=-=-="\r
+Subject: [notmuch] bbdb import notmuch addresses\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 25 Mar 2010 15:20:33 -0000\r
+\r
+--=-=-=\r
+\r
+I used notmuch_address.py to scrape email addresses from notmuch and\r
+generate elisp to showve them into bbdb.  Tab completion via bbdb is\r
+much faster than via notmuch_addresses.\r
+\r
+Run the script, execute the results in emacs.  I didn't care enough to\r
+do any merging, so records that clash with existing records are ignored.\r
+\r
+\r
+--=-=-=\r
+Content-Type: text/x-python\r
+Content-Disposition: inline; filename=scrape.py\r
+Content-Description: scrape.py\r
+\r
+#!/usr/bin/python\r
+\r
+from cnotmuch import notmuch\r
+import notmuch_addresses\r
+\r
+def get_matching_messages(self):\r
+        notmuch_db = notmuch.Database(self.db_path)\r
+        query_string = "(from:" + self.email\r
+\r
+        for addr in self.other_emails:\r
+            query_string += (" OR from:" + addr)\r
+\r
+        query_string += ")"\r
+\r
+        query = notmuch.Query(notmuch_db, query_string)\r
+        return query.search_messages()\r
+notmuch_addresses._get_matching_messages = get_matching_messages\r
+\r
+\r
+matcher = notmuch_addresses.NotmuchAddressMatcher('')\r
+matcher.generate_matches()\r
+\r
+print """\r
+(defun bbdb-snarf-email-alias (name email)\r
+  "Import email alias into bbdb"\r
+  (condition-case nil \r
+      (unless (bbdb-search-simple nil email)\r
+       (bbdb-create-internal name nil email nil nil nil))\r
+    (error nil)))\r
+"""\r
+\r
+for elem in matcher.matches:\r
+    if not '@' in elem:\r
+        continue\r
+    if not '<' in elem:\r
+        print "(bbdb-snarf-email-alias \"%s\")" % elem.lower()\r
+    else:\r
+        elem = elem.replace('"', '')\r
+        elem = elem.replace(' <', '" "')\r
+        elem = elem.replace('>', '"')\r
+        if elem[0] != '"':\r
+            elem = '"%s' % elem\r
+        print "(bbdb-snarf-email-alias %s)" % elem\r
+\r
+    \r
+\r
+--=-=-=--\r