1 ;;; gnus-offline.el --- To process mail & news at offline environment.
2 ;;; $Id: gnus-offline.el,v 1.1.2.5.2.28 1999-01-31 23:06:20 yamaoka Exp $
4 ;;; Copyright (C) 1998 Tatsuya Ichikawa
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 ;;; Tsukamoto Tetsuo <czkmt@remus.dti.ne.jp>
12 ;;; Keywords: news , mail , offline , gnus
15 ;;; Keiichi Suzuki <kei-suzu@mail.wbs.or.jp>
16 ;;; KORIYAMA Naohiro <kory@ba2.so-net.or.jp>
17 ;;; Katsumi Yamaoka <yamaoka@jpl.org>
19 ;;; This file is part of Semi-gnus.
21 ;;; GNU Emacs is free software; you can redistribute it and/or modify
22 ;;; it under the terms of the GNU General Public License as published by
23 ;;; the Free Software Foundation; either version 2, or (at your option)
24 ;;; any later version.
26 ;;; GNU Emacs is distributed in the hope that it will be useful,
27 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
28 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 ;;; GNU General Public License for more details.
31 ;;; You should have received a copy of the GNU General Public License
32 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
33 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
34 ;;; Boston, MA 02111-1307, USA.
38 ;;; This file works only with after version of Emacs 19.30.
39 ;;; This file needs miee.el and SEMI.
40 ;;; If you set gnus-offline-drafts-queue-type to 'agent , you don't need
42 ;;; You must use Semi-gnus 6.X.X.
46 ;;; Add following code at the end in your .emacs
48 ;;; (load "gnus-ofsetup")
49 ;;; (gnus-setup-for-offline)
50 ;;; (load gnus-offline-setting-file)
52 ;;; If you use gnus-agent as souper , put gnus-agent setup code in you .gnus.el
54 ;;; If you use nnspool as souper , put following code in your .emacs before
55 ;;; gnus-offline setting.
57 ;;; Then , put hang.exe in exec-path directory.
59 ;;; In Gnus group buffer , type g to get all news and mail.
60 ;;; Then send mail and news in spool directory.
62 ;;; Security Notice. (This is available before version 2.02)
64 ;;; You can set the variable gnus-offline-pop-password-file to save your POP
65 ;;; passwords. But TAKE CARE. Use it at your own risk.
66 ;;; If you decide to use it, then write in .emacs or .gnus-offline.el
69 ;;; (setq gnus-offline-pop-password-file "~/.pop.passwd")
71 ;;; and write in this file something like:
73 ;;; (setq pop3-fma-password
74 ;;; '(("SERVER1" "ACCOUNT1" "PASSWORD1")
75 ;;; ("SERVER2" "ACCOUNT2" "PASSWORD2")
76 ;;; ............................
79 ;;; If you want to encode the file with base64, try:
81 ;;; M-: (base64-encode-region (point-min) (point-max))
84 ;;; gnus-offline-dialup-program-arguments
85 ;;; ... List of dialup program arguments.
86 ;;; gnus-offline-hangup-program-arguments
87 ;;; ... List of hangup program arguments.
88 ;;; gnus-offline-mail-treat-environ ... toggle sending mail online/offline.
89 ;;; gnus-offline-articles-to-fetch ... toggle fetch articles.
90 ;;; both->mail->news->both...
91 ;;; gnus-offline-load-hook ... hook before gnus-offline load.
92 ;;; gnus-offline-before-online-hook ... hook before all online jobs.
93 ;;; gnus-offline-after-online-hook ... hook after all online jobs.
94 ;;; gnus-offline-interval-time ... Interval time to do all online jobs.
96 ;;; gnus-offline-dialup-function ... Function to diualup.
97 ;;; gnus-offline-hangup-function ... Function to hangup.
98 ;;; gnus-offline-pop-password-file ... File to keep the POP password info.
99 ;;; gnus-offline-pop-password-decoding-function
100 ;;; ... Function to decode the password info.
104 (eval '(run-hooks 'gnus-offline-load-hook))
110 (unless (and (condition-case ()
114 (fboundp 'defcustom))
116 (defmacro defgroup (&rest args))
117 (defmacro defcustom (symbol value &optional doc &rest args)
118 (` (defvar (, symbol) (, value) (, doc))))
120 (defgroup gnus-offline nil
121 "Offline backend utility for Gnus."
122 :prefix "gnus-offline-"
126 (defconst gnus-offline-version-number "2.10b1")
127 (defconst gnus-offline-codename
129 ;; "This is the time" ; 2.00
130 ;; "A matter of trust"
132 "Ahhhhhhh!!" ; 2.10b1
136 (defconst gnus-offline-version (format "Gnus offline backend utiliy v%s"
137 gnus-offline-version-number))
139 (defcustom gnus-offline-dialup-program-arguments nil
140 "*Program arguments of gnus-offline-dialup-program."
142 :type '(repeat (string :tag "Argument")))
144 (defcustom gnus-offline-hangup-program-arguments nil
145 "*Program arguments of gnus-offline-hangup-program."
147 :type '(repeat (string :tag "Argument")))
149 (defcustom gnus-offline-auto-hangup t
150 "*Whether dialup-network automatically hang up when all online jobs has done."
154 (defcustom gnus-offline-load-hook nil
155 "*Hook to be run after the gnus-offline package has been loaded."
159 (defcustom gnus-offline-before-online-hook nil
160 "*Hook to be run before all online jobs."
164 (defcustom gnus-offline-after-online-hook nil
165 "*Hook to be run after all online jobs."
169 (defcustom gnus-offline-mail-treat-environ 'offline
170 "*If online , gnus-offline send all mail under online environ.
171 If offline , gnus-offline send all mail temporary to spool dir."
173 :type '(choice (const offline)
176 (defcustom gnus-offline-articles-to-fetch 'both
177 "*If both , gnus-offline fetch mail and news articles.
178 If mail , gnus-offline only fetch mail articles.
179 If news , gnus-offline only fetch news articles."
181 :type '(choice (const both)
185 (defcustom gnus-offline-interval-time 0
186 "*Interval time(minutes) to do online jobs.
187 If set to 0 , timer call is disabled."
191 (defcustom gnus-offline-mail-group-level 1
192 "*Group level for mail group."
196 (defcustom gnus-offline-after-empting-spool-hook nil
197 "*Hook to be run before empting spool."
201 (defcustom gnus-offline-before-empting-spool-hook nil
202 "*Hook to be run after empting spool."
206 (defcustom gnus-offline-dialup-function 'gnus-offline-connect-server
207 "*Function to dialup."
211 (defcustom gnus-offline-hangup-function 'gnus-offline-hangup-line
212 "*Function to hangup."
216 (defcustom gnus-offline-pop-password-file nil
217 "*File name for saving one's POP password information.
218 This variable should be nil if there's some possibility that
219 your passwords be stolen."
221 :type '(choice (file :tag "File")
224 (defcustom gnus-offline-pop-password-decoding-function
225 (function (lambda () (base64-decode-region (point-min) (point-max))))
226 "*Function for decoding one's password information.
227 The value has no effect when `gnus-offline-pop-password-file'
229 This variable might be nil if you don't need to encode your passwords."
233 ;;; Internal variables.
234 (defvar gnus-offline-connected nil
235 "*If value is t , dialup line is connected status.
236 If value is nil , dialup line is disconnected status.")
238 (defvar gnus-offline-news-fetch-method nil
239 "*Method to fetch news articles.")
241 (defvar gnus-offline-mail-fetch-method nil
242 "*Method to fetch mail articles.")
244 (defvar gnus-offline-header-string
245 (format "%s - \"%s\""
247 gnus-offline-codename)
248 "*Header string for gnus-offline.")
250 (defvar gnus-offline-stored-group-level nil
251 "*Mail Group level before changing.")
253 (defvar gnus-offline-movemail-arguments nil
254 "*All command line arguments of exec-directory/movemail.")
256 (defvar gnus-offline-mail-source nil
257 "*nnmail-spool-file save variable.")
259 ;;; Temporary variable:
266 (defvar gnus-offline-error-buffer " *Error*")
267 (defvar gnus-offline-map (make-sparse-keymap))
269 ;;; To silence byte compiler
271 (fboundp 'eval-when-compile)
275 (eval-region (point-min) (point)))
276 (let (case-fold-search)
280 (unless (boundp symbol)
281 (make-local-variable symbol)
282 (eval (list 'setq symbol nil)))))
285 sendmail-to-spool-directory
286 news-spool-request-post-directory
294 gnus-agent-handle-level
296 (make-local-variable 'byte-compile-warnings)
297 (setq byte-compile-warnings nil))))
299 (put 'gnus-offline-set-unplugged-state 'menu-enable 'gnus-offline-connected)
300 (if (eq system-type 'windows-nt)
301 (define-process-argument-editing "/hang\\.exe\\'"
302 (lambda (x) (general-process-argument-editing-function
303 x nil t t nil t t))))
308 (defun gnus-offline-setup ()
309 "*Initialize gnus-offline function"
311 ;; Load setting file - required.
312 (load gnus-offline-setting-file)
315 (gnus-offline-define-menu-and-key)
317 ;; To transfer Mail/News function.
318 (cond ((eq gnus-offline-mail-treat-environ 'offline)
319 ;; send mail under offline environ.
320 (gnus-offline-set-offline-sendmail-function))
321 ((eq gnus-offline-mail-treat-environ 'online)
322 ;; send mail under offline environ.
323 (gnus-offline-set-online-sendmail-function))))
324 ;; (add-hook 'gnus-group-mode-hook 'gnus-offline-setup))
327 ;; Setting Error check.
328 (defun gnus-offline-error-check ()
329 ;; Check gnus-agent and nnspool setting.
330 (cond ((eq gnus-offline-news-fetch-method 'nnagent)
331 ;; nnagent and gnus-agent loaded ??
332 (if (not (and (featurep 'gnus-agent)
333 (featurep 'nnagent)))
335 (get-buffer-create gnus-offline-error-buffer)
336 (set-buffer gnus-offline-error-buffer)
338 (insert "WARNING!!: gnus-agent.el or nnagent.el is not loaded.\n")
339 (insert "Please check your .emacs or .gnus.el to work gnus-agent fine.")
340 (pop-to-buffer gnus-offline-error-buffer))))
342 ((eq gnus-offline-news-fetch-method 'nnspool)
343 (if (not (featurep 'nnspool))
345 (get-buffer-create gnus-offline-error-buffer)
346 (set-buffer gnus-offline-error-buffer)
348 (insert "WARNING!!: nnspool.el is not loaded.\n")
349 (insert "Please check your .emacs or .gnus.el to work nnspool fine.")
350 (pop-to-buffer gnus-offline-error-buffer))))))
353 (defun gnus-offline-set-offline-sendmail-function ()
354 "*Initialize sendmail-function when unplugged status."
355 (if (eq gnus-offline-drafts-queue-type 'miee)
357 (if (eq gnus-offline-news-fetch-method 'nnagent)
358 (setq gnus-agent-send-mail-function 'sendmail-to-spool-in-gnspool-format))
359 (setq message-send-mail-function 'sendmail-to-spool-in-gnspool-format))
360 (setq gnus-agent-send-mail-function (gnus-offline-set-online-sendmail-function)
361 message-send-mail-function 'gnus-agent-send-mail)))
363 (defun gnus-offline-set-online-sendmail-function ()
364 "*Initialize sendmail-function when plugged status."
365 (if (eq gnus-offline-MTA-type 'smtp)
366 (setq message-send-mail-function 'message-send-mail-with-smtp)
367 (setq message-send-mail-function 'message-send-mail-with-sendmail)))
369 (defun gnus-offline-set-offline-post-news-function ()
370 "*Initialize sendnews-function when unplugged status."
371 (if (eq gnus-offline-drafts-queue-type 'miee)
372 (setq message-send-news-function 'gnspool-request-post)))
374 (defun gnus-offline-set-online-post-news-function ()
375 "*Initialize sendnews-function when plugged status."
376 (setq message-send-news-function 'message-send-news-with-gnus))
378 ;; Get new news jobs. (gnus-agent and nnspool)
380 (defun gnus-offline-gnus-get-new-news (&optional arg)
381 "*Override function \"gnus-group-get-new-news\"."
383 (run-hooks 'gnus-offline-before-online-hook)
384 (if (functionp gnus-offline-dialup-function)
385 (funcall gnus-offline-dialup-function))
386 (gnus-offline-get-new-news-function)
387 (if (not (locate-library "mail-source"))
393 (or pop3-fma-password
394 (when gnus-offline-pop-password-file
395 (setq pop3-fma-save-password-information t)
396 (setq buffer (get-buffer-create "*offline-temp*"))
399 (insert-file-contents-as-binary gnus-offline-pop-password-file)
400 (and gnus-offline-pop-password-decoding-function
401 (funcall gnus-offline-pop-password-decoding-function))
403 (gnus-group-get-new-news arg))
404 (when gnus-offline-pop-password-file
405 (setq pop3-fma-password nil)
406 (setq pop3-fma-save-password-information nil)
407 (kill-buffer buffer)))))
409 ;; Use mail-source.el
410 (gnus-group-get-new-news arg)))
415 (defun gnus-offline-connect-server ()
417 ;; Dialup if gnus-offline-dialup-program is specified
418 (if (stringp gnus-offline-dialup-program)
420 (message "Dialing ...")
421 (apply 'call-process gnus-offline-dialup-program nil nil nil
422 gnus-offline-dialup-program-arguments)
424 (message "Dialing ... done."))))
427 ;; Jobs before get new news , send mail and post news.
429 (defun gnus-offline-get-new-news-function ()
430 "*Prepare to get new news/mail."
431 ;; Set mail group level
432 (if (eq gnus-offline-articles-to-fetch 'mail)
433 (gnus-offline-set-mail-group-level gnus-offline-mail-group-level))
435 ;; Set to online environ.
436 (setq gnus-offline-connected t)
438 ;; Set send mail/news functions to online functions.
439 (gnus-offline-set-online-sendmail-function)
440 (gnus-offline-set-online-post-news-function)
441 (message "Set to online status.")
444 (if (eq gnus-offline-articles-to-fetch 'news)
445 (gnus-offline-disable-fetch-mail))
447 ;; fetch both mail and news. or Only mail.
448 (gnus-offline-enable-fetch-news)
449 (if (memq gnus-offline-articles-to-fetch '(both mail))
450 (gnus-offline-enable-fetch-mail))
452 ;; fetch only mail for gnus-agent
453 (if (and (eq gnus-offline-news-fetch-method 'nnagent)
454 (eq gnus-offline-articles-to-fetch 'mail))
455 (setq gnus-agent-handle-level gnus-offline-mail-group-level)))
458 ;; Change mail group level to handle only mail.
460 (defun gnus-offline-set-mail-group-level (level)
461 "*Set nnm* group level."
462 (switch-to-buffer gnus-group-buffer)
463 (goto-char (point-min))
465 ;; Save current level
466 (if (not gnus-offline-stored-group-level)
467 (while (re-search-forward " nnm" nil t)
468 (setq gnus-offline-stored-group-level
469 (append gnus-offline-stored-group-level
470 (list (gnus-group-group-level)))))
474 (goto-char (point-min))
475 (while (re-search-forward " nnm" nil t)
476 (gnus-group-set-current-level 1 level)
481 ;; Restore mail group level
483 (defun gnus-offline-restore-mail-group-level ()
484 "*Restore nnm* group level."
485 (switch-to-buffer gnus-group-buffer)
486 (goto-char (point-min))
488 (while (re-search-forward " nnm" nil t)
489 (gnus-group-set-current-level 1 (nth num gnus-offline-stored-group-level))
492 (beginning-of-line)))
494 ;; Jobs after getting new news.
496 (defun gnus-offline-after-get-new-news ()
497 "*After getting news and mail jobs."
498 (if (memq gnus-offline-articles-to-fetch '(both mail))
501 ;; send mail/news in spool
502 (gnus-offline-empting-spool)
503 (if (eq gnus-offline-articles-to-fetch 'mail)
505 ;; Send only mail and hang up...
506 (if (and gnus-offline-connected
507 gnus-offline-auto-hangup)
508 (gnus-offline-set-unplugged-state))
509 ;; Disable fetch mail.
510 (gnus-offline-disable-fetch-mail)
511 (gnus-offline-after-jobs-done)))))
514 (if (memq gnus-offline-articles-to-fetch '(both news))
516 (if gnus-offline-connected
517 (cond ((eq gnus-offline-news-fetch-method 'nnagent)
518 ;; Get New News (gnus-agent)
519 (gnus-agent-toggle-plugged t)
522 (gnus-agent-fetch-session)
524 ;; Hang Up line. then set to offline status.
525 (if (and gnus-offline-connected
526 gnus-offline-auto-hangup)
527 (gnus-offline-set-unplugged-state))
529 ;; All online jobs has done.
530 (gnus-offline-after-jobs-done))
532 (if (eq gnus-offline-news-fetch-method 'nnspool)
533 ;; Get New News (nnspool)
534 (gnspool-get-news))))))))
536 ;; Disable fetch mail
538 (defun gnus-offline-disable-fetch-mail ()
539 "*Set do not fetch mail."
540 (setq nnmail-spool-file nil))
544 (defun gnus-offline-enable-fetch-mail ()
545 "*Set to fetch mail."
546 (setq gnus-offline-mail-fetch-method 'nnmail)
547 (if (not (locate-library "mail-source"))
549 (setq nnmail-movemail-program 'pop3-fma-movemail)
550 (setq nnmail-spool-file (append
551 pop3-fma-local-spool-file-alist
555 pop3-fma-spool-file-alist))))
556 (setq nnmail-spool-file gnus-offline-mail-source)))
560 (defun gnus-offline-enable-fetch-news ()
561 "*Set to fetch news."
562 (if (eq gnus-offline-news-fetch-method 'nnagent)
564 (setq gnus-agent-handle-level gnus-level-subscribed)
565 (gnus-agent-toggle-plugged t))))
568 ;; Add your custom header.
570 (defun gnus-offline-add-custom-header (header string)
571 "*Add X-Gnus-Offline-Backend header to Mail/News message."
573 (progn (goto-char (point-min))
575 (concat "^" (regexp-quote mail-header-separator) "\n"))
577 (goto-char (point-min))
578 (or (re-search-forward (concat "^" header) delimline t)
580 (goto-char delimline)
583 (setq hdr (concat header " "))
584 (setq str (concat hdr string))
585 (setq hdr (concat str "\n"))
586 (insert-string hdr)))))
588 ;; Add X-Offline-Backend header.
590 (defun gnus-offline-message-add-header ()
591 "*Add X-Gnus-Offline-Backend header to Mail/News message."
592 (if (eq gnus-offline-mail-treat-environ 'offline)
594 (if (eq gnus-offline-news-fetch-method 'nnagent)
595 (setq ver nnagent-version)
596 (setq ver nnspool-version))
597 (setq str (format "\n with %s" ver)
598 string (concat gnus-offline-header-string str))
599 (gnus-offline-add-custom-header "X-Gnus-Offline-Backend:" string))))
603 ;; Toggle plugged/unplugged
605 (defun gnus-offline-toggle-plugged (plugged)
606 "*Override function \"Jj\" - gnus-agent-toggle-plugged."
607 (interactive (list (not gnus-offline-connected)))
610 (setq gnus-offline-connected plugged)
611 (gnus-agent-toggle-plugged plugged)
612 ;; Set send mail/news function to offline functions.
613 (gnus-offline-set-online-sendmail-function)
614 (gnus-offline-set-online-post-news-function))
615 ;; Set to offline status
616 (gnus-offline-set-unplugged-state)))
618 ;; Function of hang up line.
620 (defun gnus-offline-set-unplugged-state ()
621 "*Set to unplugged state."
624 (if (functionp gnus-offline-hangup-function)
625 (funcall gnus-offline-hangup-function))
626 (setq gnus-offline-connected nil)
627 (if (eq gnus-offline-news-fetch-method 'nnagent)
628 (gnus-agent-toggle-plugged nil))
630 ;; Set send mail/news function to offline functions.
631 (gnus-offline-set-offline-sendmail-function)
632 (gnus-offline-set-offline-post-news-function)
634 (setenv "MAILHOST" nil))
636 ;; Hangup line function
638 (defun gnus-offline-hangup-line ()
639 "*Hangup line function."
640 (message "Hang up line ... ")
641 (if (stringp gnus-offline-hangup-program)
642 (apply 'start-process "hup" nil gnus-offline-hangup-program
643 gnus-offline-hangup-program-arguments))
644 (message "Hang up line ... done."))
646 ;; Hang Up line routine whe using nnspool
648 (defun gnus-offline-nnspool-hangup-line ()
649 (if (and gnus-offline-connected
650 gnus-offline-auto-hangup)
651 (gnus-offline-set-unplugged-state))
652 (gnus-offline-after-jobs-done))
654 ;; Function of all jobs has done.
656 (defun gnus-offline-after-jobs-done ()
657 "*Jobs after all online jobs."
658 (run-hooks 'gnus-offline-after-online-hook)
659 (if (eq gnus-offline-articles-to-fetch 'mail)
660 (gnus-offline-restore-mail-group-level))
661 (if (eq gnus-offline-news-fetch-method 'nnagent)
662 (or gnus-agent-expire-all
663 (gnus-offline-agent-expire)))
664 (if (and (featurep 'xemacs)
665 (fboundp 'play-sound-file))
668 (gnus-group-save-newsrc)
669 (message "All online jobs has done."))
673 ;; Toggle auto hang up
675 (defun gnus-offline-toggle-auto-hangup ()
676 "*Toggle auto hangup flag."
678 (setq string "Auto hang up logic")
679 (if gnus-offline-auto-hangup
681 (setq gnus-offline-auto-hangup nil
683 (setq gnus-offline-auto-hangup t
685 (message (format "%s %s" string str)))
687 ;; Toggle offline/online to send mail.
689 (defun gnus-offline-toggle-on/off-send-mail ()
690 "*Toggel online/offline sendmail."
692 (if (eq gnus-offline-mail-treat-environ 'offline)
694 ;; Sending mail under online environ.
695 (gnus-offline-set-online-sendmail-function)
696 (setq gnus-offline-mail-treat-environ 'online)
697 (message "Sending mail immidiately."))
698 ;; Sending mail under offline environ.
699 (gnus-offline-set-offline-sendmail-function)
700 (setq gnus-offline-mail-treat-environ 'offline)
701 (message "Sending mail temporary to spool directory.")))
703 ;; Toggle articles to fetch ... both -> mail -> news -> both
705 (defun gnus-offline-toggle-articles-to-fetch ()
706 "*Set articles to fetch... both(Mail/News) -> mail only -> News only -> both"
708 (setq string "Articles fetch from server.")
709 (cond ((eq gnus-offline-articles-to-fetch 'both)
710 (setq gnus-offline-articles-to-fetch 'mail
712 ((eq gnus-offline-articles-to-fetch 'mail)
713 (setq gnus-offline-articles-to-fetch 'news
716 (setq gnus-offline-articles-to-fetch 'both
717 str "Mail/News both")))
718 (message (format "%s %s" string str)))
720 ;; Toggle movemail program pop3.el -> movemail -> pop3.el
722 (defun gnus-offline-toggle-movemail-program ()
723 "*Toggle movemail program movemail -> pop3.el -> movemail ->..."
725 (setq string "Set nnmail-movemail-program")
726 (cond ((eq pop3-fma-movemail-type 'lisp)
727 (setq pop3-fma-movemail-type 'exe
730 (setq pop3-fma-movemail-type 'lisp
732 (message (format "%s %s" string str)))
734 ;; Send mail and Post news using Miee or gnus-agent.
736 (defun gnus-offline-empting-spool ()
737 "*Send all drafts on queue."
738 (run-hooks 'gnus-offline-before-empting-spool-hook)
739 (if (eq gnus-offline-drafts-queue-type 'miee)
740 ;; Send queued message by miee.el.
742 (if (eq gnus-offline-mail-treat-environ 'offline)
744 (message "Sending mails in spool ...")
745 ;; Using miee to send mail.
747 (message "Sending mails in spool ... done.")))
748 (message "Posting news in spool ...")
749 ;; Using miee to post news.
750 (if (and (not (stringp msspool-news-server))
751 (not msspool-news-service))
753 (setq msspool-news-server (nth 1 gnus-select-method))
754 (setq msspool-news-service 119)))
756 (message "Posting news in spool ... done."))
757 ;; Send queued message by gnus-agent
758 (message "Sending messages in spool ...")
759 (gnus-group-send-drafts)
760 (message "Sending messages in spool ... done."))
762 (run-hooks 'gnus-offline-after-empting-spool-hook))
766 (defun gnus-offline-set-interval-time ()
767 "*Set interval time for gnus-daemon."
769 (setq gnus-offline-interval-time
770 (string-to-int (read-from-minibuffer
771 (format "Interval time (now %s minutes) : "
772 gnus-offline-interval-time)
774 (if (< gnus-offline-interval-time 2)
776 (message "Retrieving message logic by timer is disabled.")
777 (setq gnus-offline-interval-time 0))
778 (message (format "Interval time set to %d minutes" gnus-offline-interval-time)))
779 (gnus-offline-processed-by-timer))
781 ;; Expire articles using gnus-agent.
783 (defun gnus-offline-agent-expire ()
784 "*Expire expirable article on News group."
790 (defun gnus-offline-define-menu-and-key ()
792 (if (eq gnus-offline-drafts-queue-type 'miee)
793 (if (featurep 'xemacs)
794 (add-hook 'gnus-group-mode-hook 'gnus-offline-define-menu-on-miee)
795 (gnus-offline-define-menu-on-miee))
796 (add-hook 'gnus-group-mode-hook 'gnus-offline-define-menu-on-agent))
797 (add-hook 'gnus-group-mode-hook
799 (local-set-key "\C-coh" 'gnus-offline-set-unplugged-state)
800 (if (not (locate-library "mail-source"))
801 (local-set-key "\C-com" 'gnus-offline-toggle-movemail-program))
802 (local-set-key "\C-cof" 'gnus-offline-toggle-articles-to-fetch)
803 (local-set-key "\C-coo" 'gnus-offline-toggle-on/off-send-mail)
804 (local-set-key "\C-cox" 'gnus-offline-toggle-auto-hangup)
805 (local-set-key "\C-cos" 'gnus-offline-set-interval-time)
806 (substitute-key-definition
807 'gnus-group-get-new-news 'gnus-offline-gnus-get-new-news
809 (if (eq gnus-offline-news-fetch-method 'nnagent)
811 (substitute-key-definition
812 'gnus-agent-toggle-plugged 'gnus-offline-toggle-plugged
813 gnus-agent-group-mode-map)
814 (local-set-key "\C-coe" 'gnus-offline-agent-expire)))
815 (or (featurep 'xemacs)
816 (define-key gnus-group-mode-map
817 (if (eq system-type 'windows-nt) [S-mouse-2] [mouse-3])
818 'gnus-offline-popup-menu))))
819 (if (eq gnus-offline-news-fetch-method 'nnagent)
820 (add-hook 'gnus-summary-mode-hook
822 (substitute-key-definition
823 'gnus-agent-toggle-plugged 'gnus-offline-toggle-plugged
824 gnus-agent-summary-mode-map))))
825 (if (featurep 'xemacs)
826 ;; Overwrite the toolbar spec for gnus-group-mode.
827 (add-hook 'gnus-startup-hook
829 (let ((i 0) (stat t) but)
830 (while (and stat (setq but (nth i gnus-group-toolbar)))
831 (and (equal 'gnus-group-get-new-news (aref but 1))
832 (aset but 1 'gnus-offline-gnus-get-new-news)
834 (setq i (1+ i))))))))
837 (defun gnus-offline-define-menu-on-miee ()
838 "*Set and change menu bar on MIEE menu."
840 (if (featurep 'meadow)
845 ["Spool
\e$B$K$"$k5-;v$NAw?.
\e(B" news-spool-post t]
846 ["Spool
\e$B$K$"$k
\e(B Mail
\e$B$NAw?.
\e(B" mail-spool-send t]
848 ["Offline
\e$B>uBV$X
\e(B" message-offline-state (not message-offline-state)]
849 ["Online
\e$B>uBV$X
\e(B" message-online-state message-offline-state]
852 ["movemail
\e$B$N@ZBX$(
\e(B" gnus-offline-toggle-movemail-program
853 (not (locate-library "mail-source"))]
854 ["
\e$B<hF@5-;v<oN`$NJQ99
\e(B" gnus-offline-toggle-articles-to-fetch t]
855 ["Mail
\e$BAw?.J}K!
\e(B(On/Off)
\e$B$N@ZBX$(
\e(B" gnus-offline-toggle-on/off-send-mail t]
856 ["
\e$B<+F0@ZCG$N@ZBX$(
\e(B" gnus-offline-toggle-auto-hangup t]
858 ["
\e$B<hF@:Q5-;v$r>C$9
\e(B" gnus-offline-agent-expire (eq gnus-offline-news-fetch-method 'nnagent)]
859 ["
\e$B5-;v<hF@4V3V;~4V$N@_Dj
\e(B" gnus-offline-set-interval-time t]
861 ["
\e$B2s@~$N@ZCG
\e(B" gnus-offline-set-unplugged-state gnus-offline-connected])
867 ["Post news in spool" news-spool-post t]
868 ["Send mails in spool" mail-spool-send t]
870 ["Message Offline" message-offline-state (not message-offline-state)]
871 ["Message Online" message-online-state message-offline-state]
874 ["Toggle movemail program" gnus-offline-toggle-movemail-program
875 (not (locate-library "mail-source"))]
876 ["Toggle articles to fetch" gnus-offline-toggle-articles-to-fetch t]
877 ["Toggle online/offline send mail" gnus-offline-toggle-on/off-send-mail t]
878 ["Toggle auto hangup" gnus-offline-toggle-auto-hangup t]
880 ["Expire articles" gnus-offline-agent-expire (eq gnus-offline-news-fetch-method 'nnagent)]
881 ["Set interval time" gnus-offline-set-interval-time t]
883 ["Hang up Line." gnus-offline-set-unplugged-state gnus-offline-connected]
885 (and (featurep 'xemacs)
886 (easy-menu-add menu))))
888 ;; define menu without miee.
890 (defun gnus-offline-define-menu-on-agent ()
891 "*Set menu bar on OFFLINE menu."
893 gnus-offline-menu-on-agent
896 (if (featurep 'meadow)
898 ["movemail
\e$B$N@ZBX$(
\e(B" gnus-offline-toggle-movemail-program
899 (not (locate-library "mail-source"))]
900 ["
\e$B<hF@5-;v<oN`$NJQ99
\e(B" gnus-offline-toggle-articles-to-fetch t]
901 ["Mail
\e$BAw?.J}K!
\e(B(On/Off)
\e$B$N@ZBX$(
\e(B" gnus-offline-toggle-on/off-send-mail t]
902 ["
\e$B<+F0@ZCG$N@ZBX$(
\e(B" gnus-offline-toggle-auto-hangup t]
904 ["
\e$B<hF@:Q5-;v$r>C$9
\e(B" gnus-offline-agent-expire (eq gnus-offline-news-fetch-method 'nnagent)]
905 ["
\e$B5-;v<hF@4V3V;~4V$N@_Dj
\e(B" gnus-offline-set-interval-time t]
907 ["
\e$B2s@~$N@ZCG
\e(B" gnus-offline-set-unplugged-state gnus-offline-connected])
909 ["Toggle movemail program" gnus-offline-toggle-movemail-program
910 (not (locate-library "mail-source"))]
911 ["Toggle articles to fetch" gnus-offline-toggle-articles-to-fetch t]
912 ["Toggle online/offline send mail" gnus-offline-toggle-on/off-send-mail t]
913 ["Toggle auto hangup" gnus-offline-toggle-auto-hangup t]
915 ["Expire articles" gnus-offline-agent-expire (eq gnus-offline-news-fetch-method 'nnagent)]
916 ["Set interval time" gnus-offline-set-interval-time t]
918 ["Hang up Line." gnus-offline-set-unplugged-state gnus-offline-connected])))
919 (and (featurep 'xemacs)
920 (easy-menu-add gnus-offline-menu-on-agent)))
922 ;; Popup menu within the group buffer (under Emacs).
924 (defun gnus-offline-popup-menu (event)
925 "Popup menu for Gnus offline."
927 (let* ((menu (if (boundp 'miee-popup-menu)
929 (assoc 'Miee (assoc 'menu-bar global-map)))
931 gnus-offline-menu-on-agent))
932 (pop (x-popup-menu t menu))
933 (func (and pop (lookup-key menu (apply 'vector pop)))))
934 (and pop func (funcall func))))
938 (defun gnus-offline-processed-by-timer ()
939 "*Set timer interval."
940 (if (and (> gnus-offline-interval-time 0)
941 (not gnus-offline-connected))
943 (gnus-demon-add-handler 'gnus-offline-gnus-get-new-news
944 gnus-offline-interval-time
945 gnus-offline-interval-time))
946 (if (= gnus-offline-interval-time 0)
947 (gnus-demon-remove-handler 'gnus-offline-gnus-get-new-news t)))
950 (provide 'gnus-offline)
951 ;;; gnus-offline.el ends here