1 ;;; gnus-offline.el --- To process mail & news at offline environment.
3 ;;; Copyright (C) 1998 Tatsuya Ichikawa
5 ;;; Author: Tatsuya Ichikawa <t-ichi@po.shiojiri.ne.jp>
6 ;;; Yukihiro Ito <ito@rs.civil.tohoku.ac.jp>
7 ;;; Hidekazu Nakamura <u90121@uis-inf.co.jp>
8 ;;; Tsukamoto Tetsuo <czkmt@remus.dti.ne.jp>
11 ;;; Keywords: news , mail , offline , gnus
14 ;;; Keiichi Suzuki <kei-suzu@mail.wbs.or.jp>
15 ;;; KORIYAMA Naohiro <kory@ba2.so-net.or.jp>
16 ;;; Katsumi Yamaoka <yamaoka@jpl.org>
18 ;;; This file is part of Semi-gnus.
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.
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.
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.
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
41 ;;; You must use T-gnus 6.12.0 or later.
45 ;;; Add following code at the end in your .emacs
47 ;;; (load "gnus-ofsetup")
48 ;;; (gnus-setup-for-offline)
50 ;;; If you use gnus-agent as souper , put gnus-agent setup code in you .gnus.el
52 ;;; If you use nnspool as souper , put following code in your .emacs before
53 ;;; gnus-offline setting.
55 ;;; Then , put hang.exe in exec-path directory.
57 ;;; In Gnus group buffer , type g to get all news and mail.
58 ;;; Then send mail and news in spool directory.
61 ;;; gnus-offline-dialup-program-arguments
62 ;;; ... List of dialup program arguments.
63 ;;; gnus-offline-hangup-program-arguments
64 ;;; ... List of hangup program arguments.
65 ;;; gnus-offline-mail-treat-environ ... toggle sending mail online/offline.
66 ;;; gnus-offline-articles-to-fetch ... toggle fetch articles.
67 ;;; both->mail->news->both...
68 ;;; gnus-offline-load-hook ... hook before gnus-offline load.
69 ;;; gnus-offline-before-online-hook ... hook before all online jobs.
70 ;;; gnus-offline-after-online-hook ... hook after all online jobs.
71 ;;; gnus-offline-interval-time ... Interval time to do all online jobs.
73 ;;; gnus-offline-dialup-function ... Function to diualup.
74 ;;; gnus-offline-hangup-function ... Function to hangup.
78 (eval '(run-hooks 'gnus-offline-load-hook))
80 (eval-when-compile (require 'cl))
84 (require 'gnus-group))
87 (provide 'gnus-offline)
89 (defgroup gnus-offline nil
90 "Offline backend utility for Gnus."
91 :prefix "gnus-offline-"
96 (defconst gnus-offline-version-number "2.20")
97 (defconst gnus-offline-codename
99 ;; "This is the time" ; 2.00
100 ;; "A matter of trust"
102 ;; "Ahhhhhhh!!" ; 2.10b1
107 (defconst gnus-offline-version (format "Gnus offline backend utiliy v%s"
108 gnus-offline-version-number))
113 (unless (boundp symbol)
114 (make-local-variable symbol)
115 (eval (list 'setq symbol nil))))
121 gnus-group-toolbar)))
123 (if (featurep 'meadow)
124 (define-process-argument-editing "/hang\\.exe\\'"
126 (general-process-argument-editing-function
127 x nil t t nil t t))))
129 (defcustom gnus-offline-auto-ppp '(connect disconnect)
130 "*This variable decides whether to connect and/or disconnect automatically."
133 (const :tag "Connection and Disconnection" (connect disconnect))
134 (const :tag "Connection Only" (connect))
135 (const :tag "Do Everything Manually" nil)))
137 (defcustom gnus-offline-load-hook nil
138 "*Hook to be run after the gnus-offline package has been loaded."
142 (defcustom gnus-offline-before-online-hook nil
143 "*Hook to be run before all online jobs."
147 (defcustom gnus-offline-after-online-hook nil
148 "*Hook to be run after all online jobs."
152 (defcustom gnus-offline-mail-treat-environ 'offline
153 "*If online , gnus-offline send all mail under online environ.
154 If offline , gnus-offline send all mail temporary to spool dir."
156 :type '(choice (const offline)
159 (defcustom gnus-offline-articles-to-fetch 'both
160 "*If both , gnus-offline fetch mail and news articles.
161 If mail , gnus-offline only fetch mail articles.
162 If news , gnus-offline only fetch news articles."
164 :type '(choice (const both)
168 (defcustom gnus-offline-mail-group-level 1
169 "*Group level for mail group."
173 (defcustom gnus-offline-after-empting-spool-hook nil
174 "*Hook to be run before empting spool."
178 (defcustom gnus-offline-before-empting-spool-hook nil
179 "*Hook to be run after empting spool."
183 (defcustom gnus-offline-dialup-function 'gnus-offline-connect-server
184 "*Function to dialup."
188 (defcustom gnus-offline-hangup-function 'gnus-offline-hangup-line
189 "*Function to hangup."
193 (defcustom gnus-offline-auto-expire t
194 "*Non-nil means expire articles on every session."
198 ;; These variables should be customized using `gnus-offline-customize',
199 ;; not by `customize'.
201 (defvar gnus-offline-dialup-program nil
202 "*Program name for dialup.")
204 (defvar gnus-offline-hangup-program nil
205 "*Program name for hangup.")
207 (defvar gnus-offline-dialup-program-arguments nil
208 "*Program arguments of gnus-offline-dialup-program.")
210 (defvar gnus-offline-hangup-program-arguments nil
211 "*Program arguments of gnus-offline-hangup-program.")
213 (defvar gnus-offline-interval-time 0
214 "*Interval time(minutes) to do online jobs.
215 If set to 0 , timer call is disabled.")
217 (defvar gnus-offline-drafts-queue-type 'agent
218 "*Queuing function used for draft messages.")
220 (defvar gnus-offline-MTA-type 'smtp
221 "*Type of MTA, sendmail or smtp.el.")
223 ;;; Internal variables.
224 (defvar gnus-offline-connected nil
225 "*If value is t , dialup line is connected status.
226 If value is nil , dialup line is disconnected status.")
228 (defvar gnus-offline-news-fetch-method nil
229 "*Method to fetch news articles.")
231 (defvar gnus-offline-mail-fetch-method nil
232 "*Method to fetch mail articles.")
234 (defvar gnus-offline-header-string
235 (format "%s - \"%s\""
237 gnus-offline-codename)
238 "*Header string for gnus-offline.")
240 (defvar gnus-offline-stored-group-level nil
241 "*Mail Group level before changing.")
243 (defvar gnus-offline-mail-source nil
244 "*mail-sources save variable.")
246 (defvar gnus-offline-lang)
248 (defvar gnus-offline-resource-en
250 . "WARNING!!: gnus-agent.el or nnagent.el is not loaded.
251 Please check your .emacs or .gnus.el to work gnus-agent fine.")
252 (error-check-2 ."WARNING!!: nnspool.el is not loaded.
253 Please check your .emacs or .gnus.el to work nnspool fine.")
254 (connect-server-1 . "Dialing ...")
255 (connect-server-2 . "Dialing ... done.")
256 (get-new-news-function-1 . "Set to online status.")
257 (hangup-line-1 . "Hang up line ... ")
258 (hangup-line-2 . "Hang up line ... done.")
259 (after-jobs-done-1 . "All online jobs has done.")
260 (set-auto-ppp-1 . "Connect and disconnect automatically.")
261 (set-auto-ppp-2 . "Connect automatically.")
262 (set-auto-ppp-3 . "Connect and disconnect manually.")
263 (set-auto-ppp-menu-1 . "Automatically Connect/Disconnect")
264 (set-auto-ppp-menu-2 . "Automatically Connect")
265 (set-auto-ppp-menu-3 . "Manually Connect/Disconnect")
266 (toggle-on/off-send-mail-1 . "Sending mail immidiately.")
267 (toggle-on/off-send-mail-2 . "Sending mail temporary to spool directory.")
268 (toggle-articles-to-fetch-1 . "Articles fetch from server.")
269 (toggle-articles-to-fetch-2 . "Only Mail")
270 (toggle-articles-to-fetch-3 . "Only News")
271 (toggle-articles-to-fetch-4 . "Mail/News both")
272 (empting-spool-1 . "Sending mails in spool ...")
273 (empting-spool-2 . "Sending mails in spool ... done.")
274 (empting-spool-3 . "Posting news in spool ...")
275 (empting-spool-4 . "Posting news in spool ... done.")
276 (empting-spool-5 . "Sending messages in spool ...")
277 (empting-spool-6 . "Sending messages in spool ... done.")
278 (interval-time-1 . "Interval time (now %d minutes) : ")
279 (interval-time-2 . "Retrieving message logic by timer is disabled.")
280 (interval-time-3 . "Interval time set to %d minutes")
281 (menu-miee-1 . "Post news in spool")
282 (menu-miee-2 . "Send mails in spool")
283 (menu-miee-3 . "Message Offline")
284 (menu-miee-4 . "Message Online")
285 (menu-1 . "Toggle articles to fetch")
286 (menu-2 . "Toggle online/offline send mail")
287 (menu-3 . "Set auto PPP")
288 (menu-4 . "Expire articles")
289 (menu-5 . "Set interval time")
290 (menu-6 . "Hang up Line.")
291 (menu-7 . "Customize options...")))
293 (defvar gnus-offline-resource-ja
295 . "
\e$B7Y9p
\e(B!!: gnus-agent.el
\e$B$^$?$O
\e(B nnagent.el
\e$B$,%m!<%I$5$l$F$$$^$;$s!#
\e(B
296 .emacs
\e$B$^$?$O
\e(B .gnus.el
\e$B$N
\e(B gnus-agent
\e$B$N@_Dj$r@5$7$/$7$F$/$@$5$$!#
\e(B")
297 (error-check-2 ."
\e$B7Y9p
\e(B!!: nnspool.el
\e$B$,%m!<%I$5$l$F$$$^$;$s!#
\e(B
298 .emacs
\e$B$^$?$O
\e(B .gnus.el
\e$B$N
\e(B nnspool
\e$B$N@_Dj$r@5$7$/$7$F$/$@$5$$!#
\e(B")
299 (connect-server-1 . "
\e$B@\B3$7$F$$$^$9
\e(B...")
300 (connect-server-2 . "
\e$B@\B3$7$F$$$^$9
\e(B...
\e$B40N;!#
\e(B")
301 (get-new-news-function-1 . "
\e$B%*%s%i%$%s>uBV$G$9!#
\e(B")
302 (set-auto-ppp-1 . "
\e$B<+F0E*$K
\e(B PPP
\e$B@\B3!&@ZCG$7$^$9!#
\e(B")
303 (set-auto-ppp-2 . "
\e$B<+F0E*$K
\e(B PPP
\e$B@\B3$7$^$9!#
\e(B")
304 (set-auto-ppp-3 . "
\e$B<jF0$G
\e(B PPP
\e$B@\B3!&@ZCG$7$^$9!#
\e(B")
305 (hangup-line-1 . "
\e$B@ZCG$7$F$$$^$9
\e(B...")
306 (hangup-line-2 . "
\e$B@ZCG$7$F$$$^$9
\e(B...
\e$B40N;!#
\e(B")
307 (after-jobs-done-1 . "
\e$BA4$F$N%*%s%i%$%s=hM}$r40N;$7$^$7$?!#
\e(B")
308 (toggle-on/off-send-mail-1 . "
\e$B%a!<%k$rD>@\Aw?.$7$^$9!#
\e(B")
309 (toggle-on/off-send-mail-2 . "
\e$B%a!<%k$O%-%e!<$KAw$i$l$^$9!#
\e(B")
310 (toggle-articles-to-fetch-1 . "
\e$B<u?.$9$k%a%C%;!<%8$O
\e(B... ")
311 (toggle-articles-to-fetch-2 . "
\e$B%a!<%k$N$_$G$9!#
\e(B")
312 (toggle-articles-to-fetch-3 . "
\e$B%K%e!<%9$N$_$G$9!#
\e(B")
313 (toggle-articles-to-fetch-4 . "
\e$B%a!<%k$H%K%e!<%9$NN>J}$G$9!#
\e(B")
314 (empting-spool-1 . "
\e$B%-%e!<$N%a!<%k$rAw?.Cf
\e(B...")
315 (empting-spool-2 . "
\e$B%-%e!<$N%a!<%k$rAw?.Cf
\e(B...
\e$B40N;!#
\e(B")
316 (empting-spool-3 . "
\e$B%-%e!<$N%K%e!<%95-;v$rAw?.Cf
\e(B...")
317 (empting-spool-4 . "
\e$B%-%e!<$N%K%e!<%95-;v$rAw?.Cf
\e(B...
\e$B40N;!#
\e(B")
318 (empting-spool-5 . "
\e$B%-%e!<$N%a%C%;!<%8$rAw?.Cf
\e(B...")
319 (empting-spool-6 . "
\e$B%-%e!<$N%a%C%;!<%8$rAw?.Cf
\e(B...
\e$B40N;!#
\e(B")
320 (interval-time-1 . "
\e$BAw<u?.%8%g%V$N4V3V
\e(B (
\e$B8=:_$N@_Dj$O
\e(B %d
\e$BJ,$G$9
\e(B) : ")
321 (interval-time-2 . "
\e$B<+F0Aw<u?.5!G=$r
\e(B
\e$B%*%U
\e(B
\e$B$K$7$^$7$?!#
\e(B")
322 (interval-time-3 . "
\e$B<+F0Aw<u?.$N4V3V$r
\e(B %d
\e$BJ,$K@_Dj$7$^$7$?!#
\e(B")))
324 (defvar gnus-offline-resource-ja_complete
326 gnus-offline-resource-ja
327 '((menu-miee-1 . "Spool
\e$B$K$"$k5-;v$NAw?.
\e(B")
328 (menu-miee-2 . "Spool
\e$B$K$"$k
\e(B Mail
\e$B$NAw?.
\e(B")
329 (menu-miee-3 . "Offline
\e$B>uBV$X
\e(B")
330 (menu-miee-4 . "Online
\e$B>uBV$X
\e(B")
331 (menu-1 . "
\e$B<hF@5-;v<oN`$NJQ99
\e(B")
332 (menu-2 . "Mail
\e$BAw?.J}K!
\e(B(On/Off)
\e$B$N@ZBX$(
\e(B")
333 (menu-3 . "
\e$B<+F0
\e(B PPP
\e$B@)8f$N@_Dj
\e(B")
334 (menu-4 . "
\e$B<hF@:Q5-;v$r>C$9
\e(B")
335 (menu-5 . "
\e$B5-;v<hF@4V3V;~4V$N@_Dj
\e(B")
336 (menu-6 . "
\e$B2s@~$N@ZCG
\e(B")
337 (menu-7 . "
\e$B%W%m%Q%F%#
\e(B...")
338 (set-auto-ppp-menu-1 . "
\e$B<+F0E*$K
\e(B PPP
\e$B@\B3!&@ZCG
\e(B")
339 (set-auto-ppp-menu-2 . "
\e$B<+F0E*$K
\e(B PPP
\e$B@\B3
\e(B")
340 (set-auto-ppp-menu-3 . "
\e$B<jF0$G
\e(B PPP
\e$B@\B3!&@ZCG
\e(B"))))
345 (defsubst gnus-offline-gettext (symbol &optional lang)
346 (setq lang (or lang gnus-offline-lang))
348 (cdr (assq symbol (symbol-value
349 (intern (format "gnus-offline-resource-%s" lang)))))
350 (cdr (assq symbol gnus-offline-resource-en))))
352 (defsubst gnus-offline-set-online-sendmail-function ()
353 "*Initialize sendmail-function when plugged status."
354 (if (eq gnus-offline-MTA-type 'smtp)
355 (setq message-send-mail-function 'message-send-mail-with-smtp)
356 (setq message-send-mail-function 'message-send-mail-with-sendmail)))
358 (defsubst gnus-offline-set-offline-sendmail-function ()
359 "*Initialize sendmail-function when unplugged status."
360 (cond ((eq gnus-offline-drafts-queue-type 'miee)
361 (if (eq gnus-offline-news-fetch-method 'nnagent)
362 (setq gnus-agent-send-mail-function
363 'sendmail-to-spool-in-gnspool-format))
364 (setq message-send-mail-function 'sendmail-to-spool-in-gnspool-format))
366 (setq gnus-agent-send-mail-function
367 (gnus-offline-set-online-sendmail-function)
368 message-send-mail-function 'gnus-agent-send-mail))))
370 (defsubst gnus-offline-set-offline-post-news-function ()
371 "*Initialize sendnews-function when unplugged status."
372 (if (eq gnus-offline-drafts-queue-type 'miee)
373 (setq message-send-news-function 'gnspool-request-post)))
375 (defsubst gnus-offline-set-online-post-news-function ()
376 "*Initialize sendnews-function when plugged status."
377 (setq message-send-news-function 'message-send-news-with-gnus))
379 (defsubst gnus-offline-disable-fetch-mail ()
380 "*Set do not fetch mail."
381 (setq mail-sources nil
382 nnmail-spool-file nil))
384 (defsubst gnus-offline-enable-fetch-mail ()
385 "*Set to fetch mail."
386 (setq gnus-offline-mail-fetch-method 'nnmail)
387 (setq mail-sources gnus-offline-mail-source))
389 (defsubst gnus-offline-enable-fetch-news ()
390 "*Set to fetch news."
391 (if (eq gnus-offline-news-fetch-method 'nnagent)
393 (setq gnus-agent-handle-level gnus-level-subscribed)
394 (gnus-agent-toggle-plugged t))))
396 ;; Advice to Gnus functions.
397 (defadvice gnus-group-get-new-news (before gnus-offline-advice
398 activate preactivate)
399 "When called interactively, dial up and get online automatically."
400 (when (interactive-p)
401 (run-hooks 'gnus-offline-before-online-hook)
402 (if (and (memq 'connect gnus-offline-auto-ppp)
403 (functionp gnus-offline-dialup-function))
404 (funcall gnus-offline-dialup-function))
405 (gnus-offline-get-new-news-function)))
407 (defadvice gnus-agent-toggle-plugged (around gnus-offline-advice
408 activate preactivate)
409 "Also toggle gnus-offline `connected--disconnected' status."
410 (interactive (list (not gnus-offline-connected)))
411 (cond ((ad-get-arg 0)
412 (setq gnus-offline-connected (ad-get-arg 0))
414 ;; Set send mail/news function to offline functions.
415 (gnus-offline-set-online-sendmail-function)
416 (gnus-offline-set-online-post-news-function))
418 ;; Set to offline status
419 (gnus-offline-set-unplugged-state))))
421 (defadvice gnus-agent-expire (around gnus-offline-advice activate preactivate)
422 "Advice not to delete new articles."
423 (cond ((eq 0 gnus-agent-expire-days)
424 (let (gnus-agent-expire-all)
432 (defun gnus-offline-setup ()
433 "*Initialize gnus-offline function"
435 (when (eq gnus-offline-drafts-queue-type 'agent)
436 (setq gnus-offline-connected gnus-plugged))
438 (gnus-offline-processed-by-timer)
439 (gnus-offline-error-check)
441 ;; To transfer Mail/News function.
442 (cond ((or (and (eq 'gnus-offline-drafts-queue-type 'agent)
443 gnus-offline-connected)
444 (eq gnus-offline-mail-treat-environ 'online))
445 ;; send mail under offline environ.
446 (gnus-offline-set-online-sendmail-function))
448 ;; send mail under offline environ.
449 (gnus-offline-set-offline-sendmail-function))))
452 ;; Setting Error check.
453 (defun gnus-offline-error-check ()
454 ;; Check gnus-agent and nnspool setting.
455 (let ((buffer " *Offline Error*"))
456 (cond ((eq gnus-offline-news-fetch-method 'nnagent)
457 ;; nnagent and gnus-agent loaded ??
458 (unless (and (featurep 'gnus-agent)
460 (set-buffer (gnus-get-buffer-create buffer))
462 (insert (gnus-offline-gettext 'error-check-1))
463 (pop-to-buffer buffer)))
465 ((eq gnus-offline-news-fetch-method 'nnspool)
466 (unless (featurep 'nnspool)
467 (set-buffer (gnus-get-buffer-create buffer))
469 (insert (gnus-offline-gettext 'error-check-2))
470 (pop-to-buffer buffer)))
477 (defun gnus-offline-connect-server ()
479 ;; Dialup if gnus-offline-dialup-program is specified
480 (if (stringp gnus-offline-dialup-program)
482 (message (gnus-offline-gettext 'connect-server-1))
483 (apply 'call-process gnus-offline-dialup-program nil nil nil
484 gnus-offline-dialup-program-arguments)
486 (message (gnus-offline-gettext 'connect-server-2)))))
489 ;; Jobs before get new news , send mail and post news.
491 (defun gnus-offline-get-new-news-function ()
492 "*Prepare to get new news/mail."
493 ;; Set mail group level
494 (if (eq gnus-offline-articles-to-fetch 'mail)
495 (gnus-offline-set-mail-group-level gnus-offline-mail-group-level))
497 ;; Set to online environ.
498 (setq gnus-offline-connected t)
500 ;; Set send mail/news functions to online functions.
501 (gnus-offline-set-online-sendmail-function)
502 (gnus-offline-set-online-post-news-function)
503 (message (gnus-offline-gettext 'get-new-news-function-1))
506 (if (eq gnus-offline-articles-to-fetch 'news)
507 (gnus-offline-disable-fetch-mail))
509 ;; fetch both mail and news. or Only mail.
510 (gnus-offline-enable-fetch-news)
511 (if (memq gnus-offline-articles-to-fetch '(both mail))
512 (gnus-offline-enable-fetch-mail))
514 ;; fetch only mail for gnus-agent
515 (if (and (eq gnus-offline-news-fetch-method 'nnagent)
516 (eq gnus-offline-articles-to-fetch 'mail))
517 (setq gnus-agent-handle-level gnus-offline-mail-group-level)))
520 ;; Change mail group level to handle only mail.
522 (defun gnus-offline-set-mail-group-level (level)
523 "*Set nnm* group level."
524 (switch-to-buffer gnus-group-buffer)
525 (goto-char (point-min))
527 ;; Save current level
528 (if (not gnus-offline-stored-group-level)
529 (while (re-search-forward " nnm" nil t)
530 (setq gnus-offline-stored-group-level
531 (append gnus-offline-stored-group-level
532 (list (gnus-group-group-level)))))
536 (goto-char (point-min))
537 (while (re-search-forward " nnm" nil t)
538 (gnus-group-set-current-level 1 level)
543 ;; Restore mail group level
545 (defun gnus-offline-restore-mail-group-level ()
546 "*Restore nnm* group level."
547 (switch-to-buffer gnus-group-buffer)
548 (goto-char (point-min))
550 (while (re-search-forward " nnm" nil t)
551 (gnus-group-set-current-level 1 (nth num gnus-offline-stored-group-level))
554 (beginning-of-line))))
556 ;; Jobs after getting new news.
558 (defun gnus-offline-after-get-new-news ()
559 "*After getting news and mail jobs."
560 (cond (gnus-offline-connected
561 (when (memq gnus-offline-articles-to-fetch '(both mail))
563 ;; send mail/news in spool
564 (gnus-offline-empting-spool)
565 (when (eq gnus-offline-articles-to-fetch 'mail)
566 ;; Send only mail and hang up...
567 (if gnus-offline-connected
568 (gnus-offline-set-unplugged-state))
569 ;; Disable fetch mail.
570 (gnus-offline-disable-fetch-mail)
571 (gnus-offline-after-jobs-done)))
572 (when (memq gnus-offline-articles-to-fetch '(both news))
574 (cond ((eq gnus-offline-news-fetch-method 'nnagent)
575 ;; Get New News (gnus-agent)
576 (gnus-agent-toggle-plugged t)
578 (gnus-agent-fetch-session)
579 ;; Hang Up line. then set to offline status.
580 (gnus-offline-set-unplugged-state)
581 ;; All online jobs has done.
582 (gnus-offline-after-jobs-done))
584 (if (eq gnus-offline-news-fetch-method 'nnspool)
585 ;; Get New News (nnspool)
586 (gnspool-get-news))))))
591 ;; Add your custom header.
593 (defun gnus-offline-add-custom-header (header string)
594 "*Add X-Gnus-Offline-Backend header to Mail/News message."
596 (progn (goto-char (point-min))
598 (concat "^" (regexp-quote mail-header-separator) "\n"))
601 (goto-char (point-min))
602 (unless (re-search-forward (concat "^" header) delimline t)
603 (goto-char delimline)
606 (setq hdr (concat header " "))
607 (setq str (concat hdr string))
608 (setq hdr (concat str "\n"))
609 (insert-string hdr))))
611 ;; Add X-Offline-Backend header.
613 (defun gnus-offline-message-add-header ()
614 "*Add X-Gnus-Offline-Backend header to Mail/News message."
615 (when (eq gnus-offline-mail-treat-environ 'offline)
616 (let* ((ver (if (eq gnus-offline-news-fetch-method 'nnagent)
619 (str (format "\n with %s" ver)))
620 (gnus-offline-add-custom-header
621 "X-Gnus-Offline-Backend:" (concat gnus-offline-header-string str)))))
625 ;; Function of hang up line.
627 (defun gnus-offline-set-unplugged-state ()
628 "*Set to unplugged state."
631 (if (and (memq 'disconnect gnus-offline-auto-ppp)
632 (functionp gnus-offline-hangup-function))
633 (funcall gnus-offline-hangup-function))
634 (setq gnus-offline-connected nil)
635 (if (eq gnus-offline-news-fetch-method 'nnagent)
636 (ad-Orig-gnus-agent-toggle-plugged nil))
638 ;; Set send mail/news function to offline functions.
639 (gnus-offline-set-offline-sendmail-function)
640 (gnus-offline-set-offline-post-news-function)
642 (setenv "MAILHOST" nil))
644 ;; Hangup line function
646 (defun gnus-offline-hangup-line ()
647 "*Hangup line function."
648 (message (gnus-offline-gettext 'hangup-line-1))
649 (if (stringp gnus-offline-hangup-program)
650 (apply 'start-process "hup" nil gnus-offline-hangup-program
651 gnus-offline-hangup-program-arguments))
652 (message (gnus-offline-gettext 'hangup-line-2)))
654 ;; Hang Up line routine whe using nnspool
656 (defun gnus-offline-nnspool-hangup-line ()
657 (if gnus-offline-connected
658 (gnus-offline-set-unplugged-state))
659 (gnus-offline-after-jobs-done))
661 ;; Function of all jobs has done.
663 (defun gnus-offline-after-jobs-done ()
664 "*Jobs after all online jobs."
665 (run-hooks 'gnus-offline-after-online-hook)
666 (if (eq gnus-offline-articles-to-fetch 'mail)
667 (gnus-offline-restore-mail-group-level))
668 (if (and (eq gnus-offline-news-fetch-method 'nnagent)
669 gnus-offline-auto-expire)
671 (if (and (featurep 'xemacs)
672 (fboundp 'play-sound-file))
675 (gnus-group-save-newsrc)
676 (message (gnus-offline-gettext 'after-jobs-done-1)))
682 (defun gnus-offline-set-auto-ppp ()
683 "*Decide whether to connect and/or disconnect automatically."
685 (let ((keys (key-description (this-command-keys)))
687 (cond ((or (string= "misc-user" keys)
688 (string= "S-mouse-2" keys)
689 (string-match "^menu-bar" keys)
690 (string-match "^mouse" keys))
691 (setq title (gnus-offline-gettext 'menu-3))
694 (gnus-offline-get-menu-items
695 '((set-auto-ppp-menu-1
697 (setq gnus-offline-auto-ppp '(connect disconnect))
698 (message (gnus-offline-gettext 'set-auto-ppp-1)))
702 (setq gnus-offline-auto-ppp '(connect))
703 (message (gnus-offline-gettext 'set-auto-ppp-2)))
707 (setq gnus-offline-auto-ppp nil)
708 (message (gnus-offline-gettext 'set-auto-ppp-3)))
710 (gnus-offline-popup menu title))
712 (cond ((eq gnus-offline-auto-ppp nil)
713 (setq gnus-offline-auto-ppp '(connect disconnect))
714 (setq str (gnus-offline-gettext 'set-auto-ppp-1)))
715 ((memq 'connect gnus-offline-auto-ppp)
716 (cond ((memq 'disconnect gnus-offline-auto-ppp)
717 (setq gnus-offline-auto-ppp '(connect))
719 (gnus-offline-gettext 'set-auto-ppp-2)))
721 (setq gnus-offline-auto-ppp nil)
723 (gnus-offline-gettext 'set-auto-ppp-3))))))
726 ;; Toggle offline/online to send mail.
728 (defun gnus-offline-toggle-on/off-send-mail ()
729 "*Toggel online/offline sendmail."
731 (if (eq gnus-offline-mail-treat-environ 'offline)
733 ;; Sending mail under online environ.
734 (gnus-offline-set-online-sendmail-function)
735 (setq gnus-offline-mail-treat-environ 'online)
736 (message (gnus-offline-gettext 'toggle-on/off-send-mail-1)))
737 ;; Sending mail under offline environ.
738 (gnus-offline-set-offline-sendmail-function)
739 (setq gnus-offline-mail-treat-environ 'offline)
740 (message (gnus-offline-gettext 'toggle-on/off-send-mail-2))))
742 ;; Toggle articles to fetch ... both -> mail -> news -> both
744 (defun gnus-offline-toggle-articles-to-fetch ()
745 "*Set articles to fetch... both(Mail/News) -> mail only -> News only -> both"
747 (let ((string (gnus-offline-gettext 'toggle-articles-to-fetch-1))
749 (cond ((eq gnus-offline-articles-to-fetch 'both)
750 (setq gnus-offline-articles-to-fetch 'mail
751 str (gnus-offline-gettext 'toggle-articles-to-fetch-2)))
752 ((eq gnus-offline-articles-to-fetch 'mail)
753 (setq gnus-offline-articles-to-fetch 'news
754 str (gnus-offline-gettext 'toggle-articles-to-fetch-3)))
756 (setq gnus-offline-articles-to-fetch 'both
757 str (gnus-offline-gettext 'toggle-articles-to-fetch-4))))
758 (message (format "%s %s" string str))))
760 ;; Send mail and Post news using Miee or gnus-agent.
762 (defun gnus-offline-empting-spool ()
763 "*Send all drafts on queue."
764 (run-hooks 'gnus-offline-before-empting-spool-hook)
765 (if (eq gnus-offline-drafts-queue-type 'miee)
766 ;; Send queued message by miee.el.
768 (if (eq gnus-offline-mail-treat-environ 'offline)
770 (message (gnus-offline-gettext 'empting-spool-1))
771 ;; Using miee to send mail.
773 (message (gnus-offline-gettext 'empting-spool-2))))
774 (message (gnus-offline-gettext 'empting-spool-3))
775 ;; Using miee to post news.
776 (if (and (not (stringp msspool-news-server))
777 (not msspool-news-service))
779 (setq msspool-news-server (nth 1 gnus-select-method))
780 (setq msspool-news-service 119)))
782 (message (gnus-offline-gettext 'empting-spool-4)))
783 ;; Send queued message by gnus-agent
784 (message (gnus-offline-gettext 'empting-spool-5))
785 (gnus-group-send-drafts)
786 (message (gnus-offline-gettext 'empting-spool-6)))
788 (run-hooks 'gnus-offline-after-empting-spool-hook))
792 (defun gnus-offline-set-interval-time ()
793 "*Set interval time for gnus-daemon."
795 (setq gnus-offline-interval-time
796 (string-to-int (read-from-minibuffer
797 (format (gnus-offline-gettext 'interval-time-1)
798 gnus-offline-interval-time)
800 (if (< gnus-offline-interval-time 2)
802 (message (gnus-offline-gettext 'interval-time-2))
803 (setq gnus-offline-interval-time 0))
805 (format (gnus-offline-gettext 'interval-time-3)
806 gnus-offline-interval-time)))
807 (gnus-offline-processed-by-timer))
812 (defun gnus-offline-define-menu-and-key ()
814 (cond ((eq gnus-offline-drafts-queue-type 'miee)
817 (add-hook 'gnus-group-mode-hook 'gnus-offline-define-menu-on-miee))
819 (gnus-offline-define-menu-on-miee))))
821 (add-hook 'gnus-group-mode-hook 'gnus-offline-define-menu-on-agent)))
823 (add-hook 'gnus-group-mode-hook
825 (local-set-key "\C-coh" 'gnus-offline-set-unplugged-state)
826 (local-set-key "\C-cof" 'gnus-offline-toggle-articles-to-fetch)
827 (local-set-key "\C-coo" 'gnus-offline-toggle-on/off-send-mail)
828 (local-set-key "\C-cox" 'gnus-offline-set-auto-ppp)
829 (local-set-key "\C-cos" 'gnus-offline-set-interval-time)
830 (if (eq gnus-offline-news-fetch-method 'nnagent)
831 (local-set-key "\C-coe" 'gnus-agent-expire))
832 (static-unless (featurep 'xemacs)
834 (if (eq system-type 'windows-nt) [S-mouse-2] [mouse-3])
835 'gnus-offline-popup-menu)))))
839 (defun gnus-offline-popup (menu &optional title)
844 (let ((menu-func (or (and (fboundp 'easy-menu-create-menu)
845 'easy-menu-create-menu)
846 'easy-menu-create-keymaps))
848 (static-cond ((< emacs-major-version 20)
849 ;; For Emacsen from 19.34 down to 19.28.
850 ;; Seems the first item in MENU will be ignored.
853 (append (list "" ;; This will be ignored.
854 (or title "Popup Menu")
860 (append (list 'keymap
867 (funcall menu-func (car menu) (cdr menu)))))
872 (funcall menu-func (car menu) (cdr menu))))))
873 ;; Display the popup menu.
874 (if (and (setq pop (x-popup-menu t keymap))
875 (setq func (lookup-key keymap
876 (apply 'vector pop))))
879 (defun gnus-offline-get-menu-items (list)
884 (cons (gnus-offline-gettext (car el)) (cdr el)))
888 (defvar gnus-offline-menu
889 (gnus-offline-get-menu-items
890 '((menu-1 gnus-offline-toggle-articles-to-fetch t)
891 (menu-2 gnus-offline-toggle-on/off-send-mail t)
892 (menu-3 gnus-offline-set-auto-ppp t)
894 (menu-4 gnus-agent-expire
895 (eq gnus-offline-news-fetch-method 'nnagent))
896 (menu-5 gnus-offline-set-interval-time t)
898 (menu-6 gnus-offline-set-unplugged-state gnus-offline-connected)
900 (menu-7 gnus-ofsetup-customize t))))
902 (defun gnus-offline-define-menu-on-miee ()
903 "*Set and change menu bar on MIEE menu."
905 (gnus-offline-get-menu-items
906 '((menu-miee-1 news-spool-post t)
907 (menu-miee-2 mail-spool-send t)
909 (menu-miee-3 message-offline-state (not message-offline-state))
910 (menu-miee-4 message-online-state message-offline-state)
917 (list (cons "Gnus Offline" gnus-offline-menu)))))
918 (static-if (featurep 'xemacs)
919 (easy-menu-add menu))))
921 ;; define menu without miee.
923 (defun gnus-offline-define-menu-on-agent ()
924 "*Set menu bar on OFFLINE menu."
926 gnus-offline-menu-on-agent gnus-group-mode-map "Gnus offline Menu"
927 (cons "Offline" gnus-offline-menu))
928 (static-if (featurep 'xemacs)
929 (easy-menu-add gnus-offline-menu-on-agent)))
931 ;; Popup menu within the group buffer (under Emacs).
933 (static-unless (featurep 'xemacs)
934 (defun gnus-offline-popup-menu (event)
935 "Popup menu for Gnus Offline."
937 (apply 'gnus-offline-popup
938 (if (boundp 'miee-popup-menu)
939 (list (or (assq 'keymap
940 (assq 'Miee (assq 'menu-bar global-map)))
943 (list (symbol-value 'gnus-offline-menu-on-agent)
948 (defun gnus-offline-processed-by-timer ()
949 "*Set timer interval."
950 (let ((func (lambda () (call-interactively 'gnus-group-get-new-news)))
951 (time gnus-offline-interval-time))
952 (cond ((and (> time 0) (not gnus-offline-connected))
954 (gnus-demon-add-handler func time time))
955 ((= gnus-offline-interval-time 0)
956 (gnus-demon-remove-handler func t)))))
958 ;; Code for making Gnus and Gnus Offline cooperate with each other.
961 ;; Display `X-Gnus-Offline-Backend' message header aesthetically.
962 (eval-after-load "eword-decode"
963 '(mime-set-field-decoder 'X-Gnus-Offline-Backend nil nil))
965 ;; Enable key and menu definitions here.
966 (eval '(funcall 'gnus-offline-define-menu-and-key))
970 ;;; gnus-offline.el ends here