comparison lisp/net/eudcb-bbdb.el @ 49598:0d8b17d428b5

Trailing whitepace deleted.
author Juanma Barranquero <lekktu@gmail.com>
date Tue, 04 Feb 2003 13:24:35 +0000
parents 6d743d659035
children 695cf19ef79e d7ddb3e565de
comparison
equal deleted inserted replaced
49597:e88404e8f2cf 49598:0d8b17d428b5
48 (phone . phones)) 48 (phone . phones))
49 "Alist mapping EUDC attribute names to BBDB names.") 49 "Alist mapping EUDC attribute names to BBDB names.")
50 50
51 (eudc-protocol-set 'eudc-query-function 'eudc-bbdb-query-internal 'bbdb) 51 (eudc-protocol-set 'eudc-query-function 'eudc-bbdb-query-internal 'bbdb)
52 (eudc-protocol-set 'eudc-list-attributes-function nil 'bbdb) 52 (eudc-protocol-set 'eudc-list-attributes-function nil 'bbdb)
53 (eudc-protocol-set 'eudc-protocol-attributes-translation-alist 53 (eudc-protocol-set 'eudc-protocol-attributes-translation-alist
54 'eudc-bbdb-attributes-translation-alist 'bbdb) 54 'eudc-bbdb-attributes-translation-alist 'bbdb)
55 (eudc-protocol-set 'eudc-bbdb-conversion-alist nil 'bbdb) 55 (eudc-protocol-set 'eudc-bbdb-conversion-alist nil 'bbdb)
56 (eudc-protocol-set 'eudc-protocol-has-default-query-attributes nil 'bbdb) 56 (eudc-protocol-set 'eudc-protocol-has-default-query-attributes nil 'bbdb)
57 57
58 (defun eudc-bbdb-format-query (query) 58 (defun eudc-bbdb-format-query (query)
66 (company (cdr (assq 'company query))) 66 (company (cdr (assq 'company query)))
67 (net (cdr (assq 'net query))) 67 (net (cdr (assq 'net query)))
68 (notes (cdr (assq 'notes query))) 68 (notes (cdr (assq 'notes query)))
69 (phone (cdr (assq 'phone query)))) 69 (phone (cdr (assq 'phone query))))
70 (list name company net notes phone))) 70 (list name company net notes phone)))
71 71
72 72
73 (defun eudc-bbdb-filter-non-matching-record (record) 73 (defun eudc-bbdb-filter-non-matching-record (record)
74 "Return RECORD if it matches `eudc-bbdb-current-query', nil otherwise." 74 "Return RECORD if it matches `eudc-bbdb-current-query', nil otherwise."
75 (catch 'unmatch 75 (catch 'unmatch
76 (progn 76 (progn
77 (mapcar 77 (mapcar
78 (function 78 (function
79 (lambda (condition) 79 (lambda (condition)
80 (let ((attr (car condition)) 80 (let ((attr (car condition))
81 (val (cdr condition)) 81 (val (cdr condition))
82 (case-fold-search t) 82 (case-fold-search t)
83 bbdb-val) 83 bbdb-val)
84 (or (and (memq attr '(firstname lastname aka company phones addresses net)) 84 (or (and (memq attr '(firstname lastname aka company phones addresses net))
85 (progn 85 (progn
86 (setq bbdb-val 86 (setq bbdb-val
87 (eval (list (intern (concat "bbdb-record-" 87 (eval (list (intern (concat "bbdb-record-"
88 (symbol-name attr))) 88 (symbol-name attr)))
89 'record))) 89 'record)))
90 (if (listp bbdb-val) 90 (if (listp bbdb-val)
91 (if eudc-bbdb-enable-substring-matches 91 (if eudc-bbdb-enable-substring-matches
92 (eval `(or ,@(mapcar '(lambda (subval) 92 (eval `(or ,@(mapcar '(lambda (subval)
106 (mapcar (function 106 (mapcar (function
107 (lambda (phone) 107 (lambda (phone)
108 (if eudc-bbdb-use-locations-as-attribute-names 108 (if eudc-bbdb-use-locations-as-attribute-names
109 (cons (intern (bbdb-phone-location phone)) 109 (cons (intern (bbdb-phone-location phone))
110 (bbdb-phone-string phone)) 110 (bbdb-phone-string phone))
111 (cons 'phones (format "%s: %s" 111 (cons 'phones (format "%s: %s"
112 (bbdb-phone-location phone) 112 (bbdb-phone-location phone)
113 (bbdb-phone-string phone)))))) 113 (bbdb-phone-string phone))))))
114 (bbdb-record-phones record))) 114 (bbdb-record-phones record)))
115 115
116 (defun eudc-bbdb-extract-addresses (record) 116 (defun eudc-bbdb-extract-addresses (record)
121 (concat s "\n")) 121 (concat s "\n"))
122 (unless (= 0 (length (setq s (bbdb-address-street2 address)))) 122 (unless (= 0 (length (setq s (bbdb-address-street2 address))))
123 (concat s "\n")) 123 (concat s "\n"))
124 (unless (= 0 (length (setq s (bbdb-address-street3 address)))) 124 (unless (= 0 (length (setq s (bbdb-address-street3 address))))
125 (concat s "\n")) 125 (concat s "\n"))
126 (progn 126 (progn
127 (setq c (bbdb-address-city address)) 127 (setq c (bbdb-address-city address))
128 (setq s (bbdb-address-state address)) 128 (setq s (bbdb-address-state address))
129 (if (and (> (length c) 0) (> (length s) 0)) 129 (if (and (> (length c) 0) (> (length s) 0))
130 (concat c ", " s " ") 130 (concat c ", " s " ")
131 (concat c " "))) 131 (concat c " ")))
141 (let ((attrs (or eudc-bbdb-current-return-attributes 141 (let ((attrs (or eudc-bbdb-current-return-attributes
142 '(firstname lastname aka company phones addresses net notes))) 142 '(firstname lastname aka company phones addresses net notes)))
143 attr 143 attr
144 eudc-rec 144 eudc-rec
145 val) 145 val)
146 (while (prog1 146 (while (prog1
147 (setq attr (car attrs)) 147 (setq attr (car attrs))
148 (setq attrs (cdr attrs))) 148 (setq attrs (cdr attrs)))
149 (cond 149 (cond
150 ((eq attr 'phones) 150 ((eq attr 'phones)
151 (setq val (eudc-bbdb-extract-phones record))) 151 (setq val (eudc-bbdb-extract-phones record)))
152 ((eq attr 'addresses) 152 ((eq attr 'addresses)
153 (setq val (eudc-bbdb-extract-addresses record))) 153 (setq val (eudc-bbdb-extract-addresses record)))
154 ((memq attr '(firstname lastname aka company net notes)) 154 ((memq attr '(firstname lastname aka company net notes))
155 (setq val (eval 155 (setq val (eval
156 (list (intern 156 (list (intern
157 (concat "bbdb-record-" 157 (concat "bbdb-record-"
158 (symbol-name attr))) 158 (symbol-name attr)))
159 'record)))) 159 'record))))
160 (t 160 (t
161 (setq val "Unknown BBDB attribute"))) 161 (setq val "Unknown BBDB attribute")))
162 (if val 162 (if val
163 (cond 163 (cond
164 ((memq attr '(phones addresses)) 164 ((memq attr '(phones addresses))
165 (setq eudc-rec (append val eudc-rec))) 165 (setq eudc-rec (append val eudc-rec)))
166 ((and (listp val) 166 ((and (listp val)
167 (= 1 (length val))) 167 (= 1 (length val)))
168 (setq eudc-rec (cons (cons attr (car val)) eudc-rec))) 168 (setq eudc-rec (cons (cons attr (car val)) eudc-rec)))
169 ((> (length val) 0) 169 ((> (length val) 0)
170 (setq eudc-rec (cons (cons attr val) eudc-rec))) 170 (setq eudc-rec (cons (cons attr val) eudc-rec)))
171 (t 171 (t
172 (error "Unexpected attribute value"))))) 172 (error "Unexpected attribute value")))))
173 (nreverse eudc-rec))) 173 (nreverse eudc-rec)))
174 174
175 175
176 176
177 (defun eudc-bbdb-query-internal (query &optional return-attrs) 177 (defun eudc-bbdb-query-internal (query &optional return-attrs)
178 "Query BBDB with QUERY. 178 "Query BBDB with QUERY.
179 QUERY is a list of cons cells (ATTR . VALUE) where ATTRs should be valid 179 QUERY is a list of cons cells (ATTR . VALUE) where ATTRs should be valid
180 BBDB attribute names. 180 BBDB attribute names.
181 RETURN-ATTRS is a list of attributes to return, defaulting to 181 RETURN-ATTRS is a list of attributes to return, defaulting to
182 `eudc-default-return-attributes'." 182 `eudc-default-return-attributes'."
183 183
184 (let ((eudc-bbdb-current-query query) 184 (let ((eudc-bbdb-current-query query)
185 (eudc-bbdb-current-return-attributes return-attrs) 185 (eudc-bbdb-current-return-attributes return-attrs)
186 (query-attrs (eudc-bbdb-format-query query)) 186 (query-attrs (eudc-bbdb-format-query query))
200 (lambda (record) 200 (lambda (record)
201 (setq filtered (eudc-filter-duplicate-attributes record)) 201 (setq filtered (eudc-filter-duplicate-attributes record))
202 ;; If there were duplicate attributes reverse the order of the 202 ;; If there were duplicate attributes reverse the order of the
203 ;; record so the unique attributes appear first 203 ;; record so the unique attributes appear first
204 (if (> (length filtered) 1) 204 (if (> (length filtered) 1)
205 (setq filtered (mapcar (function 205 (setq filtered (mapcar (function
206 (lambda (rec) 206 (lambda (rec)
207 (reverse rec))) 207 (reverse rec)))
208 filtered))) 208 filtered)))
209 (setq result (append result filtered)))) 209 (setq result (append result filtered))))
210 (delq nil 210 (delq nil
211 (mapcar 'eudc-bbdb-format-record-as-result 211 (mapcar 'eudc-bbdb-format-record-as-result
212 (delq nil 212 (delq nil
213 (mapcar 'eudc-bbdb-filter-non-matching-record 213 (mapcar 'eudc-bbdb-filter-non-matching-record
214 records))))) 214 records)))))
215 result)) 215 result))
216 216
217 ;;}}} 217 ;;}}}
218 218