Hello,

I did a first step for snarfing german contact data.  With the patch
below bbdb-snarf (de) should be able to snarf a region like

--8<---------------cut here---------------start------------->8---
Maja Musterfrau
Strasse 15
12345 Ort
+4912345
mobile: +49123456
xxx....@xxxx.xxx
http://www.xxx.xx
notes bla bla bla
bla bla bla
--8<---------------cut here---------------end--------------->8---

into bbdb.

The patch is limited and comes with no warranties.


Ciao,
                                          Marco

>From 5f240ccc4af844dea6a07f68c3c0389a465c97f2 Mon Sep 17 00:00:00 2001
From: Marco Wahl <marcowahls...@gmail.com>
Date: Wed, 1 Apr 2015 16:23:41 +0200
Subject: [PATCH] bbdb-snarf: snarf de contact data

---
 lisp/bbdb-snarf.el | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/lisp/bbdb-snarf.el b/lisp/bbdb-snarf.el
index 1b43c07..eba36d4 100644
--- a/lisp/bbdb-snarf.el
+++ b/lisp/bbdb-snarf.el
@@ -43,6 +43,15 @@
         bbdb-snarf-url bbdb-snarf-mail bbdb-snarf-empty-lines
         bbdb-snarf-name bbdb-snarf-address-us bbdb-snarf-empty-lines
         bbdb-snarf-notes bbdb-snarf-name-mail)
+    (de bbdb-snarf-surrounding-space
+        bbdb-snarf-phone-normalized
+        bbdb-snarf-url
+        bbdb-snarf-mail
+        bbdb-snarf-empty-lines
+        bbdb-snarf-name
+        bbdb-snarf-address-de
+        bbdb-snarf-empty-lines
+        bbdb-snarf-notes)
     (mail bbdb-snarf-mail-address))
   "Alist of rules for snarfing.
 Each rule is of the form (KEY FUNCTION FUNCTION ...).
@@ -111,6 +120,20 @@ The string LABEL denotes the default label for FIELD."
   :group 'bbdb-utilities-snarf
   :type 'regexp)
 
+(defcustom bbdb-snarf-phone-normalized-regexp
+  "\\+[0-9]+"
+  "Regexp matching a normalized phone number.  E.g. +49110.
+TODO: make this smarter."
+  :group 'bbdb-utilities-snarf
+  :type 'regexp)
+
+(defcustom bbdb-snarf-address-de-regexp
+  (concat "\\(.*\\)\n"
+          "\\([0-9][0-9][0-9][0-9][0-9]\\)[ \t]+" "\\(.*\\)")
+  "Regexp matching a typical DE address."
+  :group 'bbdb-utilities-snarf
+  :type 'regexp)
+
 (defun bbdb-snarf-surrounding-space (record)
   "Discard beginning and trailing space when snarfing RECORD."
   (while (re-search-forward "^[ \t]+" nil t)
@@ -182,6 +205,19 @@ NANP is the North American Numbering Plan used in North and Central America."
                   phones)))))
     (bbdb-record-set-phone record (nconc (bbdb-record-phone record) phones))))
 
+(defun bbdb-snarf-phone-normalized (record)
+  "Snarf normalized Phone Numbers for RECORD."
+  (let ((case-fold-search t) phones)
+    (while (re-search-forward bbdb-snarf-phone-normalized-regexp nil t)
+      (let ((begin (match-beginning 0))
+            (end (match-end 0)))
+        (let ((number (buffer-substring begin end)))
+          (delete-region begin end)
+          (push (vconcat (list (bbdb-snarf-label 'phone)) ; hint: this list is a string
+                         (list number))
+                phones))))
+    (bbdb-record-set-field record 'phone (nconc (bbdb-record-phone record) phones) nil t)))
+
 (defun bbdb-snarf-mail (record)
   "Snarf mail addresses for RECORD."
   (let (mails)
@@ -239,6 +275,25 @@ NANP is the North American Numbering Plan used in North and Central America."
                              (nconc (bbdb-record-address record)
                                     (list address)))))
 
+(defun bbdb-snarf-address-de (record)
+  "Snarf a DE address for RECORD."
+  (let ((address (make-vector bbdb-address-length nil)))
+    (cond ((re-search-forward bbdb-snarf-address-de-regexp nil t)
+           (save-restriction
+             (narrow-to-region (point-min) (match-end 0))
+             (bbdb-address-set-streets address
+                                       (list (buffer-substring (match-beginning 1) (match-end 1))))
+             (bbdb-address-set-postcode address
+                                        (buffer-substring (match-beginning 2) (match-end 2)))
+             (bbdb-address-set-state address nil) ;; no handling of state
+             (bbdb-address-set-city address
+                                    (buffer-substring (match-beginning 3) (match-end 3)))
+             ; delete the just handled section:
+             (delete-region (match-beginning 0) (match-end 0)))))
+    (bbdb-record-set-address record
+                             (nconc (bbdb-record-address record)
+                                    (list address)))))
+
 (defun bbdb-snarf-url (record)
   "Snarf URL for RECORD."
   (when (and bbdb-snarf-url
@@ -325,6 +380,8 @@ See `bbdb-snarf-rule-alist' for details."
     record))
 
 ;; Some test cases
+
+;; us
 ;;
 ;; another test person
 ;; 1234 Gridley St.
@@ -353,4 +410,16 @@ See `bbdb-snarf-rule-alist' for details."
 ;; 555-1212
 ;; t...@person.net
 
+;; de
+;;
+;; Maja Musterfrau
+;; Strasse 15
+;; 12345 Ort
+;; +4912345
+;; mobile: +49123456
+;; xxx....@xxxx.xxx
+;; http://www.xxx.xx
+;; notes bla bla bla
+;; bla bla bla
+
 (provide 'bbdb-snarf)
-- 
2.3.5

-- 
http://www.wahlzone.de
GPG: 0x49010A040A3AE6F2
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/

Reply via email to