e7c0dc5cd6279946cc6465a43035a46fc8584fd9
[elisp/tm.git] / gnus / tm-sgnus.el
1 ;;;
2 ;;; tm-sgnus.el --- tm-gnus module for September GNUS
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 ;;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
9 ;;; Created: 1995/09/24
10 ;;; Version: $Revision: 7.20 $
11 ;;; Keywords: news, MIME, multimedia, multilingual, encoded-word
12 ;;;
13 ;;; This file is part of tm (Tools for MIME).
14 ;;;
15 ;;; This program is free software; you can redistribute it and/or
16 ;;; modify it under the terms of the GNU General Public License as
17 ;;; published by the Free Software Foundation; either version 2, or
18 ;;; (at your option) any later version.
19 ;;;
20 ;;; This program is distributed in the hope that it will be useful,
21 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23 ;;; General Public License for more details.
24 ;;;
25 ;;; You should have received a copy of the GNU General Public License
26 ;;; along with This program.  If not, write to the Free Software
27 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
28
29 (require 'tl-str)
30 (require 'tl-list)
31 (require 'tl-misc)
32 (require 'tm-view)
33 (require 'gnus)
34 (require 'tm-gd5)
35
36
37 ;;; @ version
38 ;;;
39
40 (defconst tm-gnus/RCS-ID
41   "$Id: tm-sgnus.el,v 7.20 1995/12/04 00:25:21 morioka Exp $")
42
43 (defconst tm-gnus/version
44   (concat (get-version-string tm-gnus/RCS-ID) " for September"))
45
46
47 ;;; @ variables
48 ;;;
49
50 (defvar tm-gnus/automatic-mime-preview t
51   "*If non-nil, show MIME processed article.
52 This variable is set to `gnus-show-mime'.")
53
54 (setq gnus-show-mime tm-gnus/automatic-mime-preview)
55
56
57 ;;; @ command functions
58 ;;;
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-original-article-buffer t)
67   (let (buffer-read-only)
68     (if (text-property-any (point-min) (point-max) 'invisible t)
69         (remove-text-properties (point-min) (point-max)
70                                 gnus-hidden-properties)
71       ))
72   (mime/viewer-mode nil nil nil gnus-original-article-buffer
73                     gnus-article-buffer)
74   )
75
76 (defun tm-gnus/summary-scroll-down ()
77   "Scroll down one line current article."
78   (interactive)
79   (gnus-summary-scroll-up -1)
80   )
81
82 (defun tm-gnus/summary-toggle-header (&optional arg)
83   (interactive "P")
84   (if (and gnus-show-mime
85            (or (not gnus-strict-mime)
86                (save-excursion
87                  (set-buffer gnus-article-buffer)
88                  (gnus-fetch-field "Mime-Version")
89                  )))
90       (let ((mime-viewer/ignored-field-regexp
91              (if (save-excursion
92                    (set-buffer gnus-article-buffer)
93                    (some-element
94                     (lambda (field)
95                       (rfc822/get-field-body field)
96                       )
97                     mime-viewer/ignored-field-list))
98                  mime-viewer/ignored-field-regexp
99                "^:$")))
100         (gnus-summary-select-article t t)
101         )
102     (gnus-summary-toggle-header arg)
103     ))
104
105 (define-key gnus-summary-mode-map "v" (function tm-gnus/view-message))
106 (define-key gnus-summary-mode-map
107   "\e\r" (function tm-gnus/summary-scroll-down))
108 (define-key gnus-summary-mode-map
109   "t" (function tm-gnus/summary-toggle-header))
110
111
112 ;;; @ for tm-view
113 ;;;
114
115 (defun mime-viewer/quitting-method-for-sgnus ()
116   (if (not gnus-show-mime)
117       (mime-viewer/kill-buffer))
118   (delete-other-windows)
119   (gnus-article-show-summary)
120   (if (or (not gnus-show-mime)
121           (null gnus-have-all-headers))
122       (gnus-summary-select-article nil t)
123     ))
124
125 (call-after-loaded
126  'tm-view
127  (lambda ()
128    (set-alist 'mime-viewer/quitting-method-alist
129               'gnus-original-article-mode
130               (function mime-viewer/quitting-method-for-sgnus))
131    ))
132
133
134 ;;; @ for tm-partial
135 ;;;
136
137 (call-after-loaded
138  'tm-partial
139  (lambda ()
140    (set-atype 'mime/content-decoding-condition
141               '((type . "message/partial")
142                 (method . mime-article/grab-message/partials)
143                 (major-mode . gnus-original-article-mode)
144                 (summary-buffer-exp . gnus-summary-buffer)
145                 ))
146    (set-alist 'tm-partial/preview-article-method-alist
147               'gnus-original-article-mode
148               '(lambda ()
149                  (tm-gnus/view-message (gnus-summary-article-number))
150                  ))
151    ))
152
153
154 ;;; @ article filter
155 ;;;
156
157 (defun tm-gnus/article-reset-variable ()
158   (setq tm-gnus/automatic-mime-preview nil)
159   )
160
161 (add-hook 'gnus-article-prepare-hook 'tm-gnus/article-reset-variable)
162
163 (defun tm-gnus/preview-article ()
164   (make-local-variable 'tm:mother-button-dispatcher)
165   (setq tm:mother-button-dispatcher
166         (function gnus-article-push-button))
167   (mime/viewer-mode nil nil nil gnus-original-article-buffer
168                     gnus-article-buffer)
169   (setq tm-gnus/automatic-mime-preview t)
170   (run-hooks 'tm-gnus/article-prepare-hook)
171   )
172
173 (setq gnus-show-mime-method (function tm-gnus/preview-article))
174
175 (defun tm-gnus/article-decode-encoded-word ()
176   (mime/decode-message-header)
177   (run-hooks 'tm-gnus/article-prepare-hook)
178   )
179
180 (setq gnus-decode-encoded-word-method
181       (function tm-gnus/article-decode-encoded-word))
182
183 (or (fboundp 'tm::gnus-article-hide-headers-if-wanted)
184     (fset 'tm::gnus-article-hide-headers-if-wanted
185           (symbol-function 'gnus-article-hide-headers-if-wanted))
186     )
187
188 (defun gnus-article-hide-headers-if-wanted ()
189   (or tm-gnus/automatic-mime-preview
190       (tm::gnus-article-hide-headers-if-wanted)
191       ))
192
193
194 ;;; @ for BBDB
195 ;;;
196
197 (defun tm-gnus/bbdb-setup ()
198   (if (memq 'bbdb/gnus-update-record gnus-article-prepare-hook)
199       (progn
200         (remove-hook 'gnus-article-prepare-hook 'bbdb/gnus-update-record)
201         (add-hook 'tm-gnus/article-prepare-hook 'bbdb/gnus-update-record)
202         )))
203
204 (add-hook 'gnus-startup-hook 'tm-gnus/bbdb-setup t)
205
206 (tm-gnus/bbdb-setup)
207
208
209 ;;; @ end
210 ;;;
211
212 (provide 'tm-sgnus)