X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=bbdb-csv-import.el;h=757032a9f3aac9306aa1b229a4405f60d6df7031;hb=3b13d7284fb46353c041e458c4468b9a9e49edc5;hp=edd876010d8daa66b9d25eb780c1e9a37e687f83;hpb=670cc2486767e0d90d414f91877fc86419104f4b;p=bbdb-csv-import diff --git a/bbdb-csv-import.el b/bbdb-csv-import.el index edd8760..757032a 100644 --- a/bbdb-csv-import.el +++ b/bbdb-csv-import.el @@ -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 @@ -89,6 +90,16 @@ ;; 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 tips: +;; * The repeat keyword expands numbered field names, based on the first +;; subsequent 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 field name to create custom fields in bbdb. It downcases +;; the field name, and replaces spaces with "-". +;; * For example, if you had a csv data for bbdb's mail-alias, you could add to :xfields +;; a csv field name would become "mail-alias", like "Mail Alias" or "Mail-alias" ;;; Misc tips/troubleshooting: ;; @@ -101,16 +112,18 @@ ;; 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 ;; ;; Patches and bugs are very welcome via https://gitlab.com/iankelling/bbdb-csv-import ;; -;; Questions, feedback, etc are very welcome via email to Ian Kelling -;; . I will add any useful questions, answers, etc. to this -;; file. The scope/userbase of this project doesn't justify a mailing list, but if -;; it ever did I would start a mailman or discourse to act as a mailing list -;; and forum. +;; 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 + ;;; Code: @@ -119,7 +132,6 @@ (require 'bbdb-com) (eval-when-compile (require 'cl)) - (defconst bbdb-csv-import-thunderbird '((:namelist "First Name" "Last Name") (:name "Display Name") @@ -324,10 +336,13 @@ See the commentary section of this file for more details." (defun bbdb-csv-import-expand-repeats (csv-fields list) - "Return new list where elements from LIST in form (repeat elem1 ...) -become ((elem1 ...) [(elem2 ...)] ...) for as many repeating -numbered fields exist in the csv fields. elem can be a string or -a tree (a list with lists inside it)" + "Return new list where elements from LIST in form (repeat elem1 +...) become ((elem1 ...) [(elem2 ...)] ...) for as many fields +exist in the csv fields. elem can be a string or a tree (a list +with lists inside it). We use the first element as a template, +and increase its number by one, and check if it exists, and then +increment any other elements from the repeat list which have +numbers in them." (cl-flet ((replace-num (num string) ;; in STRING, replace all groups of numbers with NUM (replace-regexp-in-string "[0-9]+" @@ -415,11 +430,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)) @@ -455,8 +475,6 @@ 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))) (setq e (make-symbol (downcase e)))