I used notmuch_address.py to scrape email addresses from notmuch and
generate elisp to showve them into bbdb.  Tab completion via bbdb is
much faster than via notmuch_addresses.

Run the script, execute the results in emacs.  I didn't care enough to
do any merging, so records that clash with existing records are ignored.

#!/usr/bin/python

from cnotmuch import notmuch
import notmuch_addresses

def get_matching_messages(self):
        notmuch_db = notmuch.Database(self.db_path)
        query_string = "(from:" + self.email

        for addr in self.other_emails:
            query_string += (" OR from:" + addr)

        query_string += ")"

        query = notmuch.Query(notmuch_db, query_string)
        return query.search_messages()
notmuch_addresses._get_matching_messages = get_matching_messages


matcher = notmuch_addresses.NotmuchAddressMatcher('')
matcher.generate_matches()

print """
(defun bbdb-snarf-email-alias (name email)
  "Import email alias into bbdb"
  (condition-case nil 
      (unless (bbdb-search-simple nil email)
	(bbdb-create-internal name nil email nil nil nil))
    (error nil)))
"""

for elem in matcher.matches:
    if not '@' in elem:
        continue
    if not '<' in elem:
        print "(bbdb-snarf-email-alias \"%s\")" % elem.lower()
    else:
        elem = elem.replace('"', '')
        elem = elem.replace(' <', '" "')
        elem = elem.replace('>', '"')
        if elem[0] != '"':
            elem = '"%s' % elem
        print "(bbdb-snarf-email-alias %s)" % elem

    
_______________________________________________
notmuch mailing list
[email protected]
http://notmuchmail.org/mailman/listinfo/notmuch

Reply via email to