lisp/gnus-offline.el: Bug fix.
[elisp/gnus.git-] / lisp / gnus-offline.el
1 ;;; gnus-offline.el --- To process mail & news at offline environment.
2 ;;; $Id: gnus-offline.el,v 1.1.2.5.2.15 1998-12-10 09:58:13 ichikawa Exp $
3
4 ;;; Copyright (C) 1998 Tatsuya Ichikawa
5 ;;;                    Yukihiro Ito
6 ;;; Author: Tatsuya Ichikawa <t-ichi@po.shiojiri.ne.jp>
7 ;;;         Yukihiro Ito <ito@rs.civil.tohoku.ac.jp>
8 ;;;         Hidekazu Nakamura <u90121@uis-inf.co.jp>
9
10 ;;; Version: 2.00
11 ;;; Keywords: news , mail , offline , gnus
12 ;;;
13 ;;; SPECIAL THANKS
14 ;;;    Keiichi Suzuki <kei-suzu@mail.wbs.or.jp>
15 ;;;    KORIYAMA Naohiro <kory@ba2.so-net.or.jp>
16 ;;;    Katsumi Yamaoka <yamaoka@jpl.org>
17
18 ;;; This file is part of Semi-gnus.
19 ;;;
20 ;;; GNU Emacs is free software; you can redistribute it and/or modify
21 ;;; it under the terms of the GNU General Public License as published by
22 ;;; the Free Software Foundation; either version 2, or (at your option)
23 ;;; any later version.
24
25 ;;; GNU Emacs is distributed in the hope that it will be useful,
26 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
27 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 ;;; GNU General Public License for more details.
29
30 ;;; You should have received a copy of the GNU General Public License
31 ;;; along with GNU Emacs; see the file COPYING.  If not, write to the
32 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
33 ;;; Boston, MA 02111-1307, USA.
34 ;;;
35 ;;;; Commentary:
36 ;;; Note.
37 ;;;   This file works only with after version of Emacs 19.30.
38 ;;;   This file needs miee.el and SEMI.
39 ;;;   If you set gnus-offline-drafts-queue-type to 'agent , you don't need 
40 ;;;   miee.el
41 ;;;   You must use Semi-gnus 6.X.X.
42 ;;;
43 ;;; How to use.
44 ;;;
45 ;;; Add following code at the end in your .emacs
46 ;;;
47 ;;;    (load "gnus-ofsetup")
48 ;;;    (gnus-setup-for-offline)
49 ;;;    (load gnus-offline-setting-file)
50 ;;;
51 ;;; If you use gnus-agent as souper , put gnus-agent setup code in you .gnus.el
52 ;;;
53 ;;; If you use nnspool as souper , put following code in your .emacs before
54 ;;; gnus-offline setting.
55 ;;;
56 ;;; Then , put hang.exe in exec-path directory.
57 ;;;
58 ;;; In Gnus group buffer , type g to get all news and mail.
59 ;;; Then send mail and news in spool directory.
60 ;;;
61 ;;; Variables.
62 ;;;  gnus-offline-dialup-program-arguments
63 ;;;                                   ... List of dialup program arguments.
64 ;;;  gnus-offline-hangup-program-arguments
65 ;;;                                   ... List of hangup program arguments.
66 ;;;  gnus-offline-mail-treat-environ  ... toggle sending mail online/offline.
67 ;;;  gnus-offline-articles-to-fetch   ... toggle fetch articles.
68 ;;;                                        both->mail->news->both...
69 ;;;  gnus-offline-load-hook           ... hook before gnus-offline load.
70 ;;;  gnus-offline-before-online-hook  ... hook before all online jobs.
71 ;;;  gnus-offline-after-online-hook   ... hook after all online jobs.
72 ;;;  gnus-offline-interval-time       ... Interval time to do all online jobs.
73 ;;;                                        (minutes)
74 ;;;  gnus-offline-dialup-function     ... Function to diualup.
75 ;;;  gnus-offline-hangup-function     ... Function to hangup.
76
77 ;;; Code:
78
79 (eval '(run-hooks 'gnus-offline-load-hook))
80
81 (require 'cl)
82 (require 'custom)
83 (require 'pop3-fma)
84 (require 'easymenu)
85
86 (unless (and (condition-case ()
87                  (require 'custom)
88                (file-error nil))
89              (fboundp 'defgroup)
90              (fboundp 'defcustom))
91   (require 'backquote)
92   (defmacro defgroup (&rest args))
93   (defmacro defcustom (symbol value &optional doc &rest args)
94     (` (defvar (, symbol) (, value) (, doc))))
95   )
96 (defgroup gnus-offline nil
97   "Offline backend utility for Gnus."
98   :prefix "gnus-offline-"
99   :group 'mail
100   :group 'news)
101
102 (defconst gnus-offline-version-number "2.00")
103 (defconst gnus-offline-codename
104 ;;  "Beta5"                     ; Beta
105   "This is the time"            ; 2.00
106 ;;  "A matter of trust"
107 ;;  "Modern Woman"
108 ;;  "Code of silence"
109   )
110
111 (defconst gnus-offline-version (format "Gnus offline backend utiliy v%s"
112                                        gnus-offline-version-number))
113
114 (defcustom gnus-offline-dialup-program-arguments nil
115   "*Program arguments of gnus-offline-dialup-program."
116   :group 'gnus-offline
117   :type '(repeat (string :tag "Argument")))
118
119 (defcustom gnus-offline-hangup-program-arguments nil
120   "*Program arguments of gnus-offline-hangup-program."
121   :group 'gnus-offline
122   :type '(repeat (string :tag "Argument")))
123
124 (defcustom gnus-offline-auto-hangup t
125   "*Whether dialup-network automatically hang up when all online jobs has done."
126   :group 'gnus-offline
127   :type 'boolean)
128
129 (defcustom gnus-offline-load-hook nil
130   "*Hook to be run after the gnus-offline package has been loaded."
131   :group 'gnus-offline
132   :type 'hook)
133
134 (defcustom gnus-offline-before-online-hook nil
135   "*Hook to be run before all online jobs."
136   :group 'gnus-offline
137   :type 'hook)
138
139 (defcustom gnus-offline-after-online-hook nil
140   "*Hook to be run after all online jobs."
141   :group 'gnus-offline
142   :type 'hook)
143
144 (defcustom gnus-offline-mail-treat-environ 'offline
145   "*If online , gnus-offline send all mail under online environ.
146 If offline , gnus-offline send all mail temporary to spool dir."
147   :group 'gnus-offline
148   :type '(choice (const offline)
149                  (const online)))
150
151 (defcustom gnus-offline-articles-to-fetch 'both
152   "*If both , gnus-offline fetch mail and news articles.
153 If mail , gnus-offline only fetch mail articles.
154  If news , gnus-offline only fetch news articles."
155   :group 'gnus-offline
156   :type '(choice (const both)
157                  (const mail)
158                  (const news)))
159
160 (defcustom gnus-offline-interval-time 0
161   "*Interval time(minutes) to do online jobs.
162 If set to 0 , timer call is disabled."
163   :group 'gnus-offline
164   :type 'integer)
165
166 (defcustom gnus-offline-mail-group-level 1
167   "*Group level for mail group."
168   :group 'gnus-offline
169   :type 'integer)
170
171 (defcustom gnus-offline-after-empting-spool-hook nil
172   "*Hook to be run before empting spool."
173   :group 'gnus-offline
174   :type 'hook)
175
176 (defcustom gnus-offline-before-empting-spool-hook nil
177   "*Hook to be run after empting spool."
178   :group 'gnus-offline
179   :type 'hook)
180
181 (defcustom gnus-offline-dialup-function 'gnus-offline-connect-server
182   "*Function to dialup."
183   :group 'gnus-offline
184   :type 'function)
185
186 (defcustom gnus-offline-hangup-function 'gnus-offline-hangup-line
187   "*Function to hangup."
188   :group 'gnus-offline
189   :type 'function)
190
191 ;;; Internal variables.
192 (defvar gnus-offline-connected nil
193   "*If value is t , dialup line is connected status.
194 If value is nil , dialup line is disconnected status.")
195
196 (defvar gnus-offline-news-fetch-method nil
197   "*Method to fetch news articles.")
198
199 (defvar gnus-offline-mail-fetch-method nil
200   "*Method to fetch mail articles.")
201
202 (defvar gnus-offline-header-string
203   (format "%s - \"%s\""
204           gnus-offline-version
205           gnus-offline-codename)
206   "*Header string for gnus-offline.")
207
208 (defvar gnus-offline-stored-group-level nil
209   "*Mail Group level before changing.")
210
211 (defvar gnus-offline-movemail-arguments nil
212   "*All command line arguments of exec-directory/movemail.")
213
214 ;;; Temporary variable:
215 (defvar string)
216 (defvar hdr)
217 (defvar str)
218 (defvar ver)
219 (defvar passwd)
220 (defvar num)
221 (defvar gnus-offline-error-buffer " *Error*")
222 (defvar gnus-offline-map (make-sparse-keymap))
223
224 ;;; To silence byte compiler
225 (and
226  (fboundp 'eval-when-compile)
227  (eval-when-compile
228    (save-excursion
229      (beginning-of-defun)
230      (eval-region (point-min) (point)))
231    (let (case-fold-search)
232      (mapcar
233       (function
234        (lambda (symbol)
235          (unless (boundp symbol)
236            (make-local-variable symbol)
237            (eval (list 'setq symbol nil)))))
238       '(:group
239         :prefix :type
240         sendmail-to-spool-directory
241         news-spool-request-post-directory
242         nnspool-version
243         nnagent-version
244         msspool-news-server
245         msspool-news-service
246         gnspool-get-news
247         mail-spool-send
248         news-spool-post
249         gnus-agent-handle-level
250         ))
251      (make-local-variable 'byte-compile-warnings)
252      (setq byte-compile-warnings nil))))
253        
254 (put 'gnus-offline-set-unplugged-state 'menu-enable 'gnus-offline-connected)
255 (if (eq system-type 'windows-nt)
256     (define-process-argument-editing "/hang\\.exe\\'"
257       (lambda (x) (general-process-argument-editing-function
258                    x nil t t nil t t))))
259 ;;; Functions
260 ;;
261 ;; Setting up...
262 ;;
263 (defun gnus-offline-setup ()
264   "*Initialize gnus-offline function"
265
266   ;; Load setting file - required.
267   (load gnus-offline-setting-file)
268
269   ;; Menu and keymap
270   (gnus-offline-define-menu-and-key)
271   
272   ;; To transfer Mail/News function.
273   (cond ((eq gnus-offline-mail-treat-environ 'offline)
274          ;; send mail under offline environ.
275          (gnus-offline-set-offline-sendmail-function))
276         ((eq gnus-offline-mail-treat-environ 'online)
277          ;; send mail under offline environ.
278          (gnus-offline-set-online-sendmail-function))))
279 ;;  (add-hook 'gnus-group-mode-hook 'gnus-offline-setup))
280
281 ;;
282 ;; Setting Error check.
283 (defun gnus-offline-error-check ()
284   ;; Check gnus-agent and nnspool setting.
285   (cond ((eq gnus-offline-news-fetch-method 'nnagent)
286          ;; nnagent and gnus-agent loaded ??
287          (if (not (and (featurep 'gnus-agent)
288                        (featurep 'nnagent)))
289              (progn
290                (get-buffer-create gnus-offline-error-buffer)
291                (set-buffer gnus-offline-error-buffer)
292                (erase-buffer)
293                (insert "WARNING!!: gnus-agent.el or nnagent.el is not loaded.\n")
294                (insert "Please check your .emacs or .gnus.el to work gnus-agent fine.")
295                (pop-to-buffer gnus-offline-error-buffer))))
296         
297         ((eq gnus-offline-news-fetch-method 'nnspool)
298          (if (not (featurep 'nnspool))
299              (progn
300                (get-buffer-create gnus-offline-error-buffer)
301                (set-buffer gnus-offline-error-buffer)
302                (erase-buffer)
303                (insert "WARNING!!: nnspool.el is not loaded.\n")
304                (insert "Please check your .emacs or .gnus.el to work nnspool fine.")
305                (pop-to-buffer gnus-offline-error-buffer))))))
306 ;;
307 ;;
308 (defun gnus-offline-set-offline-sendmail-function ()
309   "*Initialize sendmail-function when unplugged status."
310   (if (eq gnus-offline-drafts-queue-type 'miee)
311       (if (eq gnus-offline-news-fetch-method 'nnagent)
312           (setq gnus-agent-send-mail-function 'sendmail-to-spool-in-gnspool-format))
313     (setq message-send-mail-function 'sendmail-to-spool-in-gnspool-format)
314     (setq gnus-agent-send-mail-function message-send-mail-function
315           message-send-mail-function 'gnus-agent-send-mail)))
316 ;;
317 (defun gnus-offline-set-online-sendmail-function ()
318   "*Initialize sendmail-function when plugged status."
319   (if (eq gnus-offline-MTA-type 'smtp)
320       (setq message-send-mail-function 'message-send-mail-with-smtp)
321     (setq message-send-mail-function 'message-send-mail-with-sendmail)))
322 ;;
323 (defun gnus-offline-set-offline-post-news-function ()
324   "*Initialize sendnews-function when unplugged status."
325   (if (eq gnus-offline-drafts-queue-type 'miee)
326       (setq message-send-news-function 'gnspool-request-post)))
327 ;;
328 (defun gnus-offline-set-online-post-news-function ()
329   "*Initialize sendnews-function when plugged status."
330   (setq message-send-news-function 'message-send-news-with-gnus))
331 ;;
332 ;; Get new news jobs. (gnus-agent and nnspool)
333 ;;
334 (defun gnus-offline-gnus-get-new-news (&optional arg)
335   "*Override function \"gnus-group-get-new-news\"."
336   (interactive "P")
337   (run-hooks 'gnus-offline-before-online-hook)
338   (if (functionp gnus-offline-dialup-function)
339       (funcall gnus-offline-dialup-function))
340   (gnus-offline-get-new-news-function)
341   (gnus-group-get-new-news arg))
342
343 ;;
344 ;; dialup...
345 ;;
346 (defun gnus-offline-connect-server ()
347   "*Dialup function."
348   ;; Dialup if gnus-offline-dialup-program is specified
349   (if (stringp gnus-offline-dialup-program)
350       (progn
351         (message "Dialing ...")
352         (apply 'call-process gnus-offline-dialup-program nil nil nil
353                gnus-offline-dialup-program-arguments)
354         (sleep-for 1)
355         (message "Dialing ... done."))))
356
357 ;;
358 ;; Jobs before get new news , send mail and post news.
359 ;;
360 (defun gnus-offline-get-new-news-function ()
361   "*Prepare to get new news/mail."
362   ;; Set mail group level
363   (if (eq gnus-offline-articles-to-fetch 'mail)
364       (gnus-offline-set-mail-group-level gnus-offline-mail-group-level))
365
366   ;; Set to online environ.
367   (setq gnus-offline-connected t)
368
369   ;; Set send mail/news functions to online functions.
370   (gnus-offline-set-online-sendmail-function)
371   (gnus-offline-set-online-post-news-function)
372   (message "Set to online status.")
373
374   ;; fetch only news
375   (if (eq gnus-offline-articles-to-fetch 'news)
376       (gnus-offline-disable-fetch-mail))
377
378   ;; fetch both mail and news. or Only mail.
379   (gnus-offline-enable-fetch-news)
380   (if (memq gnus-offline-articles-to-fetch '(both mail))
381       (gnus-offline-enable-fetch-mail))
382
383   ;; fetch only mail for gnus-agent
384   (if (and (eq gnus-offline-news-fetch-method 'nnagent)
385            (eq gnus-offline-articles-to-fetch 'mail))
386           (setq gnus-agent-handle-level gnus-offline-mail-group-level)))
387
388 ;;
389 ;; Change mail group level to handle only mail.
390 ;;
391 (defun gnus-offline-set-mail-group-level (level)
392   "*Set nnm* group level."
393   (switch-to-buffer gnus-group-buffer)
394   (goto-char (point-min))
395   
396   ;; Save current level
397   (if (not gnus-offline-stored-group-level)
398       (while (re-search-forward " nnm" nil t)
399         (setq gnus-offline-stored-group-level
400               (append gnus-offline-stored-group-level
401                       (list (gnus-group-group-level)))))
402     (forward-line 1)
403     (beginning-of-line))
404   ;;
405   (goto-char (point-min))
406   (while (re-search-forward " nnm" nil t)
407     (gnus-group-set-current-level 1 level)
408     (forward-line 1)
409     (beginning-of-line))
410   t)
411 ;;
412 ;; Restore mail group level
413 ;;
414 (defun gnus-offline-restore-mail-group-level ()
415   "*Restore nnm* group level."
416   (switch-to-buffer gnus-group-buffer)
417   (goto-char (point-min))
418   (setq num 0)
419   (while (re-search-forward " nnm" nil t)
420     (gnus-group-set-current-level 1 (nth num gnus-offline-stored-group-level))
421     (forward-line 1)
422     (setq num (+ num 1))
423     (beginning-of-line)))
424 ;;
425 ;; Jobs after getting new news.
426 ;;
427 (defun gnus-offline-after-get-new-news ()
428   "*After getting news and mail jobs."
429   (if (memq gnus-offline-articles-to-fetch '(both mail))
430       (progn
431         ;; Mail/both
432         ;; send mail/news in spool
433         (gnus-offline-empting-spool)
434         (if (eq gnus-offline-articles-to-fetch 'mail)
435             (progn
436               ;; Send only mail and hang up...
437               (if (and gnus-offline-connected
438                        gnus-offline-auto-hangup)
439                   (gnus-offline-set-unplugged-state))
440               ;; Disable fetch mail.
441               (gnus-offline-disable-fetch-mail)
442               (gnus-offline-after-jobs-done)))))
443   
444   ;; News/Both
445   (if (memq gnus-offline-articles-to-fetch '(both news))
446       (progn
447         (if gnus-offline-connected
448             (cond ((eq gnus-offline-news-fetch-method 'nnagent)
449                    ;; Get New News (gnus-agent)
450                    (gnus-agent-toggle-plugged t)
451                   
452                    ;; fetch articles
453                    (gnus-agent-fetch-session)
454                   
455                    ;; Hang Up line. then set to offline status.
456                    (if (and gnus-offline-connected
457                             gnus-offline-auto-hangup)
458                        (gnus-offline-set-unplugged-state))
459                    
460                    ;; All online jobs has done.
461                    (gnus-offline-after-jobs-done))
462                   (t
463                    (if (eq gnus-offline-news-fetch-method 'nnspool)
464                        ;; Get New News (nnspool)
465                        (gnspool-get-news))))))))
466 ;;
467 ;; Disable fetch mail
468 ;;
469 (defun gnus-offline-disable-fetch-mail ()
470   "*Set do not fetch mail."
471   (setq nnmail-spool-file nil))
472 ;;
473 ;; Enable fetch mail
474 ;;
475 (defun gnus-offline-enable-fetch-mail ()
476   "*Set to fetch mail."
477   (setq gnus-offline-mail-fetch-method 'nnmail)
478   (setq nnmail-movemail-program 'pop3-fma-movemail)
479   (setq nnmail-spool-file (append
480                            pop3-fma-local-spool-file-alist
481                            (mapcar
482                             (lambda (spool)
483                               (car spool))
484                             pop3-fma-spool-file-alist))))
485 ;;
486 ;; Enable fetch news
487 ;;
488 (defun gnus-offline-enable-fetch-news ()
489   "*Set to fetch news."
490   (if (eq gnus-offline-news-fetch-method 'nnagent)
491       (progn
492         (setq gnus-agent-handle-level gnus-level-subscribed)
493         (gnus-agent-toggle-plugged t))))
494 \f
495 ;;
496 ;; Add your custom header.
497 ;;
498 (defun gnus-offline-add-custom-header (header string)
499   "*Add X-Gnus-Offline-Backend header to Mail/News message."
500   (let ((delimline
501          (progn (goto-char (point-min))
502                 (re-search-forward
503                  (concat "^" (regexp-quote mail-header-separator) "\n"))
504                 (point-marker))))
505     (goto-char (point-min))
506     (or (re-search-forward (concat "^" header) delimline t)
507         (progn
508           (goto-char delimline)
509           (forward-line -1)
510           (beginning-of-line)
511           (setq hdr (concat header " "))
512           (setq str (concat hdr string))
513           (setq hdr (concat str "\n"))
514           (insert-string hdr)))))
515 ;;
516 ;; Add X-Offline-Backend header.
517 ;;
518 (defun gnus-offline-message-add-header ()
519   "*Add X-Gnus-Offline-Backend header to Mail/News message."
520   (if (eq gnus-offline-mail-treat-environ 'offline)
521       (progn
522         (if (eq gnus-offline-news-fetch-method 'nnagent)
523             (setq ver nnagent-version)
524           (setq ver nnspool-version))
525         (setq str (format "\n                        with %s" ver)
526               string (concat gnus-offline-header-string str))
527         (gnus-offline-add-custom-header "X-Gnus-Offline-Backend:" string))))
528   
529 \f
530 ;;
531 ;; Toggle plugged/unplugged
532 ;;
533 (defun gnus-offline-toggle-plugged (plugged)
534   "*Override function \"Jj\" - gnus-agent-toggle-plugged."
535   (interactive (list (not gnus-offline-connected)))
536   (if plugged
537       (progn
538         (setq gnus-offline-connected plugged)
539         (gnus-agent-toggle-plugged plugged)
540         ;; Set send mail/news function to offline functions.
541         (gnus-offline-set-online-sendmail-function)
542         (gnus-offline-set-online-post-news-function))
543     ;; Set to offline status
544     (gnus-offline-set-unplugged-state)))
545 ;;
546 ;; Function of hang up line.
547 ;;
548 (defun gnus-offline-set-unplugged-state ()
549   "*Set to unplugged state."
550   (interactive)
551   ;; Hang Up Line.
552   (if (functionp gnus-offline-hangup-function)
553       (funcall gnus-offline-hangup-function))
554   (setq gnus-offline-connected nil)
555   (if (eq gnus-offline-news-fetch-method 'nnagent)
556       (gnus-agent-toggle-plugged nil))
557
558   ;; Set send mail/news function to offline functions.
559   (gnus-offline-set-offline-sendmail-function)
560   (gnus-offline-set-offline-post-news-function)
561   ;;
562   (setenv "MAILHOST" nil))
563 ;;
564 ;; Hangup line function 
565 ;;
566 (defun gnus-offline-hangup-line ()
567   "*Hangup line function."
568   (message "Hang up line ... ")
569   (if (stringp gnus-offline-hangup-program)
570       (apply 'start-process "hup" nil gnus-offline-hangup-program
571              gnus-offline-hangup-program-arguments))
572   (message "Hang up line ... done."))
573 ;;
574 ;; Hang Up line routine whe using nnspool
575 ;;
576 (defun gnus-offline-nnspool-hangup-line ()
577   (if (and gnus-offline-connected
578            gnus-offline-auto-hangup)
579       (gnus-offline-set-unplugged-state))
580   (gnus-offline-after-jobs-done))
581 ;;
582 ;; Function of all jobs has done.
583 ;;
584 (defun gnus-offline-after-jobs-done ()
585   "*Jobs after all online jobs."
586   (run-hooks 'gnus-offline-after-online-hook)
587   (if (eq gnus-offline-articles-to-fetch 'mail)
588       (gnus-offline-restore-mail-group-level))
589   (if (eq gnus-offline-news-fetch-method 'nnagent)
590       (or (featurep 'xemacs)
591           (gnus-offline-agent-expire)))
592   (if (and (featurep 'xemacs)
593            (fboundp 'play-sound-file))
594       (ding nil 'drum)
595     (ding))
596   (gnus-group-save-newsrc)
597   (message "All online jobs has done."))
598
599 \f
600 ;;
601 ;; Toggle auto hang up
602 ;;
603 (defun gnus-offline-toggle-auto-hangup ()
604   "*Toggle auto hangup flag."
605   (interactive)
606   (setq string "Auto hang up logic")
607   (if gnus-offline-auto-hangup
608       (progn
609         (setq gnus-offline-auto-hangup nil
610               str "disabled."))
611     (setq gnus-offline-auto-hangup t
612           str "enabled."))
613   (message (format "%s %s" string str)))
614 ;;
615 ;; Toggle offline/online to send mail.
616 ;;
617 (defun gnus-offline-toggle-on/off-send-mail ()
618   "*Toggel online/offline sendmail."
619   (interactive)
620   (if (eq gnus-offline-mail-treat-environ 'offline)
621       (progn
622         ;; Sending mail under online environ.
623         (gnus-offline-set-online-sendmail-function)
624         (setq gnus-offline-mail-treat-environ 'online)
625         (message "Sending mail immidiately."))
626     ;; Sending mail under offline environ.
627     (gnus-offline-set-offline-sendmail-function)
628     (setq gnus-offline-mail-treat-environ 'offline)
629     (message "Sending mail temporary to spool directory.")))
630 ;;
631 ;; Toggle articles to fetch ... both -> mail -> news -> both
632 ;;
633 (defun gnus-offline-toggle-articles-to-fetch ()
634   "*Set articles to fetch... both(Mail/News) -> mail only -> News only -> both"
635   (interactive)
636   (setq string "Articles fetch from server.")
637   (cond ((eq gnus-offline-articles-to-fetch 'both)
638          (setq gnus-offline-articles-to-fetch 'mail
639                str "Only Mail"))
640         ((eq gnus-offline-articles-to-fetch 'mail)
641            (setq gnus-offline-articles-to-fetch 'news
642                  str "Only News"))
643         (t
644          (setq gnus-offline-articles-to-fetch 'both
645                str "Mail/News both")))
646   (message (format "%s %s" string str)))
647 ;;
648 ;; Toggle movemail program pop3.el -> movemail -> pop3.el
649 ;;
650 (defun gnus-offline-toggle-movemail-program ()
651   "*Toggle movemail program movemail -> pop3.el -> movemail ->..."
652   (interactive)
653   (setq string "Set nnmail-movemail-program")
654   (cond ((eq pop3-fma-movemail-type 'lisp)
655          (setq pop3-fma-movemail-type 'exe
656                str "to movemail"))
657         (t
658          (setq pop3-fma-movemail-type 'lisp
659                str "to pop3.el")))
660   (message (format "%s %s" string str)))
661 ;;
662 ;; Send mail and Post news using Miee or gnus-agent.
663 ;;
664 (defun gnus-offline-empting-spool ()
665   "*Send all drafts on queue."
666   (run-hooks 'gnus-offline-before-empting-spool-hook)
667   (if (eq gnus-offline-drafts-queue-type 'miee)
668       ;; Send queued message by miee.el.
669       (progn
670         (if (eq gnus-offline-mail-treat-environ 'offline)
671             (progn
672               (message "Sending mails in spool ...")
673               ;; Using miee to send mail.
674               (mail-spool-send)
675               (message "Sending mails in spool ... done.")))
676         (message "Posting news in spool ...")
677         ;; Using miee to post news.
678         (if (and (not (stringp msspool-news-server))
679                  (not msspool-news-service))
680             (progn
681               (setq msspool-news-server (nth 1 gnus-select-method))
682               (setq msspool-news-service 119)))
683         (news-spool-post)
684         (message "Posting news in spool ... done."))
685     ;; Send queued message by gnus-agent
686     (message "Sending messages in spool ...")
687     (gnus-group-send-drafts)
688     (message "Sending messages in spool ... done."))
689   ;;
690   (run-hooks 'gnus-offline-after-empting-spool-hook))
691 ;;
692 ;; Set interval time
693 ;;
694 (defun gnus-offline-set-interval-time ()
695   "*Set interval time for gnus-daemon."
696   (interactive)
697   (setq gnus-offline-interval-time
698         (string-to-int (read-from-minibuffer
699                         (format "Interval time (now %s minutes) : "
700                                 gnus-offline-interval-time)
701                         nil)))
702   (if (< gnus-offline-interval-time 2)
703       (progn
704         (message "Retrieving message logic by timer is disabled.")
705         (setq gnus-offline-interval-time 0))
706     (message (format "Interval time set to %d minutes" gnus-offline-interval-time)))
707   (gnus-offline-processed-by-timer))
708 ;;
709 ;; Expire articles using gnus-agent.
710 ;;
711 (defun gnus-offline-agent-expire ()
712   "*Expire expirable article on News group."
713   (interactive)
714   (gnus-agent-expire))
715 ;;
716 ;; Menu.
717 ;;
718 (defun gnus-offline-define-menu-and-key ()
719   "*Set key and menu."
720   (if (eq gnus-offline-drafts-queue-type 'miee)
721       (add-hook 'gnus-group-mode-hook 'gnus-offline-define-menu-on-miee)
722     (add-hook 'gnus-group-mode-hook 'gnus-offline-define-menu-on-agent))
723   (add-hook 'gnus-group-mode-hook
724             '(lambda ()
725                (local-set-key "\C-coh" 'gnus-offline-set-unplugged-state)
726                (local-set-key "\C-com" 'gnus-offline-toggle-movemail-program)
727                (local-set-key "\C-cof" 'gnus-offline-toggle-articles-to-fetch)
728                (local-set-key "\C-coo" 'gnus-offline-toggle-on/off-send-mail)
729                (local-set-key "\C-cox" 'gnus-offline-toggle-auto-hangup)
730                (local-set-key "\C-cos" 'gnus-offline-set-interval-time)
731                (substitute-key-definition
732                 'gnus-group-get-new-news 'gnus-offline-gnus-get-new-news
733                 gnus-group-mode-map)
734                (if (eq gnus-offline-news-fetch-method 'nnagent)
735                    (progn
736                      (substitute-key-definition
737                       'gnus-agent-toggle-plugged 'gnus-offline-toggle-plugged
738                       gnus-agent-group-mode-map)
739                      (local-set-key "\C-coe" 'gnus-offline-agent-expire)))))
740   (if (eq gnus-offline-news-fetch-method 'nnagent)
741       (add-hook 'gnus-summary-mode-hook
742                 '(lambda ()
743                    (substitute-key-definition
744                     'gnus-agent-toggle-plugged 'gnus-offline-toggle-plugged
745                     gnus-agent-summary-mode-map)))))
746 ;;
747 ;;
748 (defun gnus-offline-define-menu-on-miee ()
749   "*Set menu bar on MIEE menu."
750   (easy-menu-define
751    gnus-offline-menu-on-miee gnus-group-mode-map "Gnus offline menu on Miee"
752    '("Miee"
753      ["Post news in spool" news-spool-post t]
754      ["Send mails in spool" mail-spool-send t]
755      "----"
756      ["Message Offline" message-offline-state (not message-offline-state)]
757      ["Message Online" message-online-state message-online-state]
758      "----"
759      ("Gnus Offline"
760        ["Toggle movemail program" gnus-offline-toggle-movemail-program t]
761        ["Toggle articles to fetch" gnus-offline-toggle-articles-to-fetch t]
762        ["Toggle online/offline send mail" gnus-offline-toggle-on/off-send-mail t]
763        ["Toggle auto hangup" gnus-offline-toggle-auto-hangup t]
764        "----"
765        ["Expire articles" gnus-offline-agent-expire (eq gnus-offline-news-fetch-method 'nnagent)]
766        ["Set interval time" gnus-offline-set-interval-time t]
767        "----"
768        ["Hang up Line." gnus-offline-set-unplugged-state (gnus-offline-connected)]
769        ))))
770 ;;
771 ;; define menu without miee.
772 ;;
773 (defun gnus-offline-define-menu-on-agent ()
774   "*Set menu bar on OFFLINE menu."
775   (easy-menu-define 
776    gnus-offline-menu-on-agent gnus-group-mode-map "Gnus offline Menu"
777    '("Offline"
778      ["Toggle movemail program" gnus-offline-toggle-movemail-program t]
779      ["Toggle articles to fetch" gnus-offline-toggle-articles-to-fetch t]
780      ["Toggle online/offline send mail" gnus-offline-toggle-on/off-send-mail t]
781      ["Toggle auto hangup" gnus-offline-toggle-auto-hangup t]
782      "----"
783      ["Expire articles" gnus-offline-agent-expire (eq gnus-offline-news-fetch-method 'nnagent)]
784      ["Set interval time" gnus-offline-set-interval-time t]
785      "----"
786      ["Hang up Line." gnus-offline-set-unplugged-state (gnus-offline-connected)]))
787   (and (featurep 'xemacs)
788        (easy-menu-add gnus-offline-menu-on-agent)))
789 \f
790 ;;
791 ;; Timer Function
792 (defun gnus-offline-processed-by-timer ()
793   "*Set timer interval."
794   (if (and (> gnus-offline-interval-time 0)
795            (not gnus-offline-connected))
796       ;; Timer call
797       (gnus-demon-add-handler 'gnus-offline-gnus-get-new-news
798                               gnus-offline-interval-time
799                               gnus-offline-interval-time))
800   (if (= gnus-offline-interval-time 0)
801       (gnus-demon-remove-handler 'gnus-offline-gnus-get-new-news t)))
802 ;;
803 ;;
804 (provide 'gnus-offline)
805 ;;; gnus-offline.el ends here