converting bbdb to pine?

0 views
Skip to first unread message

Matt McClure

unread,
Aug 24, 1999, 3:00:00 AM8/24/99
to
Does anyone know of a good way to convert a bbdb address book to a pine
address book? Perhaps someone has a perl script already written?

Thanks,
Matt

--
--------------------------------------
| matthew.mc...@aya.yale.edu |
| http://www.faradic.net/~mmcclure |
--------------------------------------


Nicole

unread,
Aug 24, 1999, 3:00:00 AM8/24/99
to

> Does anyone know of a good way to convert a bbdb address book to a
> pine address book? Perhaps someone has a perl script already written?

I'd search freshmeat... www.freshmeat.net

You might find something there... otherwise write it yourself ;o)

-nicole


Matt McClure

unread,
Aug 25, 1999, 3:00:00 AM8/25/99
to
Here's some emacs-lisp code (started by Alex Schroeder) to convert bbdb
address books to a pine .addressbook file.

Matt

;;;;;

(defvar bbdb-mailrc-file-name "~/.addressbook"
"Filename to write mail aliases to.")

(defun bbdb-write-dot-addressbook (to-file)
(interactive (list (read-file-name "Export To File: " "" nil nil bbdb-mailrc-file-name)))
(setq bbdb-mailrc-file-name (expand-file-name to-file))
;; `good' are people with netaddresses, `bad' are people without. The
;; people are taken of the list records and put on either the good or
;; the bad list.
(let ((good '()) (bad '())
(records (bbdb-records))
(grouped-good '()) (grouped-bad '())
(grouped-records (bbdb-records))
(mail-groups-alist '()))
;; Open .mailrc file
(find-file bbdb-mailrc-file-name)
(widen)
(erase-buffer)
;; Loop through records to print.
(while records
(if (bbdb-record-net (car records))
(setq good (cons (car records) good))
(setq bad (cons (car records) bad)))
(setq records (cdr records)))
;; write all net-addresses into .mailrc
(insert (mapconcat
(function (lambda (x)
(let ((alias (concat (bbdb-record-firstname x)
" "
(bbdb-record-lastname x)))
(name (concat (bbdb-record-lastname x)
", "
(bbdb-record-firstname x)))
(email (car (bbdb-record-net x)))
)
(concat alias
"\t"
name
"\t"
email
)
)))
(nreverse good)
"\n"))
;; Mail groups
;; get the mail-aliases
(while grouped-records
(if (and
(bbdb-record-net (car grouped-records))
(assoc 'mail-alias (bbdb-record-raw-notes (car grouped-records))))
(setq grouped-good (cons (car grouped-records) grouped-good))
(setq grouped-bad (cons (car grouped-records) grouped-bad)))
(setq grouped-records (cdr grouped-records)))

(while grouped-good
(let ((aliases (split-string
(cdr (assoc 'mail-alias
(bbdb-record-raw-notes (car grouped-good))))
"[, \f\t\n\r\v]+")))
(while aliases
;; store the name associated with alias somehow
(setq mail-groups-alist
(cons (cons (car aliases)
(concat "\""
(bbdb-record-firstname (car grouped-good))
" "
(bbdb-record-lastname (car grouped-good))
"\""))
mail-groups-alist))
(setq aliases (cdr aliases))))
(setq grouped-good (cdr grouped-good)))

(setq mail-groups-alist (sort mail-groups-alist
(lambda (x y)
(string< (car x) (car y)))))

;; put each name from mail-groups-alist into the appropriate mail aliases
(setq assn '("" . ""))
(while mail-groups-alist
(let ((assn-new (car mail-groups-alist)))
(if (string= (car assn) "")
(insert (concat "\n" (car assn-new) "\t\t("))
(if (not (string= (car assn) (car assn-new)))
(insert (concat ")\n" (car assn-new) "\t\t("))))
(insert (concat (cdr assn-new) ","))
(setq mail-groups-alist (cdr mail-groups-alist))
(setq assn assn-new)))

(if (not (string= (car assn) ""))
(insert ")\n"))

;; Feedback on the output quality.
(if bad
(message "There were %d people with bad or missing net addresses."
(length bad))
(message "Done."))))

;;;;;

Matt McClure

unread,
Aug 26, 1999, 3:00:00 AM8/26/99
to
A new version which converts spaces within aliases (which pine doesn't
like) to underscores:

;;;;;

(start 0)
)
(while (string-match " " alias start)
(let ((index (string-match " " alias start)))
(store-substring alias index "_")
(setq start index)))

(let ((alias (concat (bbdb-record-firstname (car grouped-good))
"_"
(bbdb-record-lastname (car grouped-good))
))
(start 0))
(while (string-match " " alias start)
(let ((index (string-match " " alias start)))
(store-substring alias index "_")
(setq start index)))
(cons (cons (car aliases) alias)
mail-groups-alist)))

Reply all
Reply to author
Forward
0 new messages