1 ;;; wl.el --- Wanderlust bootstrap.
3 ;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
4 ;; Copyright (C) 1998,1999,2000 Masahiro MURATA <muse@ba2.so-net.ne.jp>
6 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
7 ;; Masahiro MURATA <muse@ba2.so-net.ne.jp>
8 ;; Keywords: mail, net news
10 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
12 ;; This program is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; This program is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
35 (require 'wl-version) ; reduce recursive-load-depth
38 (unless (and (fboundp 'defgroup)
41 (defmacro defgroup (&rest args))
42 (defmacro defcustom (symbol value &optional doc &rest args)
43 (let ((doc (concat "*" (or doc ""))))
44 (` (defvar (, symbol) (, value) (, doc))))))
56 (provide 'wl) ; circular dependency
69 (require 'wl-highlight)
79 (defun wl-plugged-init (&optional make-alist)
80 (setq elmo-plugged wl-plugged)
81 (if wl-reset-plugged-alist
82 (elmo-set-plugged elmo-plugged))
84 (wl-make-plugged-alist))
86 (setq elmo-plugged (setq wl-plugged (elmo-plugged-p))
87 wl-modeline-plug-status wl-plugged)
89 (wl-toggle-plugged t 'flush)))
91 (defun wl-toggle-plugged (&optional arg queue-flush-only)
93 (elmo-quit) ; Disconnect current connection.
94 (unless queue-flush-only
99 (setq wl-plugged nil))
100 (t (setq wl-plugged (not wl-plugged))))
101 (elmo-set-plugged wl-plugged))
102 (setq elmo-plugged wl-plugged
103 wl-modeline-plug-status wl-plugged)
105 (let ((summaries (wl-collect-summary)))
107 (set-buffer (pop summaries))
108 (wl-summary-save-view)
109 (elmo-folder-commit wl-summary-buffer-elmo-folder))))
110 (setq wl-biff-check-folders-running nil)
114 (elmo-dop-queue-flush)
115 (unless queue-flush-only
116 (when wl-biff-check-folder-list
117 (wl-biff-check-folders)
119 (if (and wl-draft-enable-queuing
121 (wl-draft-queue-flush))
122 ;; (when (and (eq major-mode 'wl-summary-mode)
123 ;; (elmo-folder-plugged-p wl-summary-buffer-elmo-folder))
124 ;; (let* ((msgdb-dir (elmo-folder-msgdb-path
125 ;; wl-summary-buffer-elmo-folder))
126 ;; (seen-list (elmo-msgdb-seen-load msgdb-dir)))
128 ;; (wl-summary-flush-pending-append-operations seen-list))
129 ;; (elmo-msgdb-seen-save msgdb-dir seen-list)))
130 (run-hooks 'wl-plugged-hook))
132 (run-hooks 'wl-unplugged-hook))
133 (force-mode-line-update t))
137 (defvar wl-plugged-port-label-alist
138 (list (cons 119 "nntp")
141 ;;(cons elmo-pop-before-smtp-port "pop3")
143 (defconst wl-plugged-switch-variables
144 '(("Queuing" . wl-draft-enable-queuing)
145 ("AutoFlushQueue" . wl-auto-flush-queue)
146 ("DisconnectedOperation" . elmo-enable-disconnected-operation)))
148 (defvar wl-plugged-buf-name "Plugged")
149 (defvar wl-plugged-mode-map nil)
150 (defvar wl-plugged-alist nil)
151 (defvar wl-plugged-switch nil)
152 (defvar wl-plugged-winconf nil)
153 (defvar wl-plugged-sending-queue-alist nil)
154 (defvar wl-plugged-dop-queue-alist nil)
155 (defvar wl-plugged-alist-modified nil)
157 (defvar wl-plugged-mode-menu-spec
159 ["Toggle plugged" wl-plugged-toggle t]
160 ["Toggle All plugged" wl-plugged-toggle-all t]
161 ["Prev Port" wl-plugged-move-to-previous t]
162 ["Next Port" wl-plugged-move-to-next t]
163 ["Prev Server" wl-plugged-move-to-previous-server t]
164 ["Next Server" wl-plugged-move-to-next-server t]
165 ["Flush queue" wl-plugged-flush-queue t]
167 ["Exit" wl-plugged-exit t]))
171 (defun wl-plugged-setup-mouse ()
172 (define-key wl-plugged-mode-map 'button2 'wl-plugged-click))
173 (defun wl-plugged-setup-mouse ()
174 (define-key wl-plugged-mode-map [mouse-2] 'wl-plugged-click))))
176 (unless wl-plugged-mode-map
177 (setq wl-plugged-mode-map (make-sparse-keymap))
178 (define-key wl-plugged-mode-map " " 'wl-plugged-toggle)
179 (define-key wl-plugged-mode-map "\C-m" 'wl-plugged-toggle)
180 (define-key wl-plugged-mode-map "\M-t" 'wl-plugged-toggle-all)
181 (define-key wl-plugged-mode-map "q" 'wl-plugged-exit)
182 (define-key wl-plugged-mode-map "\C-t" 'wl-plugged-exit)
183 (define-key wl-plugged-mode-map "F" 'wl-plugged-flush-queue)
184 (define-key wl-plugged-mode-map "P" 'wl-plugged-move-to-previous-server)
185 (define-key wl-plugged-mode-map "N" 'wl-plugged-move-to-next-server)
186 (define-key wl-plugged-mode-map "p" 'wl-plugged-move-to-previous)
187 (define-key wl-plugged-mode-map "n" 'wl-plugged-move-to-next)
188 (define-key wl-plugged-mode-map "\e\t" 'wl-plugged-move-to-previous)
189 (define-key wl-plugged-mode-map "\t" 'wl-plugged-move-to-next)
190 (wl-plugged-setup-mouse)
194 "Menu used in Plugged mode."
195 wl-plugged-mode-menu-spec))
197 (defun wl-plugged-mode ()
198 "Mode for setting Wanderlust plugged.
199 See info under Wanderlust for full documentation.
202 \\{wl-plugged-mode-map}
204 Entering Plugged mode calls the value of `wl-plugged-mode-hook'."
206 (kill-all-local-variables)
207 (use-local-map wl-plugged-mode-map)
208 (setq major-mode 'wl-plugged-mode)
209 (setq mode-name "Plugged")
210 (easy-menu-add wl-plugged-mode-menu)
211 (wl-mode-line-buffer-identification)
212 (setq wl-plugged-switch wl-plugged)
213 (setq wl-plugged-alist-modified nil)
214 (setq buffer-read-only t)
215 (run-hooks 'wl-plugged-mode-hook))
217 (defmacro wl-plugged-string (plugged &optional time)
218 (` (if (, time) wl-plugged-auto-off
219 (if (, plugged) wl-plugged-plug-on wl-plugged-plug-off))))
221 (defmacro wl-plugged-server-indent ()
222 (` (make-string wl-plugged-server-indent ? )))
224 (defun wl-plugged-set-variables ()
225 (setq wl-plugged-sending-queue-alist
226 (wl-plugged-sending-queue-info))
227 (setq wl-plugged-dop-queue-alist
228 (wl-plugged-dop-queue-info))
229 (setq wl-plugged-alist
230 (sort (copy-sequence elmo-plugged-alist)
232 (string< (caar a) (caar b))))))
234 (defun wl-plugged-sending-queue-info ()
235 ;; sending queue status
236 (let (alist msgs sent-via server port)
237 (setq msgs (elmo-folder-list-messages
238 (wl-folder-get-elmo-folder wl-queue-folder)))
240 (setq sent-via (wl-draft-queue-info-operation (car msgs) 'get-sent-via))
242 (when (eq (nth 1 (car sent-via)) 'unplugged)
243 (setq server (car (nth 2 (car sent-via)))
244 port (cdr (nth 2 (car sent-via))))
245 (elmo-plugged-p server port) ;; add elmo-plugged-alist if nothing.
247 (wl-append-assoc-list
251 (setq sent-via (cdr sent-via)))
252 (setq msgs (cdr msgs)))
255 (defun wl-plugged-sending-queue-status (qinfo)
256 ;; sending queue status
257 (let ((len (length (cdr qinfo))))
258 (concat (wl-plugged-set-folder-icon
260 (wl-folder-get-petname wl-queue-folder))
262 (format ": %d msgs (" len)
263 (format ": %d msg (" len))
264 (mapconcat (function int-to-string) (cdr qinfo) ",")
267 (defun wl-plugged-dop-queue-info ()
270 (elmo-dop-queue (copy-sequence elmo-dop-queue))
271 dop-queue last alist server-info
273 ;(elmo-dop-queue-load)
274 (elmo-dop-queue-merge)
275 (setq dop-queue (sort elmo-dop-queue '(lambda (a b)
276 (string< (elmo-dop-queue-fname a)
277 (elmo-dop-queue-fname b)))))
278 (wl-append dop-queue (list nil)) ;; terminate(dummy)
279 (when (car dop-queue)
280 (setq last (elmo-dop-queue-fname (car dop-queue)))) ;; first
282 (when (car dop-queue)
283 (setq ope (cons (elmo-dop-queue-method-name (car dop-queue))
287 (elmo-dop-queue-arguments (car dop-queue))))
288 (car (elmo-dop-queue-arguments
289 (car dop-queue))))))))
290 (if (and (car dop-queue)
291 (string= last (elmo-dop-queue-fname (car dop-queue))))
292 (wl-append operation (list ope))
293 ;;(setq count (1+ count))
294 (when (and last (setq server-info (elmo-net-port-info
295 (wl-folder-get-elmo-folder last))))
297 (wl-append-assoc-list
299 (cons last operation)
301 (when (car dop-queue)
302 (setq last (elmo-dop-queue-fname (car dop-queue))
303 operation (list ope))))
304 (setq dop-queue (cdr dop-queue)))
307 (defun wl-plugged-dop-queue-status (qinfo &optional column)
309 (let ((operations (cdr qinfo))
310 (column (or column wl-plugged-queue-status-column)))
312 '(lambda (folder-ope)
313 (concat (wl-plugged-set-folder-icon
315 (wl-folder-get-petname (car folder-ope)))
317 (let ((opes (cdr folder-ope))
320 (if (setq pair (assoc (car (car opes)) shrinked))
321 (setcdr pair (+ (cdr pair)
322 (max (cdr (car opes)) 1)))
324 (cons (car (car opes))
325 (max (cdr (car opes)) 1))
327 (setq opes (cdr opes)))
331 (format "%s:%d" (car ope) (cdr ope))
332 (format "%s" (car ope))))
333 (nreverse shrinked) ","))
336 (concat "\n" (wl-set-string-width column "")))))
338 (defun wl-plugged-drawing (plugged-alist)
339 (let ((buffer-read-only nil)
340 (alist plugged-alist)
341 (vars wl-plugged-switch-variables)
342 last server port stream-type label plugged time
343 line len qinfo column)
346 (insert (format "%s:[%s]%s"
348 (wl-plugged-string (symbol-value (cdar vars)))
349 (if (cdr vars) " " "")))
350 (setq vars (cdr vars)))
352 (let ((elmo-plugged wl-plugged-switch))
353 (setq line (format "[%s](wl-plugged)"
354 (wl-plugged-string (elmo-plugged-p))))
355 ;; sending queue status
356 (when (setq qinfo (assoc (cons nil nil) wl-plugged-sending-queue-alist))
358 (wl-set-string-width wl-plugged-queue-status-column line)
359 (wl-plugged-sending-queue-status qinfo))))
362 (setq server (nth 0 (caar alist))
363 port (nth 1 (caar alist))
364 stream-type (nth 2 (caar alist))
365 label (nth 1 (car alist))
366 plugged (nth 2 (car alist))
367 time (nth 3 (car alist)))
368 (unless (string= last server)
370 (insert (format "%s[%s]%s\n"
371 (wl-plugged-server-indent)
373 (elmo-plugged-p server nil plugged-alist))
379 (make-string wl-plugged-port-indent ? )
380 (wl-plugged-string plugged time)
387 (cdr (assq port wl-plugged-port-label-alist))
390 (setq column (max (if line (1+ (string-width line)) 0)
391 wl-plugged-queue-status-column))
393 ;; sending queue status
394 ((setq qinfo (assoc (cons server port) wl-plugged-sending-queue-alist))
397 (wl-set-string-width column line)
398 (wl-plugged-sending-queue-status qinfo))))
400 ((setq qinfo (assoc (list server port stream-type)
401 wl-plugged-dop-queue-alist))
404 (wl-set-string-width column line)
405 (wl-plugged-dop-queue-status qinfo column)))))
407 (setq alist (cdr alist)))
408 (delete-region (1- (point-max)) (point-max)) ;; delete line at the end.
409 (goto-char (point-min))
411 (wl-highlight-plugged-current-line)
413 (set-buffer-modified-p nil)
414 (count-lines (point-min) (point-max)))
416 (defun wl-plugged-redrawing-switch (indent switch &optional time)
418 (when (re-search-forward
419 (format "^%s\\[\\([^]]+\\)\\]" (make-string indent ? )))
420 (goto-char (match-beginning 1))
421 (delete-region (match-beginning 1) (match-end 1))
422 (insert (wl-plugged-string switch time))
423 (wl-highlight-plugged-current-line)
426 (defun wl-plugged-redrawing (plugged-alist)
427 (let ((buffer-read-only nil)
428 (alist plugged-alist)
429 last server port plugged time)
430 (goto-char (point-min))
431 (wl-plugged-redrawing-switch 0 (elmo-plugged-p))
433 (setq server (caaar alist)
435 plugged (nth 2 (car alist))
436 time (nth 3 (car alist)))
437 (unless (string= last server)
439 (wl-plugged-redrawing-switch
440 wl-plugged-server-indent
441 (elmo-plugged-p server nil plugged-alist))
444 (wl-plugged-redrawing-switch
445 wl-plugged-port-indent plugged time)
446 (setq alist (cdr alist))))
448 (set-buffer-modified-p nil))
450 (defun wl-plugged-change ()
452 (if (not elmo-plugged-alist)
453 (message "No plugged info")
454 (setq wl-plugged-winconf (current-window-configuration))
455 (let* ((cur-win (selected-window))
456 (max-lines (if (eq major-mode 'wl-summary-mode)
461 (set-buffer (get-buffer-create wl-plugged-buf-name))
463 (buffer-disable-undo (current-buffer))
464 (delete-windows-on (current-buffer))
465 (wl-plugged-set-variables)
466 (setq lines (wl-plugged-drawing wl-plugged-alist)))
467 (select-window cur-win)
468 (setq window-lines (min max-lines (max lines window-min-height)))
469 (when (> (- (window-height) window-lines) window-min-height)
470 (split-window cur-win (- (window-height) window-lines)))
471 (switch-to-buffer wl-plugged-buf-name)
474 (enlarge-window (- window-lines (window-height)))
475 (when (fboundp 'pos-visible-in-window-p)
476 (goto-char (point-min))
477 (while (and (< (window-height) max-lines)
478 (not (pos-visible-in-window-p (1- (point-max)))))
479 (enlarge-window 2))))
481 (goto-char (point-min))
483 (wl-plugged-move-to-next)))) ;; goto first entry
485 (defsubst wl-plugged-get-server ()
488 (wl-plugged-move-to-previous-server)
490 (when (looking-at (format "^%s\\[[^]]+\\]\\(.*\\)"
491 (wl-plugged-server-indent)))
492 (elmo-match-buffer 1))))
494 (defun wl-plugged-toggle ()
496 (let ((cur-point (point)))
502 (let (variable switch name)
503 (goto-char cur-point)
504 (when (and (not (bobp))
505 (not (eq (char-before) ? )))
506 (if (re-search-backward " [^ ]+" nil t)
508 (re-search-backward "^[^ ]+" nil t)))
509 (when (looking-at "\\([^ :[]+\\):?\\[\\([^]]+\\)\\]")
510 (setq name (elmo-match-buffer 1))
511 (setq switch (not (string= (elmo-match-buffer 2) wl-plugged-plug-on)))
512 (when (setq variable (cdr (assoc name wl-plugged-switch-variables)))
513 (set variable switch))
514 (goto-char (match-beginning 2))
515 (let ((buffer-read-only nil))
516 (delete-region (match-beginning 2) (match-end 2))
517 (insert (wl-plugged-string switch))
518 (set-buffer-modified-p nil)))))
520 ((looking-at "^\\( *\\)\\[\\([^]]+\\)\\]\\([^ \n]*\\)")
521 (let* ((indent (length (elmo-match-buffer 1)))
522 (switch (elmo-match-buffer 2))
523 (name (elmo-match-buffer 3))
524 (plugged (not (string= switch wl-plugged-plug-on)))
525 (alist wl-plugged-alist)
526 server port stream-type name-1)
528 ((eq indent wl-plugged-port-indent) ;; toggle port plug
530 ((string-match "\\([^([]*\\)(\\([^)[]+\\))" name)
531 (setq port (string-to-int (elmo-match-string 2 name)))
532 (if (string-match "!" (setq name-1 (elmo-match-string 1 name)))
534 (intern (substring name-1 (match-end 0))))))
537 (setq server (wl-plugged-get-server))
538 (elmo-set-plugged plugged server port stream-type nil alist))
539 ((eq indent wl-plugged-server-indent) ;; toggle server plug
540 (elmo-set-plugged plugged name nil nil nil alist))
541 ((eq indent 0) ;; toggle all plug
542 (elmo-set-plugged plugged nil nil nil nil alist)))
544 (wl-plugged-redrawing wl-plugged-alist)
545 ;; show plugged status in modeline
546 (let ((elmo-plugged wl-plugged-switch))
547 (setq wl-plugged-switch (elmo-plugged-p)
548 wl-modeline-plug-status wl-plugged-switch)
549 (force-mode-line-update t))))))
550 (setq wl-plugged-alist-modified t)
551 (goto-char cur-point)))
553 (defun wl-plugged-click (e)
558 (defun wl-plugged-toggle-all ()
560 (let ((cur-point (point)))
561 (setq wl-plugged-switch (not wl-plugged-switch))
562 (elmo-set-plugged wl-plugged-switch nil nil nil nil wl-plugged-alist)
563 (wl-plugged-redrawing wl-plugged-alist)
564 (goto-char cur-point)
565 (setq wl-plugged-alist-modified t)
566 ;; show plugged status in modeline
567 (setq wl-modeline-plug-status wl-plugged-switch)
568 (force-mode-line-update t)))
570 (defun wl-plugged-exit ()
572 (setq ;;elmo-plugged-alist wl-plugged-alist
573 wl-plugged wl-plugged-switch
575 wl-plugged-sending-queue-alist nil
576 wl-plugged-dop-queue-alist nil)
577 (run-hooks 'wl-plugged-exit-hook)
578 (when wl-plugged-alist-modified
579 (wl-toggle-plugged (if wl-plugged 'on 'off) t))
580 (kill-buffer (current-buffer))
581 (if wl-plugged-winconf
582 (set-window-configuration wl-plugged-winconf)))
584 (defun wl-plugged-flush-queue ()
586 (let ((cur-point (point))
587 (dop-status (elmo-dop-queue-flush))
588 (send-status (wl-draft-queue-flush)))
589 (unless (or dop-status send-status)
590 (message "No processing queue."))
591 (wl-plugged-set-variables)
592 (wl-plugged-drawing wl-plugged-alist)
593 (goto-char cur-point)))
595 (defun wl-plugged-move-to-next ()
597 (when (re-search-forward "\\[\\([^]]+\\)\\]" nil t)
598 (let ((pos (match-beginning 1)))
599 (if (invisible-p pos)
600 (goto-char (next-visible-point pos))
603 (defun wl-plugged-move-to-previous ()
605 (if (eq (char-before) ?\]) (forward-char -1))
606 (when (re-search-backward "\\[\\([^]]+\\)\\]" nil t)
607 (let ((pos (match-beginning 1)))
608 (if (invisible-p pos)
609 (goto-char (next-visible-point pos))
612 (defun wl-plugged-move-to-next-server ()
615 (format "^%s\\[\\([^]]+\\)\\]" (wl-plugged-server-indent)))
619 (if (re-search-forward regexp nil t)
620 (setq point (match-beginning 1))))
621 (if point (goto-char point))))
623 (defun wl-plugged-move-to-previous-server ()
626 (format "^%s\\[\\([^]]+\\)\\]" (wl-plugged-server-indent))))
627 (if (re-search-backward regexp nil t)
628 (goto-char (match-beginning 1)))))
630 ;;; end of wl-plugged-mode
633 "Save summary and folder status."
635 (wl-save-status 'keep-summary)
636 (run-hooks 'wl-save-hook))
638 (defun wl-execute-temp-marks ()
639 "Execute temporary marks in summary buffers."
641 (let ((summaries (wl-collect-summary)))
643 (with-current-buffer (car summaries)
644 (wl-summary-exec-with-confirmation)
645 (wl-summary-save-status))
646 (setq summaries (cdr summaries)))))
648 (defun wl-save-status (&optional keep-summary)
649 (message "Saving summary and folder status...")
651 (let ((summaries (wl-collect-summary)))
653 (with-current-buffer (car summaries)
655 (wl-summary-cleanup-temp-marks))
656 (wl-summary-save-view)
657 (elmo-folder-commit wl-summary-buffer-elmo-folder)
659 (kill-buffer (car summaries))))
660 (setq summaries (cdr summaries)))))
661 (wl-refile-alist-save)
662 (wl-folder-info-save)
663 (and (featurep 'wl-fldmgr) (wl-fldmgr-exit))
664 (and (featurep 'wl-spam) (wl-spam-save-status))
665 (elmo-crosspost-message-alist-save)
666 (message "Saving summary and folder status...done"))
670 (when (or (not wl-interactive-exit)
671 (y-or-n-p "Do you really want to quit Wanderlust? "))
673 (when wl-use-acap (funcall (symbol-function 'wl-acap-exit)))
675 (elmo-clear-signal-slots)
676 (elmo-passwd-alist-clear)
677 (run-hooks 'wl-exit-hook)
679 (wl-folder-cleanup-variables)
680 (wl-message-buffer-cache-clean-up)
684 (list wl-folder-buffer-name
687 (when wl-delete-startup-frame-function
688 (funcall wl-delete-startup-frame-function))
689 ;; (if (and wl-folder-use-frame
690 ;; (> (length (visible-frame-list)) 1))
693 (remove-hook 'kill-emacs-hook 'wl-save-status)
695 (message "") ; empty minibuffer.
700 (require 'mime-setup)
701 (setq elmo-plugged wl-plugged)
702 (add-hook 'kill-emacs-hook 'wl-save-status)
705 (wl-refile-alist-setup)
709 (fset 'wl-summary-from-func-internal
710 (symbol-value 'wl-summary-from-function))
711 (fset 'wl-summary-subject-func-internal
712 (symbol-value 'wl-summary-subject-function))
713 (fset 'wl-summary-subject-filter-func-internal
714 (symbol-value 'wl-summary-subject-filter-function))
715 (wl-summary-define-mark-action)
716 (dolist (spec wl-summary-flag-alist)
719 (format "wl-highlight-summary-%s-flag-face" (car spec))))
721 (setq elmo-get-folder-function #'wl-folder-make-elmo-folder)
722 (setq elmo-no-from wl-summary-no-from-message)
723 (setq elmo-no-subject wl-summary-no-subject-message)
724 (elmo-global-flags-initialize (mapcar 'car wl-summary-flag-alist))
727 'message-number-changed
729 (elmo-define-signal-handler (listener folder old-number new-number)
730 (dolist (buffer (wl-collect-draft))
731 (with-current-buffer buffer
732 (wl-draft-buffer-change-number old-number new-number)))
733 (wl-draft-rename-saved-config old-number new-number))
734 (elmo-define-signal-filter (listener folder old-number new-number)
736 (string= (elmo-folder-name-internal folder) wl-draft-folder))))
739 ;; This hook may contain the functions `wl-plugged-init-icons' and
740 ;; `wl-biff-init-icons' for reasons of system internal to accord
741 ;; facilities for the Emacs variants.
742 (run-hooks 'wl-init-hook)))
744 (defun wl-check-environment (no-check-folder)
745 (unless wl-from (error "Please set `wl-from' to your mail address"))
747 (when wl-insert-message-id
748 (let ((message-id (funcall wl-message-id-function))
750 (unless (string-match "^<\\([^@]*\\)@\\([^@]*\\)>$" message-id)
752 ((string-match "@" wl-message-id-domain)
753 (error "Please remove `@' from `wl-message-id-domain'"))
756 "Check around `wl-message-id-function' to get valid Message-ID string"))))
757 (setq domain (match-string 2 message-id))
758 (if (or (not (string-match "[^.]\\.[^.]" domain))
759 (string= domain "localhost.localdomain"))
761 "Please set `wl-message-id-domain' to get valid Message-ID string."))))
763 (when (not no-check-folder)
764 (let ((draft-folder (wl-folder-get-elmo-folder wl-draft-folder))
765 (queue-folder (wl-folder-get-elmo-folder wl-queue-folder))
766 (lost+found-folder (wl-folder-get-elmo-folder
767 elmo-lost+found-folder)))
768 (unless (elmo-folder-exists-p draft-folder)
770 (format "Draft Folder %s does not exist, create it? "
772 (elmo-folder-create draft-folder)
773 (error "Draft Folder is not created")))
774 (if (and wl-draft-enable-queuing
775 (not (elmo-folder-exists-p queue-folder)))
777 (format "Queue Folder %s does not exist, create it? "
779 (elmo-folder-create queue-folder)
780 (error "Queue Folder is not created")))
781 (when (not (eq no-check-folder 'wl-draft))
782 (unless (elmo-folder-exists-p lost+found-folder)
783 (elmo-folder-create lost+found-folder)))
785 (unless (file-exists-p wl-temporary-file-directory)
787 (format "Temp directory (to save multipart) %s does not exist, create it now? "
788 wl-temporary-file-directory))
789 (make-directory wl-temporary-file-directory)
790 (error "Temp directory is not created"))))))
792 (defconst wl-check-variables-alist
793 '((numberp . elmo-pop3-default-port)
794 (symbolp . elmo-pop3-default-authenticate-type)
795 (numberp . elmo-imap4-default-port)
796 (symbolp . elmo-imap4-default-authenticate-type)
797 (numberp . elmo-nntp-default-port)
798 (numberp . wl-pop-before-smtp-port)
799 (symbolp . wl-pop-before-smtp-authenticate-type)))
801 (defun wl-check-variables ()
802 (let ((type-variables wl-check-variables-alist)
804 (while (setq type (car type-variables))
805 (if (and (eval (cdr type))
806 (not (funcall (car type)
808 (error "%s must be %s: %S"
810 (substring (format "%s" (car type)) 0 -1)
812 (setq type-variables (cdr type-variables)))))
814 (defun wl-check-variables-2 ()
815 (if (< wl-message-buffer-cache-size 1)
816 (error "`wl-message-buffer-cache-size' must be larger than 0"))
817 (when wl-message-buffer-prefetch-depth
818 (if (not (< wl-message-buffer-prefetch-depth
819 wl-message-buffer-cache-size))
821 "`wl-message-buffer-prefetch-depth' must be smaller than "
822 "`wl-message-buffer-cache-size' - 1.")))))
825 (defun wl (&optional arg)
826 "Start Wanderlust -- Yet Another Message Interface On Emacsen.
827 If ARG (prefix argument) is specified, folder checkings are skipped."
832 (let (demo-buf check)
834 (if wl-demo (setq demo-buf (wl-demo)))
841 (message "Checking environment...")
842 (wl-check-environment arg)
843 (message "Checking environment...done")
844 (message "Checking type of variables...")
846 (wl-check-variables-2)
847 (message "Checking type of variables...done")))
848 (let ((inhibit-quit t))
849 (wl-plugged-init (wl-folder)))
851 (run-hooks 'wl-auto-check-folder-pre-hook)
852 (wl-folder-auto-check)
853 (run-hooks 'wl-auto-check-folder-hook)))
855 (if (buffer-live-p demo-buf)
856 (kill-buffer demo-buf))
857 (signal (car obj)(cdr obj)))
859 (when wl-biff-check-folder-list
860 (unless arg (wl-biff-check-folders))
862 (if (buffer-live-p demo-buf)
863 (kill-buffer demo-buf)))
864 (run-hooks 'wl-hook))
866 (defvar wl-delete-startup-frame-function nil)
869 (defun wl-other-frame (&optional arg)
870 "Pop up a frame to read messages via Wanderlust."
872 (if wl-folder-use-frame
874 (let ((focusing-functions (append '(raise-frame select-frame)
875 (if (fboundp 'x-focus-frame)
878 (folder (get-buffer wl-folder-buffer-name))
879 window frame wl-folder-use-frame)
881 (setq window (get-buffer-window folder t))
882 (window-live-p window)
883 (setq frame (window-frame window)))
885 (while focusing-functions
886 (funcall (car focusing-functions) frame)
887 (setq focusing-functions (cdr focusing-functions)))
889 (setq frame (make-frame))
890 (while focusing-functions
891 (funcall (car focusing-functions) frame)
892 (setq focusing-functions (cdr focusing-functions)))
893 (setq wl-delete-startup-frame-function
895 (setq wl-delete-startup-frame-function nil)
896 (let ((frame ,frame))
897 (if (eq (selected-frame) frame)
898 (delete-frame frame)))))
901 ;; Define some autoload functions WL might use.
903 ;; This little mapcar goes through the list below and marks the
904 ;; symbols in question as autoloaded functions.
908 (let ((interactive (nth 1 (memq ':interactive package))))
913 (when (consp function)
914 (setq keymap (car (memq 'keymap function)))
915 (setq function (car function)))
916 (autoload function (car package) nil interactive keymap))))
917 (if (eq (nth 1 package) ':interactive)
920 '(("wl-fldmgr" :interactive t
921 wl-fldmgr-access-display-all wl-fldmgr-access-display-normal
922 wl-fldmgr-add wl-fldmgr-clear-cut-entity-list wl-fldmgr-copy
923 wl-fldmgr-copy-region wl-fldmgr-cut wl-fldmgr-cut-region
924 wl-fldmgr-make-access-group wl-fldmgr-make-filter
925 wl-fldmgr-make-group wl-fldmgr-make-multi
926 wl-fldmgr-reconst-entity-hashtb wl-fldmgr-rename wl-fldmgr-delete
927 wl-fldmgr-save-folders wl-fldmgr-set-petname wl-fldmgr-sort
928 wl-fldmgr-subscribe wl-fldmgr-subscribe-region
929 wl-fldmgr-unsubscribe wl-fldmgr-unsubscribe-region wl-fldmgr-yank )
930 ("wl-acap" wl-acap-init)
931 ("wl-acap" :interactive t wl-acap-store)
933 (wl-fldmgr-mode-map keymap)
934 wl-fldmgr-add-entity-hashtb)
935 ("wl-expire" :interactive t
936 wl-folder-archive-current-entity
937 wl-folder-expire-current-entity wl-summary-archive
940 wl-score-save wl-summary-rescore-msgs wl-summary-score-headers
941 wl-summary-score-update-all-lines )
942 ("wl-score" :interactive t
943 wl-score-change-score-file wl-score-edit-current-scores
944 wl-score-edit-file wl-score-flush-cache wl-summary-rescore
945 wl-score-set-mark-below wl-score-set-expunge-below
946 wl-summary-increase-score wl-summary-lower-score )
947 ("wl-draft" wl-draft-rename-saved-config))))
949 ;; for backward compatibility
950 (defalias 'wl-summary-from-func-petname 'wl-summary-default-from)
953 (product-provide (provide 'wl) (require 'wl-version))