Okay; here's the first stab at getting addresses parsed properly by
mail-extr. It's brute force; it uses rfc822.el to determine if the
addresses have been separated correctly, and backs off and retries if
they haven't. This probably isn't an issue on your 22GHz processor,
but it makes me unhappy to do it this way. The alternative, alas, is a
hell of a lot of code duplication. I've contacted the original
maintaner of mail-extr and RMS to see about getting the problem fixed
at source.

The code below can be stuffed in a file somewhere and loaded after the
original one is defined in bbdb-snarf.el.

FWIW, I investigated what mail-extr and friends can do. Firstly,
rfc822.el will only return addresses - it'll discard all the comments
and such. GNU Emacs' current version of mail-extr claims to be able to
do multiple addresses, but the test string I fed it caused it to kick
out an amount of garbage for all but the first address. XEmacs
mail-extr contains some changes to assorted internal data, such as
domain->string conversion lists, but doesn't have the multiple-address
capability at all.

Ideally, BBDB should allow you to use whatever function you like for
this task, but so far I've found at least one point where there's an
explicit call to bbdb-address-extract-components. So I guess I'll fix
that first!

Cheers,
Waider.
------------------------------------->8----------------------------------------
(require rfc822)
(require mail-extr)

(defun bbdb-extract-address-components ( addrline )
  "Split ADDRLINE into a list of parsed addresses."
  (let (addrs (start 0))
    (setq addrline (concat addrline ",")) ;; kludge, to make parsing easier
    ;; Addresses are separated by commas. This is probably the worst
    ;; possible way to do this, but it does cut down on the amount of
    ;; coding effort I have to duplicate. Basically, we split on
    ;; commas, and then try and parse what we've found. Pathologically
    ;; bad address lines will probably break this.
    (while (string-match "\\([^,]+\\)," addrline start)
      (let* ((thisaddr (substring addrline 0 (match-end 1)))
             (comma (match-end 0)) ;; rfc822-addresses trashes match-data
             (parsed (rfc822-addresses thisaddr)))
        (if (string-match "(" (car parsed)) ;; rfc822 didn't like it.
            (setq start comma)
          (setq addrs
                (append addrs (list
                               (mail-extract-address-components
                                thisaddr)))
                ;; throw away what we just parsed
                addrline (substring addrline comma)
                start 0))))
    addrs))

-- 
[EMAIL PROTECTED] / Yes, it /is/ very personal of me.
"operating complicated machinery when possessed of the cognitive powers of a
 sea slug and the disposition of a polar bear with a toothache is most unwise."
                                   - John Walker, _The Hacker's Diet_

_______________________________________________
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/

Reply via email to