small doc update
[bbdb-csv-import] / bbdb-csv-import.el
index fb51a9e252f4b2d4abc4b1a65673d3e7773582dd..b234bd6066eeae900d9e2caa123b4a53f75dabbb 100644 (file)
@@ -9,6 +9,7 @@
 ;; Package-Requires: ((pcsv "1.3.3") (dash "2.5.0") (bbdb "20140412.1949"))
 ;; Keywords: csv, util, bbdb
 ;; Homepage: https://gitlab.com/iankelling/bbdb-csv-import
+;; Mailing-List: https://lists.iankelling.org/listinfo/bbdb-csv-import
 
 ;; This program is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
@@ -59,7 +60,7 @@
 ;; chance it will work out of the box. If it doesn't, you can try to fix it as
 ;; described below, or the maintainer will be happy to help, just anonymize your
 ;; csv data using the M-x bbdb-csv-anonymize-current-buffer (make sure csv
-;; buffer is the current one) and attach it to an email.
+;; buffer is the current one) and attach it to an email to the mailing list.
 ;;
 ;; Duplicate contacts (according to email address) are skipped if
 ;; bbdb-allow-duplicates is nil (default). Any duplicates found are echoed at
 ;; (setq bbdb-csv-import-mapping-table bbdb-csv-import-outlook-typed-email)
 ;; 
 ;; The doc string for `bbdb-create-internal' may also be useful when creating a
-;; mapping table. Please send any new tables to the maintainer listed in this
-;; file. The maintainer should be able to help with any issues and may create a
-;; new mapping table given sample data.
+;; mapping table. If you create a table for a program not not already supported,
+;; please share it with the mailing list so it can be added to this program.
+;; The maintainer should be able to help with any issues and may create a new
+;; mapping table given sample data.
 ;;
-;; Mapping table tips: For field names or sets of field names which go together,
-;; and are numbered, 1, 2, 3, the repeat keyword can be used to expand as many
-;; as are in your csv data.
+;; Mapping table tips:
+;; * The repeat keyword expands numbered field names, based on the first
+;;   field, as many times as they exist in the csv data.
+;; * All mapping fields are optional. A simple mapping table could be
+;;   (setq bbdb-csv-import-mapping-table '((:mail "Primary Email")))
+;; * :xfields uses the csv field name to create custom fields in bbdb. It downcases
+;;   the field name, and replaces spaces with "-", and repeating dashes with a
+;;   single one . For example, if you had a csv named "Mail Alias" or "Mail - alias",
+;;   you could add it to :xfields in a mapping table and it would become "mail-alias"
+;;   in bbdb.
 
 ;;; Misc tips/troubleshooting:
 ;;
 ;;   do M-x bbdb then .* then C-u * d on the beginning of a record.
 ;; - After changing a mapping table variable, don't forget to re-execute
 ;;   (setq bbdb-csv-import-mapping-table ...) so that it propagates.
+;; - :namelist is used instead of :name if 2 or more non-empty fields from :namelist are
+;;   found in a record. If :name is empty, we try a single non-empty field from :namelist
+;;   This sounds a bit strange, but it's to try and deal with Thunderbird idiosyncrasies.
 
 ;;; Bugs, patches, discussion, feedback
 ;;
 ;; 
 ;; Questions, feedback, or anything is very welcome at to the bbdb-csv-import mailing list
 ;; https://lists.iankelling.org/listinfo/bbdb-csv-import, no subscription needed to post via
-;; bbdb-csv-import@lists.iankelling.org
+;; bbdb-csv-import@lists.iankelling.org. The maintainer would probably be happy
+;; to work on new features if something is missing.
 
 
 
 (require 'bbdb-com)
 (eval-when-compile (require 'cl))
 
-
 (defconst bbdb-csv-import-thunderbird
   '((:namelist "First Name" "Last Name")
     (:name "Display Name")
@@ -421,11 +433,16 @@ BUFFER-OR-NAME is a buffer or name of a buffer, or the current buffer if nil."
                                (data (assoc-plus (if (consp e) (cadr e) e) csv-record)))
                            (if data (list data-name data)))))
         ;; set the arguments to bbdb-create-internal, then call it, the end.
-        (let ((name (let ((name (rd-assoc :namelist)))
-                      ;; prioritize any combination of first middle last over :name
-                      (if (>= (length name) 2)
-                          (mapconcat 'identity name " ")
-                        (car (rd-assoc :name)))))
+        (let ((name (let ((namelist (rd-assoc :namelist))
+                          (let-name (car (rd-assoc :name))))
+                      ;; priority: 2 or more from :namelist, then non-empty :name, then
+                      ;; any single element of :namelist
+                      (cond ((>= (length namelist) 2)
+                             (mapconcat 'identity namelist " "))
+                            ((not (null let-name))
+                             let-name)
+                            (t
+                             (mapconcat 'identity namelist " ")))))
               (affix (rd-assoc :affix))
               (aka (rd-assoc :aka))
               (organization (rd-assoc :organization))
@@ -461,10 +478,10 @@ BUFFER-OR-NAME is a buffer or name of a buffer, or the current buffer if nil."
                            (map-bbdb :address)))
               (xfields (rd (lambda (list)
                              (let ((e (car list)))
-                               (while (string-match "-" e)
-                                 (setq e (replace-match "" nil nil e)))
                                (while (string-match " +" e)
                                  (setq e (replace-match "-" nil nil e)))
+                               (while (string-match "--+" e)
+                                 (setq e (replace-match "-" nil nil e)))
                                (setq e (make-symbol (downcase e)))
                                (cons e (cadr list)))) ;; change from (a b) to (a . b)
                            (rd #'assoc-expand (map-bbdb :xfields)))))