* Makefile.in (install-package-ja): Compile and install lisp files first.
[elisp/gnus.git-] / lisp / gnus-offline.el
index 5917a64..63e6c74 100644 (file)
@@ -78,6 +78,8 @@
 (eval '(run-hooks 'gnus-offline-load-hook))
 
 (eval-when-compile (require 'cl))
+(eval-when-compile (require 'gnus-clfns))
+
 (eval-when-compile
   (require 'static)
   (require 'gnus-agent)
      miee-popup-menu
      gnus-group-toolbar)))
 
-(if (eq system-type 'windows-nt)
+(if (featurep 'meadow)
     (define-process-argument-editing "/hang\\.exe\\'"
       (lambda (x)
        (general-process-argument-editing-function
@@ -190,7 +192,7 @@ If mail , gnus-offline only fetch mail articles.
   :group 'gnus-offline
   :type 'function)
 
-(defcustom gnus-offline-agent-automatic-expire t
+(defcustom gnus-offline-auto-expire t
   "*Non-nil means expire articles on every session."
   :group 'gnus-offline
   :type 'boolean)
@@ -393,38 +395,44 @@ Please check your .emacs or .gnus.el to work nnspool fine.")
        (setq gnus-agent-handle-level gnus-level-subscribed)
        (gnus-agent-toggle-plugged t))))
 
-;; Advice to Gnus functions.
-(defadvice gnus-group-get-new-news (before gnus-offline-advice
-                                          activate preactivate)
-  "When called interactively, dial up and get online automatically."
-  (when (interactive-p)
-    (run-hooks 'gnus-offline-before-online-hook)
-    (if (and (memq 'connect gnus-offline-auto-ppp)
-            (functionp gnus-offline-dialup-function))
-       (funcall gnus-offline-dialup-function))
-    (gnus-offline-get-new-news-function)))
-
-(defadvice gnus-agent-toggle-plugged (around gnus-offline-advice
+(when (featurep 'gnus-ofsetup)
+  ;; Advice to Gnus functions.
+  (defadvice gnus-group-get-new-news (before gnus-offline-advice
                                             activate preactivate)
-  "Also toggle gnus-offline `connected--disconnected' status."
-  (interactive (list (not gnus-offline-connected)))
-  (cond ((ad-get-arg 0)
-        (setq gnus-offline-connected (ad-get-arg 0))
-        ad-do-it
-        ;; Set send mail/news function to offline functions.
-        (gnus-offline-set-online-sendmail-function)
-        (gnus-offline-set-online-post-news-function))
-       (t
-        ;; Set to offline status
-        (gnus-offline-set-unplugged-state))))
+    "When called interactively, dial up and get online automatically."
+    (when (interactive-p)
+      (run-hooks 'gnus-offline-before-online-hook)
+      (if (and (memq 'connect gnus-offline-auto-ppp)
+              (functionp gnus-offline-dialup-function))
+         (funcall gnus-offline-dialup-function))
+      (gnus-offline-get-new-news-function)))
+
+  (defadvice gnus-agent-toggle-plugged (around gnus-offline-advice
+                                              activate preactivate)
+    "Also toggle gnus-offline `connected--disconnected' status."
+    (interactive (list (not gnus-offline-connected)))
+    (cond ((ad-get-arg 0)
+          (setq gnus-offline-connected (ad-get-arg 0))
+          ad-do-it
+          ;; Set send mail/news function to offline functions.
+          (gnus-offline-set-online-sendmail-function)
+          (gnus-offline-set-online-post-news-function))
+         (t
+          ;; Set to offline status
+          (gnus-offline-set-unplugged-state))))
 
-(defadvice gnus-agent-expire (around gnus-offline-advice activate preactivate)
-  "Advice not to delete new articles."
-  (and gnus-offline-agent-automatic-expire
-       (if (eq 0 gnus-agent-expire-days)
+  (defadvice gnus-agent-expire (around gnus-offline-advice activate preactivate)
+    "Advice not to delete new articles."
+    (cond ((eq 0 gnus-agent-expire-days)
           (let (gnus-agent-expire-all)
-            ad-do-it)
-        ad-do-it)))
+            ad-do-it))
+         (t
+          ad-do-it)))
+
+  (defadvice gnus-agent-mode (around gnus-offline-advice activate preactivate)
+    "Advice not to close PPP connection."
+    (let (gnus-offline-hangup-function)
+      ad-do-it)))
 
 ;;
 ;; Setting up...
@@ -479,11 +487,11 @@ Please check your .emacs or .gnus.el to work nnspool fine.")
   ;; Dialup if gnus-offline-dialup-program is specified
   (if (stringp gnus-offline-dialup-program)
       (progn
-       (message (gnus-offline-gettext 'connect-server-1))
+       (message "%s" (gnus-offline-gettext 'connect-server-1))
        (apply 'call-process gnus-offline-dialup-program nil nil nil
               gnus-offline-dialup-program-arguments)
        (sleep-for 1)
-       (message (gnus-offline-gettext 'connect-server-2)))))
+       (message "%s" (gnus-offline-gettext 'connect-server-2)))))
 
 ;;
 ;; Jobs before get new news , send mail and post news.
@@ -500,7 +508,7 @@ Please check your .emacs or .gnus.el to work nnspool fine.")
   ;; Set send mail/news functions to online functions.
   (gnus-offline-set-online-sendmail-function)
   (gnus-offline-set-online-post-news-function)
-  (message (gnus-offline-gettext 'get-new-news-function-1))
+  (message "%s" (gnus-offline-gettext 'get-new-news-function-1))
 
   ;; fetch only news
   (if (eq gnus-offline-articles-to-fetch 'news)
@@ -557,38 +565,35 @@ Please check your .emacs or .gnus.el to work nnspool fine.")
 ;;
 (defun gnus-offline-after-get-new-news ()
   "*After getting news and mail jobs."
-  (when gnus-plugged
-    (if (memq gnus-offline-articles-to-fetch '(both mail))
-       (progn
-         ;; Mail/both
-         ;; send mail/news in spool
-         (gnus-offline-empting-spool)
-         (if (eq gnus-offline-articles-to-fetch 'mail)
-             (progn
-               ;; Send only mail and hang up...
-               (if gnus-offline-connected
-                   (gnus-offline-set-unplugged-state))
-               ;; Disable fetch mail.
-               (gnus-offline-disable-fetch-mail)
-               (gnus-offline-after-jobs-done)))))
-
-    ;; News/Both
-    (if (memq gnus-offline-articles-to-fetch '(both news))
-       (progn
-         (if gnus-offline-connected
-             (cond ((eq gnus-offline-news-fetch-method 'nnagent)
-                    ;; Get New News (gnus-agent)
-                    (gnus-agent-toggle-plugged t)
-                    ;; fetch articles
-                    (gnus-agent-fetch-session)
-                    ;; Hang Up line. then set to offline status.
-                    (gnus-offline-set-unplugged-state)
-                    ;; All online jobs has done.
-                    (gnus-offline-after-jobs-done))
-                   (t
-                    (if (eq gnus-offline-news-fetch-method 'nnspool)
-                        ;; Get New News (nnspool)
-                        (gnspool-get-news)))))))))
+  (cond (gnus-offline-connected
+        (when (memq gnus-offline-articles-to-fetch '(both mail))
+          ;; Mail/both
+          ;; send mail/news in spool
+          (gnus-offline-empting-spool)
+          (when (eq gnus-offline-articles-to-fetch 'mail)
+            ;; Send only mail and hang up...
+            (if gnus-offline-connected
+                (gnus-offline-set-unplugged-state))
+            ;; Disable fetch mail.
+            (gnus-offline-disable-fetch-mail)
+            (gnus-offline-after-jobs-done)))
+        (when (memq gnus-offline-articles-to-fetch '(both news))
+          ;; News/Both
+          (cond ((eq gnus-offline-news-fetch-method 'nnagent)
+                 ;; Get New News (gnus-agent)
+                 (gnus-agent-toggle-plugged t)
+                 ;; fetch articles
+                 (gnus-agent-fetch-session)
+                 ;; Hang Up line. then set to offline status.
+                 (gnus-offline-set-unplugged-state)
+                 ;; All online jobs has done.
+                 (gnus-offline-after-jobs-done))
+                (t
+                 (if (eq gnus-offline-news-fetch-method 'nnspool)
+                     ;; Get New News (nnspool)
+                     (gnspool-get-news))))))
+       (t
+        nil)))
 \f
 ;;
 ;; Add your custom header.
@@ -648,11 +653,11 @@ Please check your .emacs or .gnus.el to work nnspool fine.")
 ;;
 (defun gnus-offline-hangup-line ()
   "*Hangup line function."
-  (message (gnus-offline-gettext 'hangup-line-1))
+  (message "%s" (gnus-offline-gettext 'hangup-line-1))
   (if (stringp gnus-offline-hangup-program)
       (apply 'start-process "hup" nil gnus-offline-hangup-program
             gnus-offline-hangup-program-arguments))
-  (message (gnus-offline-gettext 'hangup-line-2)))
+  (message "%s" (gnus-offline-gettext 'hangup-line-2)))
 ;;
 ;; Hang Up line routine whe using nnspool
 ;;
@@ -668,14 +673,16 @@ Please check your .emacs or .gnus.el to work nnspool fine.")
   (run-hooks 'gnus-offline-after-online-hook)
   (if (eq gnus-offline-articles-to-fetch 'mail)
       (gnus-offline-restore-mail-group-level))
-  (if (eq gnus-offline-news-fetch-method 'nnagent)
+  (if (and (eq gnus-offline-news-fetch-method 'nnagent)
+          gnus-offline-auto-expire)
       (gnus-agent-expire))
-  (if (and (featurep 'xemacs)
-          (fboundp 'play-sound-file))
-      (ding nil 'drum)
+  (static-if (featurep 'xemacs)
+      (if (fboundp 'play-sound-file)
+         (ding nil 'drum)
+       (ding))
     (ding))
   (gnus-group-save-newsrc)
-  (message (gnus-offline-gettext 'after-jobs-done-1)))
+  (message "%s" (gnus-offline-gettext 'after-jobs-done-1)))
 
 \f
 ;;
@@ -687,6 +694,7 @@ Please check your .emacs or .gnus.el to work nnspool fine.")
   (let ((keys (key-description (this-command-keys)))
        menu title str)
     (cond ((or (string= "misc-user" keys)
+              (string= "S-mouse-2" keys)
               (string-match "^menu-bar" keys)
               (string-match "^mouse" keys))
           (setq title (gnus-offline-gettext 'menu-3))
@@ -696,17 +704,20 @@ Please check your .emacs or .gnus.el to work nnspool fine.")
                        '((set-auto-ppp-menu-1
                           (progn
                             (setq gnus-offline-auto-ppp '(connect disconnect))
-                            (message (gnus-offline-gettext 'set-auto-ppp-1)))
+                            (message "%s"
+                                     (gnus-offline-gettext 'set-auto-ppp-1)))
                           t)
                          (set-auto-ppp-menu-2
                           (progn
                             (setq gnus-offline-auto-ppp '(connect))
-                            (message (gnus-offline-gettext 'set-auto-ppp-2)))
+                            (message "%s"
+                                     (gnus-offline-gettext 'set-auto-ppp-2)))
                           t)
                          (set-auto-ppp-menu-3
                           (progn
                             (setq gnus-offline-auto-ppp nil)
-                            (message (gnus-offline-gettext 'set-auto-ppp-3)))
+                            (message "%s"
+                                     (gnus-offline-gettext 'set-auto-ppp-3)))
                           t)))))
           (gnus-offline-popup menu title))
          (t
@@ -722,7 +733,7 @@ Please check your .emacs or .gnus.el to work nnspool fine.")
                         (setq gnus-offline-auto-ppp nil)
                         (setq str
                               (gnus-offline-gettext 'set-auto-ppp-3))))))
-          (message str)))))
+          (message "%s" str)))))
 ;;
 ;; Toggle offline/online to send mail.
 ;;
@@ -734,11 +745,11 @@ Please check your .emacs or .gnus.el to work nnspool fine.")
        ;; Sending mail under online environ.
        (gnus-offline-set-online-sendmail-function)
        (setq gnus-offline-mail-treat-environ 'online)
-       (message (gnus-offline-gettext 'toggle-on/off-send-mail-1)))
+       (message "%s" (gnus-offline-gettext 'toggle-on/off-send-mail-1)))
     ;; Sending mail under offline environ.
     (gnus-offline-set-offline-sendmail-function)
     (setq gnus-offline-mail-treat-environ 'offline)
-    (message (gnus-offline-gettext 'toggle-on/off-send-mail-2))))
+    (message "%s" (gnus-offline-gettext 'toggle-on/off-send-mail-2))))
 ;;
 ;; Toggle articles to fetch ... both -> mail -> news -> both
 ;;
@@ -756,7 +767,7 @@ Please check your .emacs or .gnus.el to work nnspool fine.")
          (t
           (setq gnus-offline-articles-to-fetch 'both
                 str (gnus-offline-gettext 'toggle-articles-to-fetch-4))))
-    (message (format "%s %s" string str))))
+    (message "%s %s" string str)))
 ;;
 ;; Send mail and Post news using Miee or gnus-agent.
 ;;
@@ -768,11 +779,11 @@ Please check your .emacs or .gnus.el to work nnspool fine.")
       (progn
        (if (eq gnus-offline-mail-treat-environ 'offline)
            (progn
-             (message (gnus-offline-gettext 'empting-spool-1))
+             (message "%s" (gnus-offline-gettext 'empting-spool-1))
              ;; Using miee to send mail.
              (mail-spool-send)
-             (message (gnus-offline-gettext 'empting-spool-2))))
-       (message (gnus-offline-gettext 'empting-spool-3))
+             (message "%s" (gnus-offline-gettext 'empting-spool-2))))
+       (message "%s" (gnus-offline-gettext 'empting-spool-3))
        ;; Using miee to post news.
        (if (and (not (stringp msspool-news-server))
                 (not msspool-news-service))
@@ -780,11 +791,11 @@ Please check your .emacs or .gnus.el to work nnspool fine.")
              (setq msspool-news-server (nth 1 gnus-select-method))
              (setq msspool-news-service 119)))
        (news-spool-post)
-       (message (gnus-offline-gettext 'empting-spool-4)))
+       (message "%s" (gnus-offline-gettext 'empting-spool-4)))
     ;; Send queued message by gnus-agent
-    (message (gnus-offline-gettext 'empting-spool-5))
+    (message "%s" (gnus-offline-gettext 'empting-spool-5))
     (gnus-group-send-drafts)
-    (message (gnus-offline-gettext 'empting-spool-6)))
+    (message "%s" (gnus-offline-gettext 'empting-spool-6)))
   ;;
   (run-hooks 'gnus-offline-after-empting-spool-hook))
 ;;
@@ -800,7 +811,7 @@ Please check your .emacs or .gnus.el to work nnspool fine.")
                        nil)))
   (if (< gnus-offline-interval-time 2)
       (progn
-       (message (gnus-offline-gettext 'interval-time-2))
+       (message "%s" (gnus-offline-gettext 'interval-time-2))
        (setq gnus-offline-interval-time 0))
     (message
      (format (gnus-offline-gettext 'interval-time-3)