1 ;;; gnus-offline.el --- To process mail & news at offline environment.
2 ;;; $Id: gnus-offline.el,v 1.1.2.5.2.27 1999-01-26 02:35:37 ichikawa 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.
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))
111 (unless (and (condition-case ()
115 (fboundp 'defcustom))
117 (defmacro defgroup (&rest args))
118 (defmacro defcustom (symbol value &optional doc &rest args)
119 (` (defvar (, symbol) (, value) (, doc))))
121 (defgroup gnus-offline nil
122 "Offline backend utility for Gnus."
123 :prefix "gnus-offline-"
127 (defconst gnus-offline-version-number "2.02")
128 (defconst gnus-offline-codename
130 ;; "This is the time" ; 2.00
131 ;; "A matter of trust"
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 ;;; Temporary variable:
263 (defvar gnus-offline-error-buffer " *Error*")
264 (defvar gnus-offline-map (make-sparse-keymap))
266 ;;; To silence byte compiler
268 (fboundp 'eval-when-compile)
272 (eval-region (point-min) (point)))
273 (let (case-fold-search)
277 (unless (boundp symbol)
278 (make-local-variable symbol)
279 (eval (list 'setq symbol nil)))))
282 sendmail-to-spool-directory
283 news-spool-request-post-directory
291 gnus-agent-handle-level
293 (make-local-variable 'byte-compile-warnings)
294 (setq byte-compile-warnings nil))))
296 (put 'gnus-offline-set-unplugged-state 'menu-enable 'gnus-offline-connected)
297 (if (eq system-type 'windows-nt)
298 (define-process-argument-editing "/hang\\.exe\\'"
299 (lambda (x) (general-process-argument-editing-function
300 x nil t t nil t t))))
305 (defun gnus-offline-setup ()
306 "*Initialize gnus-offline function"
308 ;; Load setting file - required.
309 (load gnus-offline-setting-file)
312 (gnus-offline-define-menu-and-key)
314 ;; To transfer Mail/News function.
315 (cond ((eq gnus-offline-mail-treat-environ 'offline)
316 ;; send mail under offline environ.
317 (gnus-offline-set-offline-sendmail-function))
318 ((eq gnus-offline-mail-treat-environ 'online)
319 ;; send mail under offline environ.
320 (gnus-offline-set-online-sendmail-function))))
321 ;; (add-hook 'gnus-group-mode-hook 'gnus-offline-setup))
324 ;; Setting Error check.
325 (defun gnus-offline-error-check ()
326 ;; Check gnus-agent and nnspool setting.
327 (cond ((eq gnus-offline-news-fetch-method 'nnagent)
328 ;; nnagent and gnus-agent loaded ??
329 (if (not (and (featurep 'gnus-agent)
330 (featurep 'nnagent)))
332 (get-buffer-create gnus-offline-error-buffer)
333 (set-buffer gnus-offline-error-buffer)
335 (insert "WARNING!!: gnus-agent.el or nnagent.el is not loaded.\n")
336 (insert "Please check your .emacs or .gnus.el to work gnus-agent fine.")
337 (pop-to-buffer gnus-offline-error-buffer))))
339 ((eq gnus-offline-news-fetch-method 'nnspool)
340 (if (not (featurep 'nnspool))
342 (get-buffer-create gnus-offline-error-buffer)
343 (set-buffer gnus-offline-error-buffer)
345 (insert "WARNING!!: nnspool.el is not loaded.\n")
346 (insert "Please check your .emacs or .gnus.el to work nnspool fine.")
347 (pop-to-buffer gnus-offline-error-buffer))))))
350 (defun gnus-offline-set-offline-sendmail-function ()
351 "*Initialize sendmail-function when unplugged status."
352 (if (eq gnus-offline-drafts-queue-type 'miee)
354 (if (eq gnus-offline-news-fetch-method 'nnagent)
355 (setq gnus-agent-send-mail-function 'sendmail-to-spool-in-gnspool-format))
356 (setq message-send-mail-function 'sendmail-to-spool-in-gnspool-format))
357 (setq gnus-agent-send-mail-function (gnus-offline-set-online-sendmail-function)
358 message-send-mail-function 'gnus-agent-send-mail)))
360 (defun gnus-offline-set-online-sendmail-function ()
361 "*Initialize sendmail-function when plugged status."
362 (if (eq gnus-offline-MTA-type 'smtp)
363 (setq message-send-mail-function 'message-send-mail-with-smtp)
364 (setq message-send-mail-function 'message-send-mail-with-sendmail)))
366 (defun gnus-offline-set-offline-post-news-function ()
367 "*Initialize sendnews-function when unplugged status."
368 (if (eq gnus-offline-drafts-queue-type 'miee)
369 (setq message-send-news-function 'gnspool-request-post)))
371 (defun gnus-offline-set-online-post-news-function ()
372 "*Initialize sendnews-function when plugged status."
373 (setq message-send-news-function 'message-send-news-with-gnus))
375 ;; Get new news jobs. (gnus-agent and nnspool)
377 (defun gnus-offline-gnus-get-new-news (&optional arg)
378 "*Override function \"gnus-group-get-new-news\"."
380 (run-hooks 'gnus-offline-before-online-hook)
381 (if (functionp gnus-offline-dialup-function)
382 (funcall gnus-offline-dialup-function))
383 (gnus-offline-get-new-news-function)
388 (or pop3-fma-password
389 (when gnus-offline-pop-password-file
390 (setq pop3-fma-save-password-information t)
391 (setq buffer (get-buffer-create "*offline-temp*"))
394 (insert-file-contents-as-binary gnus-offline-pop-password-file)
395 (and gnus-offline-pop-password-decoding-function
396 (funcall gnus-offline-pop-password-decoding-function))
398 (gnus-group-get-new-news arg))
399 (when gnus-offline-pop-password-file
400 (setq pop3-fma-password nil)
401 (setq pop3-fma-save-password-information nil)
402 (kill-buffer buffer)))))
407 (defun gnus-offline-connect-server ()
409 ;; Dialup if gnus-offline-dialup-program is specified
410 (if (stringp gnus-offline-dialup-program)
412 (message "Dialing ...")
413 (apply 'call-process gnus-offline-dialup-program nil nil nil
414 gnus-offline-dialup-program-arguments)
416 (message "Dialing ... done."))))
419 ;; Jobs before get new news , send mail and post news.
421 (defun gnus-offline-get-new-news-function ()
422 "*Prepare to get new news/mail."
423 ;; Set mail group level
424 (if (eq gnus-offline-articles-to-fetch 'mail)
425 (gnus-offline-set-mail-group-level gnus-offline-mail-group-level))
427 ;; Set to online environ.
428 (setq gnus-offline-connected t)
430 ;; Set send mail/news functions to online functions.
431 (gnus-offline-set-online-sendmail-function)
432 (gnus-offline-set-online-post-news-function)
433 (message "Set to online status.")
436 (if (eq gnus-offline-articles-to-fetch 'news)
437 (gnus-offline-disable-fetch-mail))
439 ;; fetch both mail and news. or Only mail.
440 (gnus-offline-enable-fetch-news)
441 (if (memq gnus-offline-articles-to-fetch '(both mail))
442 (gnus-offline-enable-fetch-mail))
444 ;; fetch only mail for gnus-agent
445 (if (and (eq gnus-offline-news-fetch-method 'nnagent)
446 (eq gnus-offline-articles-to-fetch 'mail))
447 (setq gnus-agent-handle-level gnus-offline-mail-group-level)))
450 ;; Change mail group level to handle only mail.
452 (defun gnus-offline-set-mail-group-level (level)
453 "*Set nnm* group level."
454 (switch-to-buffer gnus-group-buffer)
455 (goto-char (point-min))
457 ;; Save current level
458 (if (not gnus-offline-stored-group-level)
459 (while (re-search-forward " nnm" nil t)
460 (setq gnus-offline-stored-group-level
461 (append gnus-offline-stored-group-level
462 (list (gnus-group-group-level)))))
466 (goto-char (point-min))
467 (while (re-search-forward " nnm" nil t)
468 (gnus-group-set-current-level 1 level)
473 ;; Restore mail group level
475 (defun gnus-offline-restore-mail-group-level ()
476 "*Restore nnm* group level."
477 (switch-to-buffer gnus-group-buffer)
478 (goto-char (point-min))
480 (while (re-search-forward " nnm" nil t)
481 (gnus-group-set-current-level 1 (nth num gnus-offline-stored-group-level))
484 (beginning-of-line)))
486 ;; Jobs after getting new news.
488 (defun gnus-offline-after-get-new-news ()
489 "*After getting news and mail jobs."
490 (if (memq gnus-offline-articles-to-fetch '(both mail))
493 ;; send mail/news in spool
494 (gnus-offline-empting-spool)
495 (if (eq gnus-offline-articles-to-fetch 'mail)
497 ;; Send only mail and hang up...
498 (if (and gnus-offline-connected
499 gnus-offline-auto-hangup)
500 (gnus-offline-set-unplugged-state))
501 ;; Disable fetch mail.
502 (gnus-offline-disable-fetch-mail)
503 (gnus-offline-after-jobs-done)))))
506 (if (memq gnus-offline-articles-to-fetch '(both news))
508 (if gnus-offline-connected
509 (cond ((eq gnus-offline-news-fetch-method 'nnagent)
510 ;; Get New News (gnus-agent)
511 (gnus-agent-toggle-plugged t)
514 (gnus-agent-fetch-session)
516 ;; Hang Up line. then set to offline status.
517 (if (and gnus-offline-connected
518 gnus-offline-auto-hangup)
519 (gnus-offline-set-unplugged-state))
521 ;; All online jobs has done.
522 (gnus-offline-after-jobs-done))
524 (if (eq gnus-offline-news-fetch-method 'nnspool)
525 ;; Get New News (nnspool)
526 (gnspool-get-news))))))))
528 ;; Disable fetch mail
530 (defun gnus-offline-disable-fetch-mail ()
531 "*Set do not fetch mail."
532 (setq nnmail-spool-file nil))
536 (defun gnus-offline-enable-fetch-mail ()
537 "*Set to fetch mail."
538 (setq gnus-offline-mail-fetch-method 'nnmail)
539 (setq nnmail-movemail-program 'pop3-fma-movemail)
540 (setq nnmail-spool-file (append
541 pop3-fma-local-spool-file-alist
545 pop3-fma-spool-file-alist))))
549 (defun gnus-offline-enable-fetch-news ()
550 "*Set to fetch news."
551 (if (eq gnus-offline-news-fetch-method 'nnagent)
553 (setq gnus-agent-handle-level gnus-level-subscribed)
554 (gnus-agent-toggle-plugged t))))
557 ;; Add your custom header.
559 (defun gnus-offline-add-custom-header (header string)
560 "*Add X-Gnus-Offline-Backend header to Mail/News message."
562 (progn (goto-char (point-min))
564 (concat "^" (regexp-quote mail-header-separator) "\n"))
566 (goto-char (point-min))
567 (or (re-search-forward (concat "^" header) delimline t)
569 (goto-char delimline)
572 (setq hdr (concat header " "))
573 (setq str (concat hdr string))
574 (setq hdr (concat str "\n"))
575 (insert-string hdr)))))
577 ;; Add X-Offline-Backend header.
579 (defun gnus-offline-message-add-header ()
580 "*Add X-Gnus-Offline-Backend header to Mail/News message."
581 (if (eq gnus-offline-mail-treat-environ 'offline)
583 (if (eq gnus-offline-news-fetch-method 'nnagent)
584 (setq ver nnagent-version)
585 (setq ver nnspool-version))
586 (setq str (format "\n with %s" ver)
587 string (concat gnus-offline-header-string str))
588 (gnus-offline-add-custom-header "X-Gnus-Offline-Backend:" string))))
592 ;; Toggle plugged/unplugged
594 (defun gnus-offline-toggle-plugged (plugged)
595 "*Override function \"Jj\" - gnus-agent-toggle-plugged."
596 (interactive (list (not gnus-offline-connected)))
599 (setq gnus-offline-connected plugged)
600 (gnus-agent-toggle-plugged plugged)
601 ;; Set send mail/news function to offline functions.
602 (gnus-offline-set-online-sendmail-function)
603 (gnus-offline-set-online-post-news-function))
604 ;; Set to offline status
605 (gnus-offline-set-unplugged-state)))
607 ;; Function of hang up line.
609 (defun gnus-offline-set-unplugged-state ()
610 "*Set to unplugged state."
613 (if (functionp gnus-offline-hangup-function)
614 (funcall gnus-offline-hangup-function))
615 (setq gnus-offline-connected nil)
616 (if (eq gnus-offline-news-fetch-method 'nnagent)
617 (gnus-agent-toggle-plugged nil))
619 ;; Set send mail/news function to offline functions.
620 (gnus-offline-set-offline-sendmail-function)
621 (gnus-offline-set-offline-post-news-function)
623 (setenv "MAILHOST" nil))
625 ;; Hangup line function
627 (defun gnus-offline-hangup-line ()
628 "*Hangup line function."
629 (message "Hang up line ... ")
630 (if (stringp gnus-offline-hangup-program)
631 (apply 'start-process "hup" nil gnus-offline-hangup-program
632 gnus-offline-hangup-program-arguments))
633 (message "Hang up line ... done."))
635 ;; Hang Up line routine whe using nnspool
637 (defun gnus-offline-nnspool-hangup-line ()
638 (if (and gnus-offline-connected
639 gnus-offline-auto-hangup)
640 (gnus-offline-set-unplugged-state))
641 (gnus-offline-after-jobs-done))
643 ;; Function of all jobs has done.
645 (defun gnus-offline-after-jobs-done ()
646 "*Jobs after all online jobs."
647 (run-hooks 'gnus-offline-after-online-hook)
648 (if (eq gnus-offline-articles-to-fetch 'mail)
649 (gnus-offline-restore-mail-group-level))
650 (if (eq gnus-offline-news-fetch-method 'nnagent)
651 (or gnus-agent-expire-all
652 (gnus-offline-agent-expire)))
653 (if (and (featurep 'xemacs)
654 (fboundp 'play-sound-file))
657 (gnus-group-save-newsrc)
658 (message "All online jobs has done."))
662 ;; Toggle auto hang up
664 (defun gnus-offline-toggle-auto-hangup ()
665 "*Toggle auto hangup flag."
667 (setq string "Auto hang up logic")
668 (if gnus-offline-auto-hangup
670 (setq gnus-offline-auto-hangup nil
672 (setq gnus-offline-auto-hangup t
674 (message (format "%s %s" string str)))
676 ;; Toggle offline/online to send mail.
678 (defun gnus-offline-toggle-on/off-send-mail ()
679 "*Toggel online/offline sendmail."
681 (if (eq gnus-offline-mail-treat-environ 'offline)
683 ;; Sending mail under online environ.
684 (gnus-offline-set-online-sendmail-function)
685 (setq gnus-offline-mail-treat-environ 'online)
686 (message "Sending mail immidiately."))
687 ;; Sending mail under offline environ.
688 (gnus-offline-set-offline-sendmail-function)
689 (setq gnus-offline-mail-treat-environ 'offline)
690 (message "Sending mail temporary to spool directory.")))
692 ;; Toggle articles to fetch ... both -> mail -> news -> both
694 (defun gnus-offline-toggle-articles-to-fetch ()
695 "*Set articles to fetch... both(Mail/News) -> mail only -> News only -> both"
697 (setq string "Articles fetch from server.")
698 (cond ((eq gnus-offline-articles-to-fetch 'both)
699 (setq gnus-offline-articles-to-fetch 'mail
701 ((eq gnus-offline-articles-to-fetch 'mail)
702 (setq gnus-offline-articles-to-fetch 'news
705 (setq gnus-offline-articles-to-fetch 'both
706 str "Mail/News both")))
707 (message (format "%s %s" string str)))
709 ;; Toggle movemail program pop3.el -> movemail -> pop3.el
711 (defun gnus-offline-toggle-movemail-program ()
712 "*Toggle movemail program movemail -> pop3.el -> movemail ->..."
714 (setq string "Set nnmail-movemail-program")
715 (cond ((eq pop3-fma-movemail-type 'lisp)
716 (setq pop3-fma-movemail-type 'exe
719 (setq pop3-fma-movemail-type 'lisp
721 (message (format "%s %s" string str)))
723 ;; Send mail and Post news using Miee or gnus-agent.
725 (defun gnus-offline-empting-spool ()
726 "*Send all drafts on queue."
727 (run-hooks 'gnus-offline-before-empting-spool-hook)
728 (if (eq gnus-offline-drafts-queue-type 'miee)
729 ;; Send queued message by miee.el.
731 (if (eq gnus-offline-mail-treat-environ 'offline)
733 (message "Sending mails in spool ...")
734 ;; Using miee to send mail.
736 (message "Sending mails in spool ... done.")))
737 (message "Posting news in spool ...")
738 ;; Using miee to post news.
739 (if (and (not (stringp msspool-news-server))
740 (not msspool-news-service))
742 (setq msspool-news-server (nth 1 gnus-select-method))
743 (setq msspool-news-service 119)))
745 (message "Posting news in spool ... done."))
746 ;; Send queued message by gnus-agent
747 (message "Sending messages in spool ...")
748 (gnus-group-send-drafts)
749 (message "Sending messages in spool ... done."))
751 (run-hooks 'gnus-offline-after-empting-spool-hook))
755 (defun gnus-offline-set-interval-time ()
756 "*Set interval time for gnus-daemon."
758 (setq gnus-offline-interval-time
759 (string-to-int (read-from-minibuffer
760 (format "Interval time (now %s minutes) : "
761 gnus-offline-interval-time)
763 (if (< gnus-offline-interval-time 2)
765 (message "Retrieving message logic by timer is disabled.")
766 (setq gnus-offline-interval-time 0))
767 (message (format "Interval time set to %d minutes" gnus-offline-interval-time)))
768 (gnus-offline-processed-by-timer))
770 ;; Expire articles using gnus-agent.
772 (defun gnus-offline-agent-expire ()
773 "*Expire expirable article on News group."
779 (defun gnus-offline-define-menu-and-key ()
781 (if (eq gnus-offline-drafts-queue-type 'miee)
782 (if (featurep 'xemacs)
783 (add-hook 'gnus-group-mode-hook 'gnus-offline-define-menu-on-miee)
784 (gnus-offline-define-menu-on-miee))
785 (add-hook 'gnus-group-mode-hook 'gnus-offline-define-menu-on-agent))
786 (add-hook 'gnus-group-mode-hook
788 (local-set-key "\C-coh" 'gnus-offline-set-unplugged-state)
789 (local-set-key "\C-com" 'gnus-offline-toggle-movemail-program)
790 (local-set-key "\C-cof" 'gnus-offline-toggle-articles-to-fetch)
791 (local-set-key "\C-coo" 'gnus-offline-toggle-on/off-send-mail)
792 (local-set-key "\C-cox" 'gnus-offline-toggle-auto-hangup)
793 (local-set-key "\C-cos" 'gnus-offline-set-interval-time)
794 (substitute-key-definition
795 'gnus-group-get-new-news 'gnus-offline-gnus-get-new-news
797 (if (eq gnus-offline-news-fetch-method 'nnagent)
799 (substitute-key-definition
800 'gnus-agent-toggle-plugged 'gnus-offline-toggle-plugged
801 gnus-agent-group-mode-map)
802 (local-set-key "\C-coe" 'gnus-offline-agent-expire)))
803 (or (featurep 'xemacs)
804 (define-key gnus-group-mode-map
805 (if (eq system-type 'windows-nt) [S-mouse-2] [mouse-3])
806 'gnus-offline-popup-menu))))
807 (if (eq gnus-offline-news-fetch-method 'nnagent)
808 (add-hook 'gnus-summary-mode-hook
810 (substitute-key-definition
811 'gnus-agent-toggle-plugged 'gnus-offline-toggle-plugged
812 gnus-agent-summary-mode-map))))
813 (if (featurep 'xemacs)
814 ;; Overwrite the toolbar spec for gnus-group-mode.
815 (add-hook 'gnus-startup-hook
817 (let ((i 0) (stat t) but)
818 (while (and stat (setq but (nth i gnus-group-toolbar)))
819 (and (equal 'gnus-group-get-new-news (aref but 1))
820 (aset but 1 'gnus-offline-gnus-get-new-news)
822 (setq i (1+ i))))))))
825 (defun gnus-offline-define-menu-on-miee ()
826 "*Set and change menu bar on MIEE menu."
828 (if (featurep 'meadow)
833 ["Spool
\e$B$K$"$k5-;v$NAw?.
\e(B" news-spool-post t]
834 ["Spool
\e$B$K$"$k
\e(B Mail
\e$B$NAw?.
\e(B" mail-spool-send t]
836 ["Offline
\e$B>uBV$X
\e(B" message-offline-state (not message-offline-state)]
837 ["Online
\e$B>uBV$X
\e(B" message-online-state message-offline-state]
840 ["movemail
\e$B$N@ZBX$(
\e(B" gnus-offline-toggle-movemail-program t]
841 ["
\e$B<hF@5-;v<oN`$NJQ99
\e(B" gnus-offline-toggle-articles-to-fetch t]
842 ["Mail
\e$BAw?.J}K!
\e(B(On/Off)
\e$B$N@ZBX$(
\e(B" gnus-offline-toggle-on/off-send-mail t]
843 ["
\e$B<+F0@ZCG$N@ZBX$(
\e(B" gnus-offline-toggle-auto-hangup t]
845 ["
\e$B<hF@:Q5-;v$r>C$9
\e(B" gnus-offline-agent-expire (eq gnus-offline-news-fetch-method 'nnagent)]
846 ["
\e$B5-;v<hF@4V3V;~4V$N@_Dj
\e(B" gnus-offline-set-interval-time t]
848 ["
\e$B2s@~$N@ZCG
\e(B" gnus-offline-set-unplugged-state gnus-offline-connected])
854 ["Post news in spool" news-spool-post t]
855 ["Send mails in spool" mail-spool-send t]
857 ["Message Offline" message-offline-state (not message-offline-state)]
858 ["Message Online" message-online-state message-offline-state]
861 ["Toggle movemail program" gnus-offline-toggle-movemail-program t]
862 ["Toggle articles to fetch" gnus-offline-toggle-articles-to-fetch t]
863 ["Toggle online/offline send mail" gnus-offline-toggle-on/off-send-mail t]
864 ["Toggle auto hangup" gnus-offline-toggle-auto-hangup t]
866 ["Expire articles" gnus-offline-agent-expire (eq gnus-offline-news-fetch-method 'nnagent)]
867 ["Set interval time" gnus-offline-set-interval-time t]
869 ["Hang up Line." gnus-offline-set-unplugged-state gnus-offline-connected]
871 (and (featurep 'xemacs)
872 (easy-menu-add menu))))
874 ;; define menu without miee.
876 (defun gnus-offline-define-menu-on-agent ()
877 "*Set menu bar on OFFLINE menu."
879 gnus-offline-menu-on-agent
882 (if (featurep 'meadow)
884 ["movemail
\e$B$N@ZBX$(
\e(B" gnus-offline-toggle-movemail-program t]
885 ["
\e$B<hF@5-;v<oN`$NJQ99
\e(B" gnus-offline-toggle-articles-to-fetch t]
886 ["Mail
\e$BAw?.J}K!
\e(B(On/Off)
\e$B$N@ZBX$(
\e(B" gnus-offline-toggle-on/off-send-mail t]
887 ["
\e$B<+F0@ZCG$N@ZBX$(
\e(B" gnus-offline-toggle-auto-hangup t]
889 ["
\e$B<hF@:Q5-;v$r>C$9
\e(B" gnus-offline-agent-expire (eq gnus-offline-news-fetch-method 'nnagent)]
890 ["
\e$B5-;v<hF@4V3V;~4V$N@_Dj
\e(B" gnus-offline-set-interval-time t]
892 ["
\e$B2s@~$N@ZCG
\e(B" gnus-offline-set-unplugged-state gnus-offline-connected])
894 ["Toggle movemail program" gnus-offline-toggle-movemail-program t]
895 ["Toggle articles to fetch" gnus-offline-toggle-articles-to-fetch t]
896 ["Toggle online/offline send mail" gnus-offline-toggle-on/off-send-mail t]
897 ["Toggle auto hangup" gnus-offline-toggle-auto-hangup t]
899 ["Expire articles" gnus-offline-agent-expire (eq gnus-offline-news-fetch-method 'nnagent)]
900 ["Set interval time" gnus-offline-set-interval-time t]
902 ["Hang up Line." gnus-offline-set-unplugged-state gnus-offline-connected])))
903 (and (featurep 'xemacs)
904 (easy-menu-add gnus-offline-menu-on-agent)))
906 ;; Popup menu within the group buffer (under Emacs).
908 (defun gnus-offline-popup-menu (event)
909 "Popup menu for Gnus offline."
911 (let* ((menu (if (boundp 'miee-popup-menu)
913 (assoc 'Miee (assoc 'menu-bar global-map)))
915 gnus-offline-menu-on-agent))
916 (pop (x-popup-menu t menu))
917 (func (and pop (lookup-key menu (apply 'vector pop)))))
918 (and pop func (funcall func))))
922 (defun gnus-offline-processed-by-timer ()
923 "*Set timer interval."
924 (if (and (> gnus-offline-interval-time 0)
925 (not gnus-offline-connected))
927 (gnus-demon-add-handler 'gnus-offline-gnus-get-new-news
928 gnus-offline-interval-time
929 gnus-offline-interval-time))
930 (if (= gnus-offline-interval-time 0)
931 (gnus-demon-remove-handler 'gnus-offline-gnus-get-new-news t)))
934 (provide 'gnus-offline)
935 ;;; gnus-offline.el ends here