Rob McNicholas wrote:
> 
> I'm just starting to play with 2.0b1, and it's pretty cool.  But tell
> me: you HAVE written a .bbdb -> address book converter, right?

Sigh.

Well, yes, I did start writing such a beast, and it kinda-sorta-almost
works.  And it's included below.

BUT, the first thing you will discover upon doing this is that the
Netscape address book is really incredibly lame.  It was intended to be
a replacement for .mailrc, not for .bbdb.  It was written in a very
short amount of time.  It may be BBDB some day, but it's not now, and if
you try to treat it as such, you'll be an unhappy camper.  

Among other things, it doesn't understand that people can have multiple
addresses, making the "notes" field of dubious usefulness.  There's also
probably a lot of n-squarededness in it that will bite you when you've
got thousands of entries.  Not to mention that the address book window
will be totally unmanagable.  And so on.  You don't have to tell me
about the new shortcomings of the Netscape address book as you discover
them -- believe me, I know.

But, despite all that, if anyone improves this lisp code, please send me
a copy.  It doesn't deal with aliases and mailing lists quite right yet,
writes out the notes fields incorrectly (I think) and probably ought to
have a configurable list of fields not to bother converting.  Or
something.

-- 
Jamie Zawinski    [EMAIL PROTECTED]   http://www.netscape.com/people/jwz/
``A signature isn't a return address, it is the ASCII equivalent of a
  black velvet clown painting; it's a rectangle of carets surrounding
  a quote from a literary giant of weeniedom like Heinlein or Dr. Who.''
                                                         -- Chris Maeda
;;; -*- Mode:Emacs-Lisp -*-

;;; This file is the part of the Insidious Big Brother Database (aka BBDB),
;;; copyright (c) 1991, 1992, 1993, 1995 Jamie Zawinski <[EMAIL PROTECTED]>.
;;; Converting a BBDB database to a Netscape Address Book.
;;; last change 1-oct-95.

;;; The Insidious Big Brother Database is free software; you can redistribute
;;; it and/or modify it under the terms of the GNU General Public License as
;;; published by the Free Software Foundation; either version 2, or (at your
;;; option) any later version.
;;;
;;; BBDB is distributed in the hope that it will be useful, but WITHOUT ANY
;;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
;;; FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
;;; details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Emacs; see the file COPYING.  If not, write to
;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

(require 'bbdb)

(defun bbdb-to-netscape ()
  (let* ((target (cons bbdb-define-all-aliases-field "."))
         (records (bbdb-search (bbdb-records) nil nil nil target))
         result record aliases match
         (lists nil)
         (single-aliases nil)
         (count 0)
         )
    (while records
      (setq record (car records))
      (setq aliases (bbdb-split 
                     (bbdb-record-getprop record bbdb-define-all-aliases-field)
                     ","))
      (while aliases
        (if (setq match (assoc (car aliases) result))
            (nconc match (cons record nil))
          (setq result (cons (list (car aliases) record) result)))
        (setq aliases (cdr aliases)))
      (setq records (cdr records)))
    (while result
      (let ((alias (downcase (car (car result))))
            (expansion (cdr (car result))))
        (cond
         ((cdr expansion)
          (setq lists (cons (cons alias expansion) lists)))
         (expansion
          (setq single-aliases (cons (cons (car expansion) alias)
                                     single-aliases))))
        (setq result (cdr result))))

    (setq xxx lists)

    (setq records (bbdb-records))
    (set-buffer (get-buffer-create "*netscape-address-book*"))
    (erase-buffer)
    (insert "<!DOCTYPE NETSCAPE-Addressbook-file-1>\n"
            "<!-- This is an automatically generated file.\n"
            "It will be read and overwritten.\n"
            "Do Not Edit! -->\n"
            "<TITLE>" (user-full-name) "'s Address book</TITLE>\n"
            "<H1>" (user-full-name) "'s Address book</H1>\n"
            "\n"
            "<DL><p>\n")
    (while records
      (setq record (car records))
      (insert "    <DT><A HREF=\"mailto:")
      (let ((net (car (bbdb-record-net record))))
        (if net (insert net))
        (insert "\" ALIASID=\"")
        (prin1 count (current-buffer))
        (insert "\"")
        (message "%d..." count)
        (setq count (1+ count))
        (cond ((setq match (cdr (assq record single-aliases)))
               (insert " NICKNAME=\"")
               (princ match (current-buffer))
               (insert "\"")))
        (insert ">")
        (insert (or (bbdb-record-name record)
                    net
                    (bbdb-record-company record)
                    "")))

      (insert "</A>\n")
      (let ((phones (bbdb-record-phones record))
            (addrs (bbdb-record-addresses record))
            (aka (bbdb-record-aka record))
            phone
            )

        (insert "<DD>")
        (setq match nil)
        (while phones
          (setq phone (car phones))
          (setq match t)
          (insert (format " %14s: " (bbdb-phone-location phone)))
          (insert (bbdb-phone-string phone) "\n")
          (setq phones (cdr phones)))
        (let (addr c s)
          (while addrs
            (setq addr (car addrs))
            (setq match t)
            (insert (format " %14s: " (bbdb-address-location addr)))
            (if (= 0 (length (setq s (bbdb-address-street1 addr)))) nil
              (indent-to 17) (insert s "\n"))
            (if (= 0 (length (setq s (bbdb-address-street2 addr)))) nil
              (indent-to 17) (insert s "\n"))
            (if (= 0 (length (setq s (bbdb-address-street3 addr)))) nil
              (indent-to 17) (insert s "\n"))
            (indent-to 17)
            (insert (setq c (bbdb-address-city addr)))
            (setq s (bbdb-address-state addr))
            (if (and (> (length c) 0) (> (length s) 0)) (insert ", "))
            (insert s "  ")
            (insert (bbdb-address-zip-string addr) "\n")
            (setq addrs (cdr addrs))))
        (cond (aka
               (setq match t)
               (insert (format " %14s: %s\n" "AKA"
                               (mapconcat (function identity) aka ", ")))))
        (let ((notes (bbdb-record-raw-notes record)))
          (if (stringp notes)
              (setq notes (list (cons 'notes notes))))
          (while notes
            (if (eq (car (car notes)) 'mail-alias)
                nil
              (setq match t)
              (insert (format " %14s: " (car (car notes))))
              (let ((p (point)))
                (insert (cdr (car notes)))
                (save-excursion
                  (save-restriction
                    (narrow-to-region p (1- (point)))
                    (goto-char (1+ p))
                    (while (search-forward "\n" nil t)
                      (forward-char -1)
                      (insert "<BR>")
                      (forward-char 1)
                      (insert (make-string 17 ?\ )))))
                (insert "\n")))
            (setq notes (cdr notes)))))

      (or match (delete-char -4))

      (setq records (cdr records))
      )
    (insert "</DL><p>\n")
    ))

Reply via email to