September 20, 2004 7:55 PM
BBDB1 handles all my contact information for use with Gnus among other things. I love its flexibility and ease of use. A useful feature is the support for automatic creation of a BBDB record while reading email in Gnus.

My old windows email client could only export contact information as Microsoft Outlook2 compatible Vcard files. I needed a quick way to import all that information into BBDB. bbdb-snarf is an inbuilt utility that allows creation of records from files. I simply wrote a function that converts vcard data into a format that bbdb-snarf can understand. Customization of bbdb-snarf-phone-regexp to support Indian phone numbers have been done very sloppily since any line consisting only of numbers must be a phone number. Why? Because, my function only supports four fields, Name, Email Address, URL, and Phone number. ;)

(defun bbdb-snarf-vcard ()
  "Snarf a vcard into BBDB."
  (let (field del
	(kill-whole-line t)
        ;Lame fix to recognize indian phone numbers
	  "\\(([0-9]+)[-\\. ]?\\|[0-9]+[-\\. ]\\)?"
	  "[0-9]+[-\\. ()]*[0-9]")))
    (goto-char 0)
    (while (re-search-forward "^\\([-=A-Z;]*[:]\\)\\(.*$\\)" nil t)
      (setq field (match-string 1))
      ;= at the end of line approximately
      ;specifies data is continued in next line as well
      (setq del 
	    (if (string= 
		 (substring (match-string 2) (- (length (match-string 2)) 1)) 
		t nil))
      (if (not (string= field "http:"))
	  (replace-match "" t t nil 1)
      (if (not (string-match "FN\\|EMAIL\\|URL\\|TEL" field))
	    (if del (kill-line 2) (kill-line)))))
    (goto-char 0)
    (bbdb-snarf 0)))

To use this, simply call bbdb-snarf-vcard while you are in a buffer with vcard data in it. Altogether, it's merely an ugly cosmetic adjustment so that bbdb-snarf can do the real work.

Don't bother with this if you can export data as CSV files. For an updated list of BBDB importers, visit BbdbImporters.


[1] BBDB is a rolodex-like database program for GNU Emacs. BBDB stands for Insidious Big Brother Database.
[2] Microsoft Outlook users can easily import their contact info into BBDB, read BbdbImportFromOutlook.

Copyright © 2004-2011 Anirudh Sasikumar. All rights reserved.
Last Updated: January 21, 2005 4:26 PM