1
;;; As per email to bbdb-info list from Len Trigg <len@netvalue.net>
2
;;; http://sourceforge.net/mailarchive/message.php?msg_name=hbr60bfmvt.wl%25len@netvalue.net.nz
4
;;; Useful name canonicalizer; consider inclusion in main package.
6
(defun bbdb-canonicalize-name-hook-lt (name)
7
"Function used to canonicalize the full names of bbdb entries."
8
;; (message (format "canonicalize name %s" name))
10
;; strip extra quotes (Some MS mailer likes "'full name'")
11
((string-match "\\`[`'\"]\\(.*\\)[`'\"]\\'" name)
12
(bbdb-match-substring name 1))
13
;; replace multiple whitespace with single
14
((string-match "[ \f\t\n\r\v]\\{2,\\}" name)
15
(replace-match " " nil t name))
16
;; remove anything in round brackets, e.g.: "Firstname Surname (E-mail)"
17
((string-match "[ ]+(.*)" name)
18
(replace-match "" nil t name))
19
;; strip leading whitespace (this is a bug in std11 libs?)
20
((string-match "\\`[ \t]+\\(.*\\)" name)
21
(bbdb-match-substring name 1))
22
;; strip trailing whitespace
23
((string-match "\\(.*\\)[ ]+\\'" name)
24
(bbdb-match-substring name 1))
26
((string-match "\\`Dr\\.? \\(.*\\)" name)
27
(bbdb-match-substring name 1))
28
;; person and person -> person & person
29
((string-match "\\`\\(\\w+\\) and \\(\\w.+\\)\\'" name)
30
(concat (bbdb-match-substring name 1) " & " (bbdb-match-substring name 2)))
31
;; Surname, Firstname -> Firstname Surname
32
((string-match "\\`\\(\\w.+\\), \\(\\w.+\\)\\'" name)
33
(concat (bbdb-match-substring name 2) " " (bbdb-match-substring name 1)))
34
;; Sometimes get an email address in the name part. Map the username to a name: <Name@domain> -> Name
35
((string-match "\\`<\\(.*\\)@.*\\'" name)
36
(bbdb-match-substring name 1))
37
;; replace name without any whitespace with empty; I don't want bbdb names containing only a single name
38
((string-match "\\`\\(\\w+\\)\\'" name)
39
;;(message (format "Eliding name %s" name))