aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Wiegley2005-11-01 07:10:36 +0000
committerJohn Wiegley2005-11-01 07:10:36 +0000
commitbff4d65f5b0fc48d832ddd3f4949d1df805004e0 (patch)
tree30e0820f346c9042b0cc5387d92f05dc29ee46f3
parent6ce65ff6782fff5179619f2a23273706bf297c12 (diff)
downloademacs-bff4d65f5b0fc48d832ddd3f4949d1df805004e0.tar.gz
emacs-bff4d65f5b0fc48d832ddd3f4949d1df805004e0.zip
(eudc-mab-query-internal): Added backend support for OS/X's
AddressBook, by calling out to the open source program "contacts" (installable through Fink).
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/net/eudcb-mab.el132
2 files changed, 138 insertions, 0 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 771eabab74e..ccea8fc6f89 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,11 @@
12005-11-01 John Wiegley <johnw@newartisans.com> 12005-11-01 John Wiegley <johnw@newartisans.com>
2 2
3 * iswitchb.el (iswitchb-define-mode-map): Re-enabled the
4 toggle-ignore keybinding (C-a). The author said it had been
5 disabled much earlier due to a possible incompatibility, but after
6 many months of usage I have encountered no problems (and it is a
7 rather useful option, especially for switching to " *temp*").
8
3 * net/eudcb-mab.el (eudc-mab-query-internal): Added backend 9 * net/eudcb-mab.el (eudc-mab-query-internal): Added backend
4 support for OS/X's AddressBook, by calling out to the open source 10 support for OS/X's AddressBook, by calling out to the open source
5 program "contacts" (installable through Fink). 11 program "contacts" (installable through Fink).
diff --git a/lisp/net/eudcb-mab.el b/lisp/net/eudcb-mab.el
new file mode 100644
index 00000000000..cd6f32dba0c
--- /dev/null
+++ b/lisp/net/eudcb-mab.el
@@ -0,0 +1,132 @@
1;;; eudcb-mab.el --- Emacs Unified Directory Client - AddressBook backend
2
3;; Copyright (C) 2003 John Wiegley.
4
5;; Author: John Wiegley <johnw@newartisans.com>
6;; Keywords: comm
7
8;; This file is NOT part of GNU Emacs.
9
10;; This program is free software; you can redistribute it and/or
11;; modify it under the terms of the GNU General Public License as
12;; published by the Free Software Foundation; either version 2, or (at
13;; your option) any later version.
14
15;; This program is distributed in the hope that it will be useful, but
16;; WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18;; General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs; see the file COPYING. If not, write to the
22;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23;; Boston, MA 02111-1307, USA.
24
25;;; Commentary:
26;; This library provides an interface to use the Mac's AddressBook,
27;; by way of the "contacts" command-line utility which can be found
28;; by searching on the Net.
29
30;;; Code:
31
32(require 'eudc)
33(require 'executable)
34
35;;{{{ Internal cooking
36
37(defvar eudc-mab-conversion-alist nil)
38(defvar eudc-buffer-time nil)
39(defvar eudc-contacts-file
40 "~/Library/Application Support/AddressBook/AddressBook.data")
41
42(eudc-protocol-set 'eudc-query-function 'eudc-mab-query-internal 'mab)
43(eudc-protocol-set 'eudc-list-attributes-function nil 'mab)
44(eudc-protocol-set 'eudc-mab-conversion-alist nil 'mab)
45(eudc-protocol-set 'eudc-protocol-has-default-query-attributes nil 'mab)
46
47(defun eudc-mab-query-internal (query &optional return-attrs)
48 "Query MAB with QUERY.
49QUERY is a list of cons cells (ATTR . VALUE) where ATTRs should be valid
50MAB attribute names.
51RETURN-ATTRS is a list of attributes to return, defaulting to
52`eudc-default-return-attributes'."
53
54 (let ((fmt-string "%ln:%fn:%p:%e")
55 (mab-buffer (get-buffer-create " *mab contacts*"))
56 (modified (nth 5 (file-attributes eudc-contacts-file)))
57 result)
58 (with-current-buffer mab-buffer
59 (make-local-variable 'eudc-buffer-time)
60 (goto-char (point-min))
61 (when (or (eobp) (time-less-p eudc-buffer-time modified))
62 (erase-buffer)
63 (call-process (executable-find "contacts") nil t nil
64 "-H" "-l" "-f" fmt-string)
65 (setq eudc-buffer-time modified))
66 (goto-char (point-min))
67 (while (not (eobp))
68 (let* ((args (split-string (buffer-substring (point)
69 (line-end-position))
70 "\\s-*:\\s-*"))
71 (lastname (nth 0 args))
72 (firstname (nth 1 args))
73 (phone (nth 2 args))
74 (mail (nth 3 args))
75 (matched t))
76
77 (if (string-match "\\s-+\\'" mail)
78 (setq mail (replace-match "" nil nil mail)))
79
80 (dolist (term query)
81 (cond
82 ((eq (car term) 'name)
83 (unless (string-match (cdr term)
84 (concat firstname " " lastname))
85 (setq matched nil)))
86 ((eq (car term) 'email)
87 (unless (string= (cdr term) mail)
88 (setq matched nil)))
89 ((eq (car term) 'phone))))
90
91 (when matched
92 (setq result
93 (cons `((firstname . ,firstname)
94 (lastname . ,lastname)
95 (name . ,(concat firstname " " lastname))
96 (phone . ,phone)
97 (email . ,mail)) result))))
98 (forward-line)))
99 (if (null return-attrs)
100 result
101 (let (eudc-result)
102 (dolist (entry result)
103 (let (entry-attrs abort)
104 (dolist (attr entry)
105 (when (memq (car attr) return-attrs)
106 (if (= (length (cdr attr)) 0)
107 (setq abort t)
108 (setq entry-attrs
109 (cons attr entry-attrs)))))
110 (if (and entry-attrs (not abort))
111 (setq eudc-result
112 (cons entry-attrs eudc-result)))))
113 eudc-result))))
114
115;;}}}
116
117;;{{{ High-level interfaces (interactive functions)
118
119(defun eudc-mab-set-server (dummy)
120 "Set the EUDC server to MAB."
121 (interactive)
122 (eudc-set-server dummy 'mab)
123 (message "MAB server selected"))
124
125;;}}}
126
127
128(eudc-register-protocol 'mab)
129
130(provide 'eudcb-mab)
131
132;;; eudcb-mab.el ends here