tm 7.19.
[elisp/tm.git] / gnus / tm-gnus4.el
1 ;;;
2 ;;; tm-gnus4.el --- tm-gnus module for GNUS 4.*
3 ;;;
4
5 (require 'tl-str)
6 (require 'tl-misc)
7 (require 'tm-ognus)
8
9
10 ;;; @ version
11 ;;;
12
13 (defconst tm-gnus/RCS-ID
14   "$Id: tm-gnus4.el,v 7.0 1995/10/22 12:12:56 morioka Exp $")
15
16 (defconst tm-gnus/version
17   (concat (get-version-string tm-gnus/RCS-ID) " for GNUS 4"))
18
19
20 ;;; @ for tm-view
21 ;;;
22
23 (autoload 'mime/viewer-mode "tm-view" "View MIME message." t)
24
25 (defun tm-gnus/view-message (arg)
26   "MIME decode and play this message."
27   (interactive "P")
28   (let ((gnus-break-pages nil))
29     (gnus-summary-select-article t t)
30     )
31   (pop-to-buffer gnus-article-buffer t)
32   (mime/viewer-mode)
33   )
34
35 (defun tm-gnus/summary-scroll-down ()
36   "Scroll down one line current article."
37   (interactive)
38   (gnus-summary-scroll-up -1)
39   )
40
41 (defun mime-viewer/quitting-method-for-gnus4 ()
42   (mime-viewer/kill-buffer)
43   (delete-other-windows)
44   (gnus-article-show-summary)
45   (if (null gnus-have-all-headers)
46       (gnus-summary-select-article nil t)
47     ))
48
49 (call-after-loaded
50  'tm-view
51  (function
52   (lambda ()
53     (set-alist 'mime-viewer/quitting-method-alist
54                'gnus-article-mode
55                (function mime-viewer/quitting-method-for-gnus4))
56     )))
57
58
59 ;;; @ for tm-partial
60 ;;;
61
62 (call-after-loaded
63  'tm-partial
64  (function
65   (lambda ()
66     (set-atype 'mime/content-decoding-condition
67                '((type . "message/partial")
68                  (method . mime-article/grab-message/partials)
69                  (major-mode . gnus-article-mode)
70                  (summary-buffer-exp . gnus-summary-buffer)
71                  ))
72     
73     (set-alist 'tm-partial/preview-article-method-alist
74                'gnus-article-mode
75                (function
76                 (lambda ()
77                   (tm-gnus/view-message (gnus-summary-article-number))
78                   )))
79     )))
80
81
82 ;;; @ Summary decoding
83 ;;;
84
85 (add-hook 'gnus-select-group-hook (function tm-gnus/decode-summary-subjects))
86
87
88 ;;; @ set up
89 ;;;
90
91 (define-key gnus-summary-mode-map
92   "\et" (function tm-gnus/toggle-decoding-mode))
93 (define-key gnus-summary-mode-map "v" (function tm-gnus/view-message))
94 (define-key gnus-summary-mode-map
95   "\e\r" (function tm-gnus/summary-scroll-down))
96
97 (fset 'gnus-article-set-mode-line 'tm-gnus/article-set-mode-line)
98 (add-hook 'gnus-article-mode-hook
99           (function tm-gnus/add-decoding-mode-to-mode-line))
100
101 (defun tm-gnus/decode-encoded-word-if-you-need ()
102   (if (and tm-gnus/decoding-mode (not gnus-have-all-headers))
103       (mime/decode-message-header)
104     ))
105
106 (add-hook 'gnus-article-prepare-hook
107           (function tm-gnus/decode-encoded-word-if-you-need) t)
108
109
110 ;;; @ for tm-comp
111 ;;;
112
113 (defun tm-gnus4/message-before-send ()
114   (let ((case-fold-search nil))
115     (or (boundp 'mime/news-reply-mode-server-running)
116         (make-variable-buffer-local 'mime/news-reply-mode-server-running))
117     (setq mime/news-reply-mode-server-running (gnus-server-opened))
118     (save-excursion
119       (gnus-start-news-server)
120       (widen)
121       (goto-char (point-min))
122       (run-hooks 'news-inews-hook)
123       (save-restriction
124         (narrow-to-region
125          (point-min)
126          (progn
127            (goto-char (point-min))
128            (search-forward (concat "\n" mail-header-separator "\n"))
129            (point)))
130         
131         (goto-char (point-min))
132         (if (search-forward-regexp "^Newsgroups: +" nil t)
133             (save-restriction
134               (narrow-to-region
135                (point)
136                (if (re-search-forward "^[^ \t]" nil 'end)
137                    (match-beginning 0)
138                  (point-max)))
139               (goto-char (point-min))
140               (replace-regexp "\n[ \t]+" " ")
141               (goto-char (point-min))
142               (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ",")
143               ))
144         ))))
145
146 (defun tm-gnus4/message-sender ()
147   (interactive)
148   (widen)
149   (goto-char (point-min))
150   (save-restriction
151     (narrow-to-region
152      (point-min)
153      (progn
154        (goto-char (point-min))
155        (search-forward (concat "\n" mail-header-separator "\n"))
156        (point)))
157     ;; Mail the message too if To: or Cc: exists.
158     (if (or (mail-fetch-field "to" nil t)
159             (mail-fetch-field "cc" nil t))
160         (if gnus-mail-send-method
161             (progn
162               (message
163                (format "Sending (%d/%d) via mail..." (+ i 1) total))
164               (widen)
165               (funcall gnus-mail-send-method)
166               (message
167                (format "Sending (%d/%d) via mail... done" (+ i 1) total))
168               (ding)
169               (message
170                "No mailer defined.  To: and/or Cc: fields ignored.")
171               (sit-for 1)))))
172   (message
173    (format "Posting %d/%d to USENET..." (+ i 1) total))
174   (if (gnus-inews-article)
175       (message 
176        (format "Posting %d/%d to USENET... done" (+ i 1) total))
177     ;; We cannot signal an error.
178     (ding)
179     (message
180      (format "Article %d/%d rejected: %s"
181              (+ i 1) total (gnus-status-message)))
182     (sit-for 3))
183   )
184
185 (defun tm-gnus4/message-after-send ()
186   (or mime/news-reply-mode-server-running
187       (gnus-close-server))
188   (and (fboundp 'bury-buffer) (bury-buffer))
189   )
190
191 (call-after-loaded
192  'tm-comp
193  (function
194   (lambda ()
195     (set-alist 'mime/message-before-send-hook-alist
196                'news-reply-mode
197                (function tm-gnus4/message-before-send))
198     (set-alist 'mime/message-sender-alist
199                'news-reply-mode
200                (function tm-gnus4/message-sender))
201     (set-alist 'mime/message-after-send-hook-alist
202                'news-reply-mode
203                (function tm-gnus4/message-after-send))
204     )))
205
206
207 ;;; @ end
208 ;;;
209
210 (provide 'tm-gnus4)