tm 7.28.
[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.9 $
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.9 1995/12/03 17:30:57 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-summary-select-article t t)
65     )
66   (pop-to-buffer gnus-article-buffer t)
67   (let ((str (buffer-string))
68         (obuf (get-buffer tm-gnus/original-article-buffer))
69         (pbuf (current-buffer))
70         )
71     (if obuf
72         (progn
73           (set-buffer obuf)
74           (setq buffer-read-only nil)
75           (erase-buffer)
76           )
77       (setq obuf (get-buffer-create tm-gnus/original-article-buffer))
78       (set-buffer obuf)
79       )
80     (insert str)
81     (gnus-article-mode)
82     (set-buffer pbuf)
83     (make-local-variable 'tm:mother-button-dispatcher)
84     (setq tm:mother-button-dispatcher
85           (function gnus-article-push-button))
86     (mime/viewer-mode
87      nil nil nil tm-gnus/original-article-buffer gnus-article-buffer)
88     (run-hooks 'tm-gnus/article-prepare-hook)
89     ))
90
91 (defun tm-gnus/summary-scroll-down ()
92   "Scroll down one line current article."
93   (interactive)
94   (gnus-summary-scroll-up -1)
95   )
96
97 (defun mime-viewer/quitting-method-for-gnus4 ()
98   (if (not gnus-show-mime)
99       (mime-viewer/kill-buffer)
100     )
101   (delete-other-windows)
102   (gnus-article-show-summary)
103   (if (or (not gnus-show-mime)
104           (null gnus-have-all-headers))
105       (gnus-summary-select-article nil t)
106     ))
107
108 (call-after-loaded
109  'tm-view
110  (function
111   (lambda ()
112     (set-alist 'mime-viewer/quitting-method-alist
113                'gnus-article-mode
114                (function mime-viewer/quitting-method-for-gnus4))
115     )))
116
117
118 ;;; @ for tm-partial
119 ;;;
120
121 (call-after-loaded
122  'tm-partial
123  (function
124   (lambda ()
125     (set-atype 'mime/content-decoding-condition
126                '((type . "message/partial")
127                  (method . mime-article/grab-message/partials)
128                  (major-mode . gnus-article-mode)
129                  (summary-buffer-exp . gnus-summary-buffer)
130                  ))
131     
132     (set-alist 'tm-partial/preview-article-method-alist
133                'gnus-article-mode
134                (function
135                 (lambda ()
136                   (tm-gnus/view-message (gnus-summary-article-number))
137                   )))
138     )))
139
140
141 ;;; @ set up
142 ;;;
143
144 (define-key gnus-summary-mode-map "v" (function tm-gnus/view-message))
145 (define-key gnus-summary-mode-map
146   "\e\r" (function tm-gnus/summary-scroll-down))
147
148 (defun tm-gnus/article-reset-variable ()
149   (setq gnus-original-article-buffer gnus-article-buffer)
150   (setq tm-gnus/automatic-mime-preview nil)
151   (gnus-article-mode)
152   (setq buffer-read-only nil)
153   )
154
155 (add-hook 'gnus-article-prepare-hook 'tm-gnus/article-reset-variable)
156
157 (defun tm-gnus/decode-encoded-word-if-you-need ()
158   (if (not gnus-have-all-headers)
159       (progn
160         (mime/decode-message-header)
161         (run-hooks 'tm-gnus/article-prepare-hook)
162         )))
163
164 (defun tm-gnus/preview-article-if-you-need ()
165   (if (not gnus-have-all-headers)
166       (let ((str (buffer-string))
167             (obuf (get-buffer tm-gnus/original-article-buffer))
168             (pbuf (current-buffer))
169             )
170         (if obuf
171             (progn
172               (set-buffer obuf)
173               (setq buffer-read-only nil)
174               (erase-buffer)
175               )
176           (setq obuf (get-buffer-create tm-gnus/original-article-buffer))
177           (set-buffer obuf)
178           )
179         (insert str)
180         (gnus-article-mode)
181         (set-buffer pbuf)
182         (make-local-variable 'tm:mother-button-dispatcher)
183         (setq tm:mother-button-dispatcher
184               (function gnus-article-push-button))
185         (mime/viewer-mode
186          nil nil nil tm-gnus/original-article-buffer gnus-article-buffer)
187         (gnus-article-show-summary)
188         (run-hooks 'tm-gnus/article-prepare-hook)
189         )))
190
191 (setq gnus-show-mime-method
192       (if tm-gnus/automatic-mime-preview
193           (function tm-gnus/preview-article-if-you-need)
194         (function tm-gnus/decode-encoded-word-if-you-need)
195         ))
196
197 (setq gnus-show-mime t)
198
199
200 ;;; @ for BBDB
201 ;;;
202
203 (defun tm-gnus/bbdb-setup ()
204   (if (memq 'bbdb/gnus-update-record gnus-article-prepare-hook)
205       (progn
206         (remove-hook 'gnus-article-prepare-hook 'bbdb/gnus-update-record)
207         (add-hook 'tm-gnus/article-prepare-hook 'bbdb/gnus-update-record)
208         )))
209
210 (add-hook 'gnus-startup-hook 'tm-gnus/bbdb-setup t)
211
212 (tm-gnus/bbdb-setup)
213
214
215 ;;; @ end
216 ;;;
217
218 (provide 'tm-gnus4)
219