lisp/gnus.el (gnus-revision-number): Change to 01.
[elisp/gnus.git-] / lisp / gnus-ofsetup.el
1 ;;; gnus-ofsetup.el --- Setup advisor for Offline reading for Mail/News.
2 ;;;
3 ;;; $Id: gnus-ofsetup.el,v 1.1.2.12 1999-02-03 13:09:33 ichikawa Exp $
4 ;;;
5 ;;; Copyright (C) 1998 Tatsuya Ichikawa
6 ;;; Author: Tatsuya Ichikawa <t-ichi@po.shiojiri.ne.jp>
7 ;;;
8 ;;; This file is part of Semi-gnus.
9 ;;;
10 ;;; GNU Emacs 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)
13 ;;; any later version.
14
15 ;;; GNU Emacs 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.
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 ;;; How to use.
27 ;;;
28 ;;;      M-x load[RET]gnus-ofsetup
29 ;;;      M-x gnus-setup-for-offline
30 ;;;
31
32 ;;; Code:
33
34 (defvar gnus-offline-setting-file "~/.gnus-offline.el")
35 (defvar gnus-offline-use-miee nil)
36 (defvar gnus-offline-news-fetch-method nil)
37 (defvar gnus-offline-mail-fetch-method nil)
38 (defvar gnus-offline-hangup-program nil)
39 (defvar gnus-offline-dialup-program nil)
40 (defvar pop3-fma-spool-file-alist nil)
41 (defvar pop3-fma-movemail-type nil)
42 (defvar pop3-fma-movemail-arguments nil)
43 (defvar use-miee nil)
44 (defvar address nil)
45 (defvar mail-source nil)
46 (defvar options nil)
47
48 ;;; To silence byte compiler
49 (and
50  (fboundp 'eval-when-compile)
51  (eval-when-compile
52    (save-excursion
53      (beginning-of-defun)
54      (eval-region (point-min) (point)))
55    (let (case-fold-search)
56      (mapcar
57       (function
58        (lambda (symbol)
59          (unless (boundp symbol)
60            (make-local-variable symbol)
61            (eval (list 'setq symbol nil)))))
62       '(:group
63         :prefix :type
64         sendmail-to-spool-directory
65         news-spool-request-post-directory
66         nnspool-version
67         nnagent-version
68         msspool-news-server
69         msspool-news-service
70         gnspool-get-news
71         mail-spool-send
72         news-spool-post
73         gnus-agent-handle-level
74         ))
75      (make-local-variable 'byte-compile-warnings)
76      (setq byte-compile-warnings nil))))
77
78 (defun gnus-setup-for-offline ()
79   "*Set up Gnus for offline environment."
80   (interactive)
81   
82   (if (not (file-exists-p gnus-offline-setting-file))
83       (progn
84         (let ((news-method
85                (completing-read
86                 "Method for offline News reading (TAB to completion): "
87                 '(("gnus-agent" 1) ("nnspool" 2))
88                 nil t nil))
89               (mail-method 'nnmail)
90               (program
91                (read-file-name "Dialup/Hangup program(type nil you do not use): "))
92               (mta-type
93                (completing-read
94                 "Select MTA type for sending mail (TAB to completion): "
95                 '(("smtp" 1) ("sendmail" 2))
96                 nil t nil))
97               (num-of-address
98                (read-from-minibuffer "How many e-mail address do you have: "))
99               )
100           (if (string-equal news-method "nnspool")
101               (setq use-miee t)
102             (setq use-miee (y-or-n-p "Use MIEE post/send message ")))
103           ;;
104           ;; Set variables.
105           (if (string-equal news-method "gnus-agent")
106               (setq gnus-offline-news-fetch-method 'nnagent)
107             (setq gnus-offline-news-fetch-method 'nnspool))
108           ;;
109           (setq gnus-offline-mail-fetch-method mail-method)
110           (setq gnus-offline-use-miee use-miee)
111           
112           ;; Set programs.
113           (if (string-equal program "nil")
114               (progn
115                 (setq gnus-offline-hangup-program nil)
116                 (setq gnus-offline-dialup-program nil))
117             (let ((options
118                    (read-from-minibuffer "Dialup program options: ")))
119               (setq gnus-offline-dialup-program-arguments
120                     (split-string options "[\t ]+")))
121             (let ((options
122                    (read-from-minibuffer "Hangup program options: ")))
123               (setq gnus-offline-hangup-program-arguments
124                     (split-string options "[\t ]+")))
125             (setq gnus-offline-hangup-program program)
126             (setq gnus-offline-dialup-program program))
127             
128             ;; Set spool directory for outgoing messages.
129           (if use-miee
130               (progn
131                 ;; Setting for MIEE with nnspool.
132                 (let ((news-spool
133                        (read-from-minibuffer
134                         "News spool directory for sending: "
135                         "/usr/spool/news.out"))
136                       (mail-spool
137                        (read-from-minibuffer
138                         "Mail spool directory for sending: "
139                         "/usr/spool/mail.out")))
140                   (setq gnus-offline-mail-spool-directory mail-spool)
141                   (setq gnus-offline-news-spool-directory news-spool)
142                   (setq gnus-offline-drafts-queue-type 'miee)
143                   
144                   ;; Load MIEE.
145                   (load "miee")
146                   ;; Set news post function for MIEE.
147                   (setq message-send-news-function 'gnspool-request-post)
148                   ;; Spool directory setting - MIEE.
149                   (if (not (file-exists-p gnus-offline-mail-spool-directory))
150                       (make-directory gnus-offline-mail-spool-directory t))
151                   (setq sendmail-to-spool-directory
152                         gnus-offline-mail-spool-directory)
153                   (if (not (file-exists-p gnus-offline-news-spool-directory))
154                       (make-directory gnus-offline-news-spool-directory t))
155                   (setq news-spool-request-post-directory
156                         gnus-offline-news-spool-directory)))
157             
158             ;; Set drafts type gnus-agent.
159             (setq gnus-offline-drafts-queue-type 'agent))
160           
161           ;; Setting for gnus-agent.
162           (if (eq gnus-offline-news-fetch-method 'nnagent)
163               (let ((agent-directory
164                      (read-from-minibuffer "Agent directory: " "~/News/agent")))
165                 (setq gnus-agent-directory agent-directory)))
166             
167           ;; Determin MTA type.
168           (if (string-equal mta-type "smtp")
169               (setq gnus-offline-MTA-type 'smtp)
170             (setq gnus-offline-MTA-type 'sendmail)
171             )
172           ;;
173           ;; Set E-Mail Address and pop3 movemail type.
174           (setq i (string-to-int num-of-address))
175           (setq address nil)
176           (if (not (locate-library "mail-source"))
177               (progn
178                 (while (> i 0)
179                   (setq address
180                         (append address
181                                 (list
182                                  (list
183                                   (concat "po:"
184                                           (read-from-minibuffer
185                                            "Email address (user@mailhost): "))
186                                   (completing-read
187                                    "Authentification Method (TAB to completion): "
188                                    '(("pass" 1) ("apop" 2)) nil t nil)))))
189                   (setq i (- i 1)))
190                 ;; Replace "hoge" -> 'hoge
191                 (mapcar
192                  (lambda (x)
193                    (if (string-equal (nth 1 x) "pass")
194                        (setcar (cdr x) 'pass)
195                      (setcar (cdr x) 'apop)))
196                  address)
197                 (setq pop3-fma-spool-file-alist address)
198                 ;; Set movemail type.
199                 (let ((movemail-type
200                        (completing-read
201                         "Select movemail type for retreave mail (TAB to completion): "
202                         '(("exe" 1) ("lisp" 2))
203                         nil t nil))
204                       )
205                   (if (string-equal movemail-type "exe")
206                       (let ((options
207                              (read-from-minibuffer "movemail options: ")))
208                         (setq pop3-fma-movemail-arguments (split-string options "[\t ]+"))))
209                   (if (string-equal movemail-type "exe")
210                       (setq pop3-fma-movemail-type 'exe)
211                     (setq pop3-fma-movemail-type 'lisp))))
212             ;;
213             ;; Use mail-source.el
214             (setq mail-source nil)
215             (while (> i 0)
216               (let ((user (read-from-minibuffer "Mail Account name : "))
217                     (server (read-from-minibuffer "Mail server : "))
218                     (auth (completing-read
219                           "Authentification Method (TAB to completion): "
220                           '(("pop" 1) ("apop" 2)) nil t nil))
221                     (islisp (y-or-n-p "Do you use pop3.el to fetch mail? ")))
222                 (if (not islisp)
223                     (let ((prog (read-file-name "movemail program name: "
224                                                 exec-directory "movemail"))
225                           (args (read-from-minibuffer "movemail options: " "-pf")))
226                       (setq mail-source
227                             (append mail-source
228                                     (list
229                                      (list
230                                       auth
231                                       :user user
232                                       :server server
233                                       :program prog
234                                       :args (format "%s %s" args
235                                                     (concat "po:" user)))))))
236                   (setq mail-source
237                         (append mail-source
238                                 (list
239                                  (list
240                                   auth
241                                   :user user
242                                   :server server))))))
243               (setq i (- i 1)))
244             ;; Replace "hoge" -> 'hoge
245             (mapcar
246              (lambda (x)
247                (if (string-equal (nth 0 x) "pop")
248                    (setcar x 'pop)
249                  (setcar x 'apop)))
250              mail-source)
251             (setq gnus-offline-mail-source mail-source)))
252
253         (setq save-passwd
254               (y-or-n-p "Do you save password information to newsrc file? "))
255         
256         ;; Write to setting file.
257         (setq tmp-buffer (get-buffer-create "* Setting"))
258         (set-buffer "* Setting")
259         (erase-buffer)
260         (insert ";;\n");
261         (insert ";; This file is created by gnus-ofsetup.el\n")
262         (insert ";; Creation date : ")
263         (insert (current-time-string))
264         (insert "\n")
265         (insert ";;\n")
266
267         ;; write Basic setting
268         (insert "(setq gnus-offline-news-fetch-method '")
269         (insert (prin1-to-string gnus-offline-news-fetch-method))
270         (insert ")\n")
271         (insert "(setq gnus-offline-mail-fetch-method '")
272         (insert (prin1-to-string gnus-offline-mail-fetch-method))
273         (insert ")\n")
274         (insert "(setq gnus-offline-use-miee ")
275         (insert (prin1-to-string gnus-offline-use-miee))
276         (insert ")\n")
277         (insert "(setq gnus-offline-dialup-program ")
278         (insert (prin1-to-string gnus-offline-dialup-program))
279         (insert ")\n")
280
281         ;; write dialup/hangup program and options.
282         (if (stringp gnus-offline-dialup-program)
283             (progn
284               (insert "(setq gnus-offline-dialup-program-arguments '")
285               (insert (prin1-to-string gnus-offline-dialup-program-arguments))
286               (insert ")\n")))
287         (insert "(setq gnus-offline-hangup-program ")
288         (insert (prin1-to-string gnus-offline-hangup-program))
289         (insert ")\n")
290         (if (stringp gnus-offline-hangup-program)
291             (progn
292               (insert "(setq gnus-offline-hangup-program-arguments '")
293               (insert (prin1-to-string gnus-offline-hangup-program-arguments))
294               (insert ")\n")))
295
296         ;; write setting about MIEE.
297         (if gnus-offline-use-miee
298             (progn
299               (insert "(setq gnus-offline-mail-spool-directory ")
300               (insert (prin1-to-string gnus-offline-mail-spool-directory))
301               (insert ")\n")
302               (insert "(setq gnus-offline-news-spool-directory ")
303               (insert (prin1-to-string gnus-offline-news-spool-directory))
304               (insert ")\n")
305               (insert "(setq sendmail-to-spool-directory gnus-offline-mail-spool-directory)\n")
306               (insert "(setq news-spool-request-post-directory gnus-offline-news-spool-directory)\n")
307               (insert "(load \"miee\")\n")
308               (insert "(setq message-send-news-function '")
309               (insert (prin1-to-string message-send-news-function))
310               (insert ")\n")))
311
312         ;; write setting about nnspool and gnus-agent.
313         (if (equal gnus-offline-news-fetch-method 'nnspool)
314             (insert "(message-offline-state)\n")
315           (insert "(setq gnus-agent-directory ")
316           (insert (prin1-to-string gnus-agent-directory))
317           (insert ")\n"))
318
319         ;; write setting about queue type -- MIEE or nnagent.
320         (insert "(setq gnus-offline-drafts-queue-type '")
321         (insert (prin1-to-string gnus-offline-drafts-queue-type))
322         (insert ")\n")
323         (insert "(setq gnus-offline-MTA-type '")
324         (insert (prin1-to-string gnus-offline-MTA-type))
325         (insert ")\n")
326
327         ;; Offline setting for gnus-nntp-*
328         (insert "(setq gnus-nntp-service nil)\n")
329         (insert "(setq gnus-nntp-server nil)\n")
330
331         ;; Write setting about hooks.
332         (insert "(add-hook 'gnus-group-mode-hook 'gnus-offline-processed-by-timer t)\n")
333         (insert "(add-hook 'gnus-group-mode-hook 'gnus-offline-error-check t)\n")
334         (insert "(add-hook 'gnus-after-getting-new-news-hook 'gnus-offline-after-get-new-news)\n")
335         (insert "(add-hook 'gnus-after-getting-news-hook 'gnus-offline-after-get-new-news)\n")
336         (if (eq gnus-offline-news-fetch-method 'nnspool)
337             (insert "(add-hook 'after-getting-news-hook 'gnus-offline-nnspool-hangup-line)\n"))
338         (insert "(add-hook 'message-send-hook 'gnus-offline-message-add-header)\n")
339         (insert "(autoload 'gnus-offline-setup \"gnus-offline\")\n")
340         (insert "(add-hook 'gnus-load-hook 'gnus-offline-setup)\n")
341
342         (if (not (locate-library "mail-source"))
343             (progn
344               ;; Write setting about pop3-fma.
345               (insert "(setq nnmail-spool-file nil)\n")
346               (insert "(require 'pop3-fma)\n")
347               (insert "(add-hook 'message-send-hook 'pop3-fma-message-add-header)\n")
348               (insert "(setq pop3-fma-spool-file-alist '")
349               (insert (prin1-to-string pop3-fma-spool-file-alist))
350               (insert ")\n")
351               (insert "(setq pop3-fma-movemail-type '")
352               (insert (prin1-to-string pop3-fma-movemail-type))
353               (insert ")\n")
354               (if save-passwd
355                   (insert "(add-hook 'gnus-setup-news-hook \n    (lambda ()\n        (add-to-list 'gnus-variable-list 'pop3-fma-password)))\n"))
356               (if (eq pop3-fma-movemail-type 'exe)
357                   (progn
358                     (insert "(setq pop3-fma-movemail-arguments '")
359                     (insert (prin1-to-string pop3-fma-movemail-arguments))
360                     (insert ")\n"))))
361           ;; Write stting about mail-source.el
362           (insert "(setq gnus-offline-mail-source '")
363           (insert (prin1-to-string gnus-offline-mail-source))
364           (insert ")\n")
365           (insert "(setq nnmail-spool-file gnus-offline-mail-source)\n")
366           (insert "(require 'read-passwd)\n")
367           (insert "(setq mail-source-read-passwd 'read-pw-read-passwd)\n")
368           (insert "(add-hook 'gnus-setup-news-hook 'read-pw-set-mail-source-passwd-cache)\n")
369           (if save-passwd
370               (insert "(add-hook 'gnus-setup-news-hook \n    (lambda ()\n        (add-to-list 'gnus-variable-list 'mail-source-password-cache)))\n"))
371           )
372         (write-region (point-min) (point-max) gnus-offline-setting-file)
373         (kill-buffer "* Setting"))
374     )
375   (load gnus-offline-setting-file))
376 ;; gnus-ofsetup.el Ends here.