Petr Hracek ec3c8d
diff --git a/lisp/net/eudcb-bbdb.el b/lisp/net/eudcb-bbdb.el
Petr Hracek ec3c8d
index 0400e5b..582ecb5 100644
Petr Hracek ec3c8d
--- a/lisp/net/eudcb-bbdb.el
Petr Hracek ec3c8d
+++ b/lisp/net/eudcb-bbdb.el
Petr Hracek ec3c8d
@@ -41,6 +41,24 @@
Petr Hracek ec3c8d
 (defvar eudc-bbdb-current-query nil)
Petr Hracek ec3c8d
 (defvar eudc-bbdb-current-return-attributes nil)
Petr Hracek ec3c8d
 
Petr Hracek ec3c8d
+(defvar bbdb-version)
Petr Hracek ec3c8d
+
Petr Hracek ec3c8d
+(defun eudc-bbdb-field (field-symbol)
Petr Hracek ec3c8d
+  "Convert FIELD-SYMBOL so that it is recognized by the current BBDB version.
Petr Hracek ec3c8d
+BBDB < 3 used `net'; BBDB >= 3 uses `mail'."
Petr Hracek ec3c8d
+  ;; This just-in-time translation permits upgrading from BBDB 2 to
Petr Hracek ec3c8d
+  ;; BBDB 3 without restarting Emacs.
Petr Hracek ec3c8d
+  (if (and (eq field-symbol 'net)
Petr Hracek ec3c8d
+	   (or
Petr Hracek ec3c8d
+     ;; MELPA versions of BBDB may have a bad package version,
Petr Hracek ec3c8d
+	    ;; but they're all version 3 or later.
Petr Hracek ec3c8d
+	    (equal bbdb-version "@PACKAGE_VERSION@")
Petr Hracek ec3c8d
+	    ;; Development versions of BBDB can have the format "X.YZ
Petr Hracek ec3c8d
+	    ;; devo".  Split the string just in case.
Petr Hracek ec3c8d
+	    (version<= "3" (car (split-string bbdb-version)))))
Petr Hracek ec3c8d
+      'mail
Petr Hracek ec3c8d
+    field-symbol))
Petr Hracek ec3c8d
+
Petr Hracek ec3c8d
 (defvar eudc-bbdb-attributes-translation-alist
Petr Hracek ec3c8d
   '((name . lastname)
Petr Hracek ec3c8d
     (email . net)
Petr Hracek ec3c8d
@@ -84,7 +102,9 @@
Petr Hracek ec3c8d
                    (progn
Petr Hracek ec3c8d
                      (setq bbdb-val
Petr Hracek ec3c8d
                            (eval (list (intern (concat "bbdb-record-"
Petr Hracek ec3c8d
-                                                       (symbol-name attr)))
Petr Hracek ec3c8d
+                                                       (symbol-name
Petr Hracek ec3c8d
+                                                        (eudc-bbdb-field
Petr Hracek ec3c8d
+                                                         attr))))
Petr Hracek ec3c8d
                                        'record)))
Petr Hracek ec3c8d
                      (if (listp bbdb-val)
Petr Hracek ec3c8d
                          (if eudc-bbdb-enable-substring-matches
Petr Hracek ec3c8d
@@ -167,7 +187,7 @@ The record is filtered according to `eudc-bbdb-current-return-attributes'"
Petr Hracek ec3c8d
 	(setq val (eval
Petr Hracek ec3c8d
 		   (list (intern
Petr Hracek ec3c8d
 			  (concat "bbdb-record-"
Petr Hracek ec3c8d
-				  (symbol-name attr)))
Petr Hracek ec3c8d
+				  (symbol-name (eudc-bbdb-field attr))))
Petr Hracek ec3c8d
 			 'record))))
Petr Hracek ec3c8d
        (t
Petr Hracek ec3c8d
 	(error "Unknown BBDB attribute")))