tm 7.41.1.
[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 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.16 $
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.16 1996/01/23 04:56:21 morioka 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-partial
127 ;;;
128
129 (call-after-loaded
130  'tm-partial
131  (function
132   (lambda ()
133     (set-atype 'mime/content-decoding-condition
134                '((type . "message/partial")
135                  (method . mime-article/grab-message/partials)
136                  (major-mode . gnus-article-mode)
137                  (summary-buffer-exp . gnus-summary-buffer)
138                  ))
139     
140     (set-alist 'tm-partial/preview-article-method-alist
141                'gnus-article-mode
142                (function
143                 (lambda ()
144                   (tm-gnus/view-message (gnus-summary-article-number))
145                   )))
146     )))
147
148
149 ;;; @ set up
150 ;;;
151
152 (define-key gnus-summary-mode-map "v" (function tm-gnus/view-message))
153 (define-key gnus-summary-mode-map
154   "\e\r" (function tm-gnus/summary-scroll-down))
155
156 (defun tm-gnus/article-reset-variable ()
157   (setq gnus-original-article-buffer nil)
158   (setq tm-gnus/automatic-mime-preview nil)
159   (gnus-article-mode)
160   (setq buffer-read-only nil)
161   )
162
163 (add-hook 'gnus-article-prepare-hook 'tm-gnus/article-reset-variable)
164
165 (defun tm-gnus/decode-encoded-word-if-you-need ()
166   (if (not gnus-have-all-headers)
167       (progn
168         (mime/decode-message-header)
169         (run-hooks 'tm-gnus/article-prepare-hook)
170         )))
171
172 (defun tm-gnus/preview-article-if-you-need ()
173   (if (not gnus-have-all-headers)
174       (let ((str (buffer-string))
175             (obuf (get-buffer tm-gnus/original-article-buffer))
176             (pbuf (current-buffer))
177             )
178         (if obuf
179             (progn
180               (set-buffer obuf)
181               (setq buffer-read-only nil)
182               (erase-buffer)
183               )
184           (setq obuf (get-buffer-create tm-gnus/original-article-buffer))
185           (set-buffer obuf)
186           )
187         (insert str)
188         (gnus-article-mode)
189         (set-buffer pbuf)
190         (make-local-variable 'tm:mother-button-dispatcher)
191         (setq tm:mother-button-dispatcher
192               (function gnus-article-push-button))
193         (save-window-excursion
194           (mime/viewer-mode
195            nil nil nil tm-gnus/original-article-buffer gnus-article-buffer)
196           )
197         (setq tm-gnus/automatic-mime-preview t)
198         (setq gnus-original-article-buffer tm-gnus/original-article-buffer)
199         (let (buffer-read-only)
200           (run-hooks 'tm-gnus/article-prepare-hook)
201           )
202         (if (featurep 'tm-gd3)
203             (setq buffer-read-only nil)
204           )
205         )))
206
207 (setq gnus-show-mime-method
208       (if tm-gnus/automatic-mime-preview
209           (function tm-gnus/preview-article-if-you-need)
210         (function tm-gnus/decode-encoded-word-if-you-need)
211         ))
212
213 (setq gnus-show-mime t)
214
215
216 ;;; @ for BBDB
217 ;;;
218
219 (defun tm-gnus/bbdb-setup ()
220   (if (memq 'bbdb/gnus-update-record gnus-article-prepare-hook)
221       (progn
222         (remove-hook 'gnus-article-prepare-hook 'bbdb/gnus-update-record)
223         (add-hook 'tm-gnus/article-prepare-hook 'bbdb/gnus-update-record)
224         )))
225
226 (add-hook 'gnus-startup-hook 'tm-gnus/bbdb-setup t)
227
228 (tm-gnus/bbdb-setup)
229
230 (call-after-loaded
231  'bbdb
232  (function
233   (lambda ()
234     (require 'tm-bbdb)
235     )))
236
237
238 ;;; @ end
239 ;;;
240
241 (provide 'tm-gnus4)
242
243 ;;; tm-gnus4.el ends here