tm 7.29.
[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.11 $
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 (require 'tl-str)
31 (require 'tl-misc)
32
33
34 ;;; @ version
35 ;;;
36
37 (defconst tm-gnus/RCS-ID
38   "$Id: tm-gnus4.el,v 7.11 1995/12/05 07:36:32 morioka Exp $")
39
40 (defconst tm-gnus/version
41   (concat (get-version-string tm-gnus/RCS-ID) " for 3.15 .. 5.1"))
42
43
44 ;;; @ variable
45 ;;;
46
47 (defvar tm-gnus/automatic-mime-preview t
48   "*If non-nil, show MIME processed article.
49 This variable is set to `gnus-show-mime'.")
50
51 (defvar tm-gnus/original-article-buffer " *Original Article*")
52 (defvar gnus-original-article-buffer nil)
53
54
55 ;;; @ for tm-view
56 ;;;
57
58 (autoload 'mime/viewer-mode "tm-view" "View MIME message." t)
59
60 (defun tm-gnus/view-message (arg)
61   "MIME decode and play this message."
62   (interactive "P")
63   (let ((gnus-break-pages nil)
64         (gnus-show-mime nil))
65     (gnus-summary-select-article t t)
66     )
67   (pop-to-buffer gnus-article-buffer t)
68   (let ((str (buffer-string))
69         (obuf (get-buffer tm-gnus/original-article-buffer))
70         (pbuf (current-buffer))
71         )
72     (if obuf
73         (progn
74           (set-buffer obuf)
75           (setq buffer-read-only nil)
76           (erase-buffer)
77           )
78       (setq obuf (get-buffer-create tm-gnus/original-article-buffer))
79       (set-buffer obuf)
80       )
81     (insert str)
82     (gnus-article-mode)
83     (set-buffer pbuf)
84     (make-local-variable 'tm:mother-button-dispatcher)
85     (setq tm:mother-button-dispatcher
86           (function gnus-article-push-button))
87     (mime/viewer-mode
88      nil nil nil tm-gnus/original-article-buffer gnus-article-buffer)
89     (run-hooks 'tm-gnus/article-prepare-hook)
90     ))
91
92 (defun tm-gnus/summary-scroll-down ()
93   "Scroll down one line current article."
94   (interactive)
95   (gnus-summary-scroll-up -1)
96   )
97
98 (defun mime-viewer/quitting-method-for-gnus4 ()
99   (if (not gnus-show-mime)
100       (mime-viewer/kill-buffer)
101     )
102   (delete-other-windows)
103   (gnus-article-show-summary)
104   (if (or (not gnus-show-mime)
105           (null gnus-have-all-headers))
106       (gnus-summary-select-article nil t)
107     ))
108
109 (call-after-loaded
110  'tm-view
111  (function
112   (lambda ()
113     (set-alist 'mime-viewer/quitting-method-alist
114                'gnus-article-mode
115                (function mime-viewer/quitting-method-for-gnus4))
116     )))
117
118
119 ;;; @ for tm-partial
120 ;;;
121
122 (call-after-loaded
123  'tm-partial
124  (function
125   (lambda ()
126     (set-atype 'mime/content-decoding-condition
127                '((type . "message/partial")
128                  (method . mime-article/grab-message/partials)
129                  (major-mode . gnus-article-mode)
130                  (summary-buffer-exp . gnus-summary-buffer)
131                  ))
132     
133     (set-alist 'tm-partial/preview-article-method-alist
134                'gnus-article-mode
135                (function
136                 (lambda ()
137                   (tm-gnus/view-message (gnus-summary-article-number))
138                   )))
139     )))
140
141
142 ;;; @ set up
143 ;;;
144
145 (define-key gnus-summary-mode-map "v" (function tm-gnus/view-message))
146 (define-key gnus-summary-mode-map
147   "\e\r" (function tm-gnus/summary-scroll-down))
148
149 (defun tm-gnus/article-reset-variable ()
150   (setq gnus-original-article-buffer gnus-article-buffer)
151   (setq tm-gnus/automatic-mime-preview nil)
152   (gnus-article-mode)
153   (setq buffer-read-only nil)
154   )
155
156 (add-hook 'gnus-article-prepare-hook 'tm-gnus/article-reset-variable)
157
158 (defun tm-gnus/decode-encoded-word-if-you-need ()
159   (if (not gnus-have-all-headers)
160       (progn
161         (mime/decode-message-header)
162         (run-hooks 'tm-gnus/article-prepare-hook)
163         )))
164
165 (defun tm-gnus/preview-article-if-you-need ()
166   (if (not gnus-have-all-headers)
167       (let ((str (buffer-string))
168             (obuf (get-buffer tm-gnus/original-article-buffer))
169             (pbuf (current-buffer))
170             )
171         (if obuf
172             (progn
173               (set-buffer obuf)
174               (setq buffer-read-only nil)
175               (erase-buffer)
176               )
177           (setq obuf (get-buffer-create tm-gnus/original-article-buffer))
178           (set-buffer obuf)
179           )
180         (insert str)
181         (gnus-article-mode)
182         (set-buffer pbuf)
183         (make-local-variable 'tm:mother-button-dispatcher)
184         (setq tm:mother-button-dispatcher
185               (function gnus-article-push-button))
186         (mime/viewer-mode
187          nil nil nil tm-gnus/original-article-buffer gnus-article-buffer)
188         (gnus-article-show-summary)
189         (setq tm-gnus/automatic-mime-preview t)
190         (setq gnus-original-article-buffer tm-gnus/original-article-buffer)
191         (run-hooks 'tm-gnus/article-prepare-hook)
192         )))
193
194 (setq gnus-show-mime-method
195       (if tm-gnus/automatic-mime-preview
196           (function tm-gnus/preview-article-if-you-need)
197         (function tm-gnus/decode-encoded-word-if-you-need)
198         ))
199
200 (setq gnus-show-mime t)
201
202
203 ;;; @ for BBDB
204 ;;;
205
206 (defun tm-gnus/bbdb-setup ()
207   (if (memq 'bbdb/gnus-update-record gnus-article-prepare-hook)
208       (progn
209         (remove-hook 'gnus-article-prepare-hook 'bbdb/gnus-update-record)
210         (add-hook 'tm-gnus/article-prepare-hook 'bbdb/gnus-update-record)
211         )))
212
213 (add-hook 'gnus-startup-hook 'tm-gnus/bbdb-setup t)
214
215 (tm-gnus/bbdb-setup)
216
217
218 ;;; @ end
219 ;;;
220
221 (provide 'tm-gnus4)
222