1 ;;; wl-acap.el --- ACAP support for Wanderlust.
3 ;; Copyright (C) 2001 Yuuichi Teranishi <teranisi@gohome.org>
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
8 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
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.
32 ((and (not (featurep 'utf-2000))
33 (module-installed-p 'un-define))
35 ((and (featurep 'xemacs)
36 (not (featurep 'utf-2000))
37 (module-installed-p 'xemacs-ucs))
38 (require 'xemacs-ucs)))
47 (defconst wl-acap-dataset-class "vendor.wanderlust")
48 (defconst wl-acap-entry-name "settings")
50 (defcustom wl-acap-user (or (getenv "USER")
57 (defcustom wl-acap-server nil
59 If nil, SLP is used to find ACAP server.
60 If nil and SLP is not available, localhost is assumed."
64 (defcustom wl-acap-port nil
66 Only valid when `wl-acap-server' is non-nil.
67 If nil, default acap port is used."
71 (defcustom wl-acap-authenticate-type 'cram-md5
72 "ACAP authenticate type."
76 (defcustom wl-acap-stream-type nil
81 (defcustom wl-acap-extra-options nil
82 "Extra options to be saved on ACAP server."
83 :type '(repeat symbol)
86 ;; Encoding string as BASE64 is temporal solution.
87 ;; As far as I know, current implementation of ACAP server
88 ;; (cyrus-smlacapd 0.5) does not accept literal argument for STORE.
89 (defvar wl-acap-base64-encode-options
91 wl-draft-config-alist)
92 "Options which should be encoded with base64 to store ACAP server.")
94 (defcustom wl-acap-coding-system 'utf-8
95 "Coding system for ACAP."
99 (defvar wl-acap-original-msgdb-dir nil)
101 (defun wl-acap-exit ()
103 (setq elmo-msgdb-dir wl-acap-original-msgdb-dir))
105 (defun wl-acap-init ()
106 "A candidate for `wl-folder-init-function'."
107 (let ((service (wl-acap-find-acap-service))
108 proc entries settings folder-top type)
109 (unless (car service) (error "No ACAP service found"))
110 (setq proc (acap-open (car service)
112 (upcase (symbol-name wl-acap-authenticate-type))
114 (setq entries (acap-response-entries
115 (acap-search proc (concat "/"
116 wl-acap-dataset-class
120 (when (string= (acap-response-entry-entry (car entries))
122 (setq settings (car (acap-response-entry-return-data-list
125 (setq entries (cdr entries)))
130 (let ((sym (wl-acap-symbol (car x))))
132 ((and sym (eq sym 'wl-folders))
134 (setq wl-folder-entity
135 (wl-acap-create-folder-entity (cadr x)))
137 ((and sym (boundp sym))
138 (setq type (custom-variable-type sym))
143 ((or (eq (car type) 'string)
144 (and (eq (car type) 'choice)
145 (memq 'string type)))
146 (if (memq sym wl-acap-base64-encode-options)
147 (wl-acap-base64-decode-string (cadr x))
148 (decode-coding-string
150 wl-acap-coding-system)))
155 wl-acap-base64-encode-options)
156 (wl-acap-base64-decode-string (cadr x))
159 (decode-coding-string
161 wl-acap-coding-system)
164 (t 'wl-acap-ignored))))
167 (dolist (setting settings)
168 (set (car setting) (cdr setting)))
169 ;; Database directory becomes specific to the ACAP server.
170 (setq wl-acap-original-msgdb-dir elmo-msgdb-dir)
171 (setq elmo-msgdb-dir (expand-file-name
172 (concat "acap/" (car service) "/" wl-acap-user)
176 (defun wl-acap-create-folder-entity (string)
178 (message "Initializing folder...")
180 (setq string (elmo-base64-decode-string string))
181 (setq string (decode-coding-string string wl-acap-coding-system))
183 (goto-char (point-min))
184 (while (and (not (eobp))
185 (setq entity (wl-create-folder-entity-from-buffer)))
186 (unless (eq entity 'ignore)
187 (wl-append folders (list entity))))
188 (message "Initializing folder...done")
189 (list wl-folder-desktop-name 'group folders))))
191 (defun wl-acap-find-acap-service ()
192 (or (and wl-acap-server
193 (cons wl-acap-server wl-acap-port))
195 (message "Searching ACAP server...")
196 (prog1 (let ((response (condition-case nil
197 (slp-findsrvs "acap")
201 (if (> (length (slp-response-body response)) 1)
205 "Select ACAP server: "
206 (mapcar (lambda (body)
209 (slp-response-srv-url-host
211 (when (slp-response-srv-url-port
215 (slp-response-srv-url-port
217 (slp-response-body response)))
220 (dolist (entry (slp-response-body response))
223 (slp-response-srv-url-host
226 (slp-response-srv-url-port
230 (slp-response-srv-url-port
233 (throw 'done entry))))))
234 (setq response (car (slp-response-body response))))
235 (cons (slp-response-srv-url-host response)
236 (slp-response-srv-url-port response))))
237 (message "Searching ACAP server...done")))
238 (cons "localhost" nil)))
240 (defun wl-acap-name (option)
241 (let ((name (symbol-name option))
243 (cond ((string-match "^wl-" name)
244 (setq name (substring name (match-end 0))
246 ((string-match "^elmo-" name)
247 (setq name (substring name (match-end 0))
250 wl-acap-dataset-class "." prefix "."
251 (mapconcat 'capitalize (split-string name "-") ""))))
253 (defun wl-acap-symbol (name)
254 (let (case-fold-search li)
255 (when (string-match (concat "^" (regexp-quote wl-acap-dataset-class)
256 "\\.\\([^\\.]+\\)\\.") name)
257 (setq li (list (match-string 1 name))
258 name (substring name (match-end 0)))
259 (while (string-match "^[A-Z][a-z0-9]*" name)
260 (setq li (cons (match-string 0 name) li))
261 (setq name (substring name (match-end 0))))
262 (intern (mapconcat 'downcase (nreverse li) "-")))))
264 (defun wl-acap-list-options ()
265 (nconc (mapcar 'car (append (custom-group-members 'wl-setting nil)
266 (custom-group-members 'elmo-setting nil)))
267 wl-acap-extra-options))
269 (defun wl-acap-store-folders (proc)
271 (insert-file-contents wl-folders-file)
274 (list (concat "/" wl-acap-dataset-class "/~/"
276 (concat wl-acap-dataset-class ".wl.Folders")
277 (wl-acap-base64-encode-string (buffer-string))))))
279 (defun wl-acap-base64-encode-string (string)
280 (elmo-base64-encode-string
281 (encode-coding-string string wl-acap-coding-system)
284 (defun wl-acap-base64-decode-string (string)
285 (decode-coding-string
286 (elmo-base64-decode-string string )
287 wl-acap-coding-system))
289 (defun wl-acap-store ()
290 "Store Wanderlust configuration to the ACAP server."
294 (let ((service (wl-acap-find-acap-service))
296 (setq proc (acap-open (car service)
298 (upcase (symbol-name wl-acap-authenticate-type))
300 (dolist (option (wl-acap-list-options))
302 (cons (wl-acap-name option) settings)
304 (cons (when (symbol-value option)
305 (setq type (custom-variable-type option))
307 ((or (eq (car type) 'string)
308 (and (eq (car type) 'choice)
309 (memq 'string type)))
310 (if (memq option wl-acap-base64-encode-options)
311 (wl-acap-base64-encode-string
312 (symbol-value option))
313 (encode-coding-string
314 (symbol-value option)
315 wl-acap-coding-system)))
316 (t (if (memq option wl-acap-base64-encode-options)
317 (wl-acap-base64-encode-string
318 (prin1-to-string (symbol-value option)))
319 (encode-coding-string
320 (prin1-to-string (symbol-value option))
321 wl-acap-coding-system)))))
325 (message "Storing settings...")
330 "/" wl-acap-dataset-class "/~/" wl-acap-entry-name))
331 (nreverse settings)))
332 (message "Storing folders...")
333 (wl-acap-store-folders proc)
334 ;; Does not work correctly??
335 ;; (acap-setacl proc (list
337 ;; "/" wl-acap-dataset-class "/~/"))
338 ;; "anyone" "") ; protect.
342 (message "Store completed."))))
345 (product-provide (provide 'wl-acap) (require 'wl-version))
347 ;;; wl-acap.el ends here