~ubuntu-branches/ubuntu/trusty/bbdb/trusty-proposed

« back to all changes in this revision

Viewing changes to bits/bbdb-canonicalize-lt.el

  • Committer: Bazaar Package Importer
  • Author(s): Barak A. Pearlmutter
  • Date: 2009-12-27 20:26:22 UTC
  • Revision ID: james.westby@ubuntu.com-20091227202622-zlyfvb108whhwo8w
Tags: 2.35.cvs20080316-2
* Misc additional files in bits/
* Minor packaging tweaks
* Build dependency for /usr/bin/tex (closes: #560582)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
3
 
 
4
;;; Useful name canonicalizer; consider inclusion in main package.
 
5
 
 
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))
 
9
  (cond
 
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))
 
25
   ;; strip Dr pronoun
 
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))
 
40
    "")
 
41
   (t name)))