1 ;;; gnus-offline.el --- To process mail & news at offline environment.
2 ;;; $Id: gnus-offline.el,v 1.1.4.9 1999-03-22 18:18:47 czkmt 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 (null gnus-offline-pop-password-file)
388 (gnus-group-get-new-news arg)
389 (let ((buffer (get-buffer-create "*offline-temp*")))
392 (if (boundp 'pop3-fma-password)
393 (setq pop3-fma-save-password-information t))
397 (insert-file-contents-as-binary gnus-offline-pop-password-file)
398 (and gnus-offline-pop-password-decoding-function
399 (funcall gnus-offline-pop-password-decoding-function))
401 (gnus-group-get-new-news arg))
402 (if (boundp 'pop3-fma-password)
403 (setq pop3-fma-password nil
404 pop3-fma-save-password-information nil)
405 (setq mail-source-password-cache nil))
406 (kill-buffer buffer)))))
411 (defun gnus-offline-connect-server ()
413 ;; Dialup if gnus-offline-dialup-program is specified
414 (if (stringp gnus-offline-dialup-program)
416 (message "Dialing ...")
417 (apply 'call-process gnus-offline-dialup-program nil nil nil
418 gnus-offline-dialup-program-arguments)
420 (message "Dialing ... done."))))
423 ;; Jobs before get new news , send mail and post news.
425 (defun gnus-offline-get-new-news-function ()
426 "*Prepare to get new news/mail."
427 ;; Set mail group level
428 (if (eq gnus-offline-articles-to-fetch 'mail)
429 (gnus-offline-set-mail-group-level gnus-offline-mail-group-level))
431 ;; Set to online environ.
432 (setq gnus-offline-connected t)
434 ;; Set send mail/news functions to online functions.
435 (gnus-offline-set-online-sendmail-function)
436 (gnus-offline-set-online-post-news-function)
437 (message "Set to online status.")
440 (if (eq gnus-offline-articles-to-fetch 'news)
441 (gnus-offline-disable-fetch-mail))
443 ;; fetch both mail and news. or Only mail.
444 (gnus-offline-enable-fetch-news)
445 (if (memq gnus-offline-articles-to-fetch '(both mail))
446 (gnus-offline-enable-fetch-mail))
448 ;; fetch only mail for gnus-agent
449 (if (and (eq gnus-offline-news-fetch-method 'nnagent)
450 (eq gnus-offline-articles-to-fetch 'mail))
451 (setq gnus-agent-handle-level gnus-offline-mail-group-level)))
454 ;; Change mail group level to handle only mail.
456 (defun gnus-offline-set-mail-group-level (level)
457 "*Set nnm* group level."
458 (switch-to-buffer gnus-group-buffer)
459 (goto-char (point-min))
461 ;; Save current level
462 (if (not gnus-offline-stored-group-level)
463 (while (re-search-forward " nnm" nil t)
464 (setq gnus-offline-stored-group-level
465 (append gnus-offline-stored-group-level
466 (list (gnus-group-group-level)))))
470 (goto-char (point-min))
471 (while (re-search-forward " nnm" nil t)
472 (gnus-group-set-current-level 1 level)
477 ;; Restore mail group level
479 (defun gnus-offline-restore-mail-group-level ()
480 "*Restore nnm* group level."
481 (switch-to-buffer gnus-group-buffer)
482 (goto-char (point-min))
484 (while (re-search-forward " nnm" nil t)
485 (gnus-group-set-current-level 1 (nth num gnus-offline-stored-group-level))
488 (beginning-of-line)))
490 ;; Jobs after getting new news.
492 (defun gnus-offline-after-get-new-news ()
493 "*After getting news and mail jobs."
494 (if (memq gnus-offline-articles-to-fetch '(both mail))
497 ;; send mail/news in spool
498 (gnus-offline-empting-spool)
499 (if (eq gnus-offline-articles-to-fetch 'mail)
501 ;; Send only mail and hang up...
502 (if (and gnus-offline-connected
503 gnus-offline-auto-hangup)
504 (gnus-offline-set-unplugged-state))
505 ;; Disable fetch mail.
506 (gnus-offline-disable-fetch-mail)
507 (gnus-offline-after-jobs-done)))))
510 (if (memq gnus-offline-articles-to-fetch '(both news))
512 (if gnus-offline-connected
513 (cond ((eq gnus-offline-news-fetch-method 'nnagent)
514 ;; Get New News (gnus-agent)
515 (gnus-agent-toggle-plugged t)
518 (gnus-agent-fetch-session)
520 ;; Hang Up line. then set to offline status.
521 (if (and gnus-offline-connected
522 gnus-offline-auto-hangup)
523 (gnus-offline-set-unplugged-state))
525 ;; All online jobs has done.
526 (gnus-offline-after-jobs-done))
528 (if (eq gnus-offline-news-fetch-method 'nnspool)
529 ;; Get New News (nnspool)
530 (gnspool-get-news))))))))
532 ;; Disable fetch mail
534 (defun gnus-offline-disable-fetch-mail ()
535 "*Set do not fetch mail."
536 (setq nnmail-spool-file nil))
540 (defun gnus-offline-enable-fetch-mail ()
541 "*Set to fetch mail."
542 (setq gnus-offline-mail-fetch-method 'nnmail)
543 (if (not (featurep 'running-pterodactyl-gnus-0_73-or-later))
545 (setq nnmail-movemail-program 'pop3-fma-movemail)
546 (setq nnmail-spool-file (append
547 pop3-fma-local-spool-file-alist
551 pop3-fma-spool-file-alist))))
552 (setq nnmail-spool-file gnus-offline-mail-source)))
556 (defun gnus-offline-enable-fetch-news ()
557 "*Set to fetch news."
558 (if (eq gnus-offline-news-fetch-method 'nnagent)
560 (setq gnus-agent-handle-level gnus-level-subscribed)
561 (gnus-agent-toggle-plugged t))))
564 ;; Add your custom header.
566 (defun gnus-offline-add-custom-header (header string)
567 "*Add X-Gnus-Offline-Backend header to Mail/News message."
569 (progn (goto-char (point-min))
571 (concat "^" (regexp-quote mail-header-separator) "\n"))
573 (goto-char (point-min))
574 (or (re-search-forward (concat "^" header) delimline t)
576 (goto-char delimline)
579 (setq hdr (concat header " "))
580 (setq str (concat hdr string))
581 (setq hdr (concat str "\n"))
582 (insert-string hdr)))))
584 ;; Add X-Offline-Backend header.
586 (defun gnus-offline-message-add-header ()
587 "*Add X-Gnus-Offline-Backend header to Mail/News message."
588 (if (eq gnus-offline-mail-treat-environ 'offline)
590 (if (eq gnus-offline-news-fetch-method 'nnagent)
591 (setq ver nnagent-version)
592 (setq ver nnspool-version))
593 (setq str (format "\n with %s" ver)
594 string (concat gnus-offline-header-string str))
595 (gnus-offline-add-custom-header "X-Gnus-Offline-Backend:" string))))
599 ;; Toggle plugged/unplugged
601 (defun gnus-offline-toggle-plugged (plugged)
602 "*Override function \"Jj\" - gnus-agent-toggle-plugged."
603 (interactive (list (not gnus-offline-connected)))
606 (setq gnus-offline-connected plugged)
607 (gnus-agent-toggle-plugged plugged)
608 ;; Set send mail/news function to offline functions.
609 (gnus-offline-set-online-sendmail-function)
610 (gnus-offline-set-online-post-news-function))
611 ;; Set to offline status
612 (gnus-offline-set-unplugged-state)))
614 ;; Function of hang up line.
616 (defun gnus-offline-set-unplugged-state ()
617 "*Set to unplugged state."
620 (if (functionp gnus-offline-hangup-function)
621 (funcall gnus-offline-hangup-function))
622 (setq gnus-offline-connected nil)
623 (if (eq gnus-offline-news-fetch-method 'nnagent)
624 (gnus-agent-toggle-plugged nil))
626 ;; Set send mail/news function to offline functions.
627 (gnus-offline-set-offline-sendmail-function)
628 (gnus-offline-set-offline-post-news-function)
630 (setenv "MAILHOST" nil))
632 ;; Hangup line function
634 (defun gnus-offline-hangup-line ()
635 "*Hangup line function."
636 (message "Hang up line ... ")
637 (if (stringp gnus-offline-hangup-program)
638 (apply 'start-process "hup" nil gnus-offline-hangup-program
639 gnus-offline-hangup-program-arguments))
640 (message "Hang up line ... done."))
642 ;; Hang Up line routine whe using nnspool
644 (defun gnus-offline-nnspool-hangup-line ()
645 (if (and gnus-offline-connected
646 gnus-offline-auto-hangup)
647 (gnus-offline-set-unplugged-state))
648 (gnus-offline-after-jobs-done))
650 ;; Function of all jobs has done.
652 (defun gnus-offline-after-jobs-done ()
653 "*Jobs after all online jobs."
654 (run-hooks 'gnus-offline-after-online-hook)
655 (if (eq gnus-offline-articles-to-fetch 'mail)
656 (gnus-offline-restore-mail-group-level))
657 (if (eq gnus-offline-news-fetch-method 'nnagent)
658 (or gnus-agent-expire-all
659 (gnus-offline-agent-expire)))
660 (if (and (featurep 'xemacs)
661 (fboundp 'play-sound-file))
664 (gnus-group-save-newsrc)
665 (message "All online jobs has done."))
669 ;; Toggle auto hang up
671 (defun gnus-offline-toggle-auto-hangup ()
672 "*Toggle auto hangup flag."
674 (setq string "Auto hang up logic")
675 (if gnus-offline-auto-hangup
677 (setq gnus-offline-auto-hangup nil
679 (setq gnus-offline-auto-hangup t
681 (message (format "%s %s" string str)))
683 ;; Toggle offline/online to send mail.
685 (defun gnus-offline-toggle-on/off-send-mail ()
686 "*Toggel online/offline sendmail."
688 (if (eq gnus-offline-mail-treat-environ 'offline)
690 ;; Sending mail under online environ.
691 (gnus-offline-set-online-sendmail-function)
692 (setq gnus-offline-mail-treat-environ 'online)
693 (message "Sending mail immidiately."))
694 ;; Sending mail under offline environ.
695 (gnus-offline-set-offline-sendmail-function)
696 (setq gnus-offline-mail-treat-environ 'offline)
697 (message "Sending mail temporary to spool directory.")))
699 ;; Toggle articles to fetch ... both -> mail -> news -> both
701 (defun gnus-offline-toggle-articles-to-fetch ()
702 "*Set articles to fetch... both(Mail/News) -> mail only -> News only -> both"
704 (setq string "Articles fetch from server.")
705 (cond ((eq gnus-offline-articles-to-fetch 'both)
706 (setq gnus-offline-articles-to-fetch 'mail
708 ((eq gnus-offline-articles-to-fetch 'mail)
709 (setq gnus-offline-articles-to-fetch 'news
712 (setq gnus-offline-articles-to-fetch 'both
713 str "Mail/News both")))
714 (message (format "%s %s" string str)))
716 ;; Toggle movemail program pop3.el -> movemail -> pop3.el
718 (defun gnus-offline-toggle-movemail-program ()
719 "*Toggle movemail program movemail -> pop3.el -> movemail ->..."
721 (setq string "Set nnmail-movemail-program")
722 (cond ((eq pop3-fma-movemail-type 'lisp)
723 (setq pop3-fma-movemail-type 'exe
726 (setq pop3-fma-movemail-type 'lisp
728 (message (format "%s %s" string str)))
730 ;; Send mail and Post news using Miee or gnus-agent.
732 (defun gnus-offline-empting-spool ()
733 "*Send all drafts on queue."
734 (run-hooks 'gnus-offline-before-empting-spool-hook)
735 (if (eq gnus-offline-drafts-queue-type 'miee)
736 ;; Send queued message by miee.el.
738 (if (eq gnus-offline-mail-treat-environ 'offline)
740 (message "Sending mails in spool ...")
741 ;; Using miee to send mail.
743 (message "Sending mails in spool ... done.")))
744 (message "Posting news in spool ...")
745 ;; Using miee to post news.
746 (if (and (not (stringp msspool-news-server))
747 (not msspool-news-service))
749 (setq msspool-news-server (nth 1 gnus-select-method))
750 (setq msspool-news-service 119)))
752 (message "Posting news in spool ... done."))
753 ;; Send queued message by gnus-agent
754 (message "Sending messages in spool ...")
755 (gnus-group-send-drafts)
756 (message "Sending messages in spool ... done."))
758 (run-hooks 'gnus-offline-after-empting-spool-hook))
762 (defun gnus-offline-set-interval-time ()
763 "*Set interval time for gnus-daemon."
765 (setq gnus-offline-interval-time
766 (string-to-int (read-from-minibuffer
767 (format "Interval time (now %s minutes) : "
768 gnus-offline-interval-time)
770 (if (< gnus-offline-interval-time 2)
772 (message "Retrieving message logic by timer is disabled.")
773 (setq gnus-offline-interval-time 0))
774 (message (format "Interval time set to %d minutes" gnus-offline-interval-time)))
775 (gnus-offline-processed-by-timer))
777 ;; Expire articles using gnus-agent.
779 (defun gnus-offline-agent-expire ()
780 "*Expire expirable article on News group."
786 (defun gnus-offline-define-menu-and-key ()
788 (if (eq gnus-offline-drafts-queue-type 'miee)
789 (if (featurep 'xemacs)
790 (add-hook 'gnus-group-mode-hook 'gnus-offline-define-menu-on-miee)
791 (gnus-offline-define-menu-on-miee))
792 (add-hook 'gnus-group-mode-hook 'gnus-offline-define-menu-on-agent))
793 (add-hook 'gnus-group-mode-hook
795 (local-set-key "\C-coh" 'gnus-offline-set-unplugged-state)
796 (if (not (featurep 'running-pterodactyl-gnus-0_73-or-later))
797 (local-set-key "\C-com" 'gnus-offline-toggle-movemail-program))
798 (local-set-key "\C-cof" 'gnus-offline-toggle-articles-to-fetch)
799 (local-set-key "\C-coo" 'gnus-offline-toggle-on/off-send-mail)
800 (local-set-key "\C-cox" 'gnus-offline-toggle-auto-hangup)
801 (local-set-key "\C-cos" 'gnus-offline-set-interval-time)
802 (substitute-key-definition
803 'gnus-group-get-new-news 'gnus-offline-gnus-get-new-news
805 (if (eq gnus-offline-news-fetch-method 'nnagent)
807 (substitute-key-definition
808 'gnus-agent-toggle-plugged 'gnus-offline-toggle-plugged
809 gnus-agent-group-mode-map)
810 (local-set-key "\C-coe" 'gnus-offline-agent-expire)))
811 (or (featurep 'xemacs)
812 (define-key gnus-group-mode-map
813 (if (eq system-type 'windows-nt) [S-mouse-2] [mouse-3])
814 'gnus-offline-popup-menu))))
815 (if (eq gnus-offline-news-fetch-method 'nnagent)
816 (add-hook 'gnus-summary-mode-hook
818 (substitute-key-definition
819 'gnus-agent-toggle-plugged 'gnus-offline-toggle-plugged
820 gnus-agent-summary-mode-map))))
821 (if (featurep 'xemacs)
822 ;; Overwrite the toolbar spec for gnus-group-mode.
823 (add-hook 'gnus-startup-hook
826 (mapcar (lambda (but)
827 (when (eq 'gnus-group-get-new-news (aref but 1))
828 (aset but 1 'gnus-offline-gnus-get-new-news)
830 gnus-group-toolbar))))))
833 (defun gnus-offline-define-menu-on-miee ()
834 "*Set and change menu bar on MIEE menu."
836 (if (featurep 'meadow)
841 ["Spool
\e$B$K$"$k5-;v$NAw?.
\e(B" news-spool-post t]
842 ["Spool
\e$B$K$"$k
\e(B Mail
\e$B$NAw?.
\e(B" mail-spool-send t]
844 ["Offline
\e$B>uBV$X
\e(B" message-offline-state (not message-offline-state)]
845 ["Online
\e$B>uBV$X
\e(B" message-online-state message-offline-state]
848 ["movemail
\e$B$N@ZBX$(
\e(B" gnus-offline-toggle-movemail-program
849 (not (featurep 'running-pterodactyl-gnus-0_73-or-later))]
850 ["
\e$B<hF@5-;v<oN`$NJQ99
\e(B" gnus-offline-toggle-articles-to-fetch t]
851 ["Mail
\e$BAw?.J}K!
\e(B(On/Off)
\e$B$N@ZBX$(
\e(B" gnus-offline-toggle-on/off-send-mail t]
852 ["
\e$B<+F0@ZCG$N@ZBX$(
\e(B" gnus-offline-toggle-auto-hangup t]
854 ["
\e$B<hF@:Q5-;v$r>C$9
\e(B" gnus-offline-agent-expire (eq gnus-offline-news-fetch-method 'nnagent)]
855 ["
\e$B5-;v<hF@4V3V;~4V$N@_Dj
\e(B" gnus-offline-set-interval-time t]
857 ["
\e$B2s@~$N@ZCG
\e(B" gnus-offline-set-unplugged-state gnus-offline-connected])
863 ["Post news in spool" news-spool-post t]
864 ["Send mails in spool" mail-spool-send t]
866 ["Message Offline" message-offline-state (not message-offline-state)]
867 ["Message Online" message-online-state message-offline-state]
870 ["Toggle movemail program" gnus-offline-toggle-movemail-program
871 (not (featurep 'running-pterodactyl-gnus-0_73-or-later))]
872 ["Toggle articles to fetch" gnus-offline-toggle-articles-to-fetch t]
873 ["Toggle online/offline send mail" gnus-offline-toggle-on/off-send-mail t]
874 ["Toggle auto hangup" gnus-offline-toggle-auto-hangup t]
876 ["Expire articles" gnus-offline-agent-expire (eq gnus-offline-news-fetch-method 'nnagent)]
877 ["Set interval time" gnus-offline-set-interval-time t]
879 ["Hang up Line." gnus-offline-set-unplugged-state gnus-offline-connected]
881 (and (featurep 'xemacs)
882 (easy-menu-add menu))))
884 ;; define menu without miee.
886 (defun gnus-offline-define-menu-on-agent ()
887 "*Set menu bar on OFFLINE menu."
889 gnus-offline-menu-on-agent
892 (if (featurep 'meadow)
894 ["movemail
\e$B$N@ZBX$(
\e(B" gnus-offline-toggle-movemail-program
895 (not (featurep 'running-pterodactyl-gnus-0_73-or-later))]
896 ["
\e$B<hF@5-;v<oN`$NJQ99
\e(B" gnus-offline-toggle-articles-to-fetch t]
897 ["Mail
\e$BAw?.J}K!
\e(B(On/Off)
\e$B$N@ZBX$(
\e(B" gnus-offline-toggle-on/off-send-mail t]
898 ["
\e$B<+F0@ZCG$N@ZBX$(
\e(B" gnus-offline-toggle-auto-hangup t]
900 ["
\e$B<hF@:Q5-;v$r>C$9
\e(B" gnus-offline-agent-expire (eq gnus-offline-news-fetch-method 'nnagent)]
901 ["
\e$B5-;v<hF@4V3V;~4V$N@_Dj
\e(B" gnus-offline-set-interval-time t]
903 ["
\e$B2s@~$N@ZCG
\e(B" gnus-offline-set-unplugged-state gnus-offline-connected])
905 ["Toggle movemail program" gnus-offline-toggle-movemail-program
906 (not (featurep 'running-pterodactyl-gnus-0_73-or-later))]
907 ["Toggle articles to fetch" gnus-offline-toggle-articles-to-fetch t]
908 ["Toggle online/offline send mail" gnus-offline-toggle-on/off-send-mail t]
909 ["Toggle auto hangup" gnus-offline-toggle-auto-hangup t]
911 ["Expire articles" gnus-offline-agent-expire (eq gnus-offline-news-fetch-method 'nnagent)]
912 ["Set interval time" gnus-offline-set-interval-time t]
914 ["Hang up Line." gnus-offline-set-unplugged-state gnus-offline-connected])))
915 (and (featurep 'xemacs)
916 (easy-menu-add gnus-offline-menu-on-agent)))
918 ;; Popup menu within the group buffer (under Emacs).
920 (defvar gnus-offline-popup-menu nil)
921 (defun gnus-offline-popup-menu (event)
922 "Popup menu for Gnus offline."
924 (unless gnus-offline-popup-menu
925 (setq gnus-offline-popup-menu
926 (or (featurep 'xemacs)
928 (if (boundp 'miee-popup-menu)
930 (assoc 'Miee (assoc 'menu-bar global-map)))
932 gnus-offline-menu-on-agent)))
933 (if (string< emacs-version "20")
934 (append (list 'keymap
935 (if (boundp 'miee-popup-menu)
942 (let* ((pop (x-popup-menu t gnus-offline-popup-menu))
943 (func (and pop (lookup-key gnus-offline-popup-menu
944 (apply 'vector pop)))))
945 (and pop func (funcall func))))
949 (defun gnus-offline-processed-by-timer ()
950 "*Set timer interval."
951 (if (and (> gnus-offline-interval-time 0)
952 (not gnus-offline-connected))
954 (gnus-demon-add-handler 'gnus-offline-gnus-get-new-news
955 gnus-offline-interval-time
956 gnus-offline-interval-time))
957 (if (= gnus-offline-interval-time 0)
958 (gnus-demon-remove-handler 'gnus-offline-gnus-get-new-news t)))
961 (provide 'gnus-offline)
962 ;;; gnus-offline.el ends here