a4cfce515d3690a0465060f28c80fe9f459b3131
[elisp/tm.git] / gnus / tm-gnus4.el
1 ;;;
2 ;;; tm-gnus4.el --- tm-gnus module for GNUS 4, 5.0.* and 5.1.*.
3 ;;;
4 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;;; Copyright (C) 1995,1996 MORIOKA Tomohiko
6 ;;;
7 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;; modified by OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
9 ;;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
10 ;;; Created: 1993/11/20 (merged tm-gnus5.el)
11 ;;; Version: $Revision: 7.19 $
12 ;;; Keywords: news, MIME, multimedia, multilingual, encoded-word
13 ;;;
14 ;;; This file is part of tm (Tools for MIME).
15 ;;;
16 ;;; This program is free software; you can redistribute it and/or
17 ;;; modify it under the terms of the GNU General Public License as
18 ;;; published by the Free Software Foundation; either version 2, or
19 ;;; (at your option) any later version.
20 ;;;
21 ;;; This program is distributed in the hope that it will be useful,
22 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24 ;;; General Public License for more details.
25 ;;;
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with This program.  If not, write to the Free Software
28 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 ;;;
30 ;;; Code:
31
32 (require 'tl-str)
33 (require 'tl-misc)
34
35
36 ;;; @ version
37 ;;;
38
39 (defconst tm-gnus/RCS-ID
40   "$Id: tm-gnus4.el,v 7.19 1996/06/06 16:43:42 shuhei-k Exp $")
41
42 (defconst tm-gnus/version
43   (concat (get-version-string tm-gnus/RCS-ID) " for 3.15 .. 5.1.*"))
44
45
46 ;;; @ variable
47 ;;;
48
49 (defvar tm-gnus/automatic-mime-preview t
50   "*If non-nil, show MIME processed article.
51 This variable is set to `gnus-show-mime'.")
52
53 (defvar tm-gnus/original-article-buffer " *Original Article*")
54 (defvar gnus-original-article-buffer nil)
55
56
57 ;;; @ for tm-view
58 ;;;
59
60 (autoload 'mime/viewer-mode "tm-view" "View MIME message." t)
61
62 (defun tm-gnus/view-message (arg)
63   "MIME decode and play this message."
64   (interactive "P")
65   (let ((gnus-break-pages nil)
66         (gnus-show-mime nil))
67     (gnus-summary-select-article t t)
68     )
69   (pop-to-buffer gnus-article-buffer t)
70   (let ((str (buffer-string))
71         (obuf (get-buffer tm-gnus/original-article-buffer))
72         (pbuf (current-buffer))
73         )
74     (if obuf
75         (progn
76           (set-buffer obuf)
77           (setq buffer-read-only nil)
78           (erase-buffer)
79           )
80       (setq obuf (get-buffer-create tm-gnus/original-article-buffer))
81       (set-buffer obuf)
82       )
83     (insert str)
84     (gnus-article-mode)
85     (set-buffer pbuf)
86     (make-local-variable 'tm:mother-button-dispatcher)
87     (setq tm:mother-button-dispatcher
88           (function gnus-article-push-button))
89     (mime/viewer-mode
90      nil nil nil tm-gnus/original-article-buffer gnus-article-buffer)
91     (let (buffer-read-only)
92       (run-hooks 'tm-gnus/article-prepare-hook)
93       )
94     ))
95
96 (defun tm-gnus/summary-scroll-down ()
97   "Scroll down one line current article."
98   (interactive)
99   (gnus-summary-scroll-up -1)
100   )
101
102 (defun mime-viewer/quitting-method-for-gnus4 ()
103   (if (not gnus-show-mime)
104       (mime-viewer/kill-buffer)
105     )
106   (delete-other-windows)
107   (gnus-article-show-summary)
108   (if (or (not gnus-show-mime)
109           (null gnus-have-all-headers))
110       (gnus-summary-select-article nil t)
111     ))
112
113 (call-after-loaded
114  'tm-view
115  (function
116   (lambda ()
117     (set-alist 'mime-viewer/quitting-method-alist
118                'gnus-article-mode
119                (function mime-viewer/quitting-method-for-gnus4))
120     (set-alist 'mime-viewer/show-summary-method
121                'gnus-article-mode
122                (function mime-viewer/quitting-method-for-gnus4))
123     )))
124
125
126 ;;; @ for tm-edit
127 ;;;
128
129 ;; suggested by OKABE Yasuo <okabe@kudpc.kyoto-u.ac.jp>
130 ;;      1995/11/08 (c.f. [tm ML:1067])
131 (defun tm-gnus/insert-article (&optional message)
132   (interactive)
133   (let (;; for Emacs 19
134         (mail-citation-hook '(mime-editor/inserted-message-filter))
135         news-reply-header-hook
136         mail-yank-hooks
137         
138         ;; for Emacs 18
139         (mail-yank-ignored-headers mime-editor/yank-ignored-field-regexp)
140         (news-make-reply-yank-header (function
141                                       (lambda (message-id from) "")
142                                       ))
143         (news-yank-original-quoting-indicator "")
144         
145         ;; select raw article buffer
146         (mail-reply-buffer
147          (save-excursion
148            (set-buffer gnus-article-buffer)
149            (if (eq major-mode 'mime/viewer-mode)
150                mime::preview/article-buffer
151              gnus-article-buffer)))
152         )
153     (news-reply-yank-original 0)
154     ))
155
156 ;;; modified by Steven L. Baur <steve@miranova.com>
157 ;;;     1995/12/6 (c.f. [tm-en:209])
158 (defun mime-editor/attach-to-news-reply-menu ()
159   "Arrange to attach MIME editor's popup menu to VM's"
160   (if (boundp 'news-reply-menu)
161       (progn
162         (setq news-reply-menu (append news-reply-menu
163                                       '("---")
164                                       mime-editor/popup-menu-for-xemacs))
165         (remove-hook 'news-setup-hook
166                      'mime-editor/attach-to-news-reply-menu)
167         )))
168
169 (call-after-loaded
170  'tm-edit
171  (function
172   (lambda ()
173     (set-alist
174      'mime-editor/message-inserter-alist
175      'news-reply-mode (function tm-gnus/insert-article))
176     
177     (autoload 'tm-mail/insert-message "tm-mail")
178     (set-alist 'mime-editor/message-inserter-alist
179                'mail-mode (function tm-mail/insert-message))
180     (if (string-match "XEmacs\\|Lucid" emacs-version)
181         (add-hook 'news-setup-hook 'mime-editor/attach-to-news-reply-menu)
182       )
183     )))
184
185
186 ;;; @ for tm-partial
187 ;;;
188
189 (call-after-loaded
190  'tm-partial
191  (function
192   (lambda ()
193     (set-atype 'mime/content-decoding-condition
194                '((type . "message/partial")
195                  (method . mime-article/grab-message/partials)
196                  (major-mode . gnus-article-mode)
197                  (summary-buffer-exp . gnus-summary-buffer)
198                  ))
199     
200     (set-alist 'tm-partial/preview-article-method-alist
201                'gnus-article-mode
202                (function
203                 (lambda ()
204                   (tm-gnus/view-message (gnus-summary-article-number))
205                   )))
206     )))
207
208
209 ;;; @ set up
210 ;;;
211
212 (define-key gnus-summary-mode-map "v" (function tm-gnus/view-message))
213 (define-key gnus-summary-mode-map
214   "\e\r" (function tm-gnus/summary-scroll-down))
215
216 (defun tm-gnus/article-reset-variable ()
217   (setq gnus-original-article-buffer nil)
218   (setq tm-gnus/automatic-mime-preview nil)
219   (gnus-article-mode)
220   (setq buffer-read-only nil)
221   )
222
223 (add-hook 'gnus-article-prepare-hook 'tm-gnus/article-reset-variable)
224
225 (defun tm-gnus/decode-encoded-word-if-you-need ()
226   (if (not gnus-have-all-headers)
227       (progn
228         (mime/decode-message-header)
229         (run-hooks 'tm-gnus/article-prepare-hook)
230         )))
231
232 (defun tm-gnus/preview-article-if-you-need ()
233   (if (not gnus-have-all-headers)
234       (let ((str (buffer-string))
235             (obuf (get-buffer tm-gnus/original-article-buffer))
236             (pbuf (current-buffer))
237             )
238         (if obuf
239             (progn
240               (set-buffer obuf)
241               (setq buffer-read-only nil)
242               (erase-buffer)
243               )
244           (setq obuf (get-buffer-create tm-gnus/original-article-buffer))
245           (set-buffer obuf)
246           )
247         (insert str)
248         (gnus-article-mode)
249         (set-buffer pbuf)
250         (make-local-variable 'tm:mother-button-dispatcher)
251         (setq tm:mother-button-dispatcher
252               (function gnus-article-push-button))
253         (save-window-excursion
254           (mime/viewer-mode
255            nil nil nil tm-gnus/original-article-buffer gnus-article-buffer)
256           )
257         (setq tm-gnus/automatic-mime-preview t)
258         (setq gnus-original-article-buffer tm-gnus/original-article-buffer)
259         (let (buffer-read-only)
260           (run-hooks 'tm-gnus/article-prepare-hook)
261           )
262         (if (featurep 'tm-gd3)
263             (setq buffer-read-only nil)
264           )
265         )))
266
267 (setq gnus-show-mime-method
268       (if tm-gnus/automatic-mime-preview
269           (function tm-gnus/preview-article-if-you-need)
270         (function tm-gnus/decode-encoded-word-if-you-need)
271         ))
272
273 (setq gnus-show-mime t)
274
275
276 ;;; @ for BBDB
277 ;;;
278
279 (call-after-loaded
280  'bbdb
281  (function
282   (lambda ()
283     (require 'tm-bbdb)
284     )))
285
286 (autoload 'tm-bbdb/update-record "tm-bbdb")
287
288 (defun tm-gnus/bbdb-setup ()
289   (if (memq 'bbdb/gnus-update-record gnus-article-prepare-hook)
290       (progn
291         (remove-hook 'gnus-article-prepare-hook 'bbdb/gnus-update-record)
292         ;;(add-hook 'tm-gnus/article-prepare-hook 'bbdb/gnus-update-record)
293         (add-hook 'gnus-article-display-hook 'tm-bbdb/update-record)
294         )))
295
296 (add-hook 'gnus-startup-hook 'tm-gnus/bbdb-setup t)
297
298 (tm-gnus/bbdb-setup)
299
300
301 ;;; @ end
302 ;;;
303
304 (provide 'tm-gnus4)
305
306 ;;; tm-gnus4.el ends here