tm 7.43.
[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,1996 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.43 $
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 ;;; Code:
30
31 (require 'tl-str)
32 (require 'tl-list)
33 (require 'tl-misc)
34 (require 'tm-view)
35 (require 'gnus)
36
37 (eval-when-compile (require 'cl))
38
39
40 ;;; @ version
41 ;;;
42
43 (defconst tm-gnus/RCS-ID
44   "$Id: tm-sgnus.el,v 7.43 1996/02/09 08:13:33 morioka Exp $")
45
46 (defconst tm-gnus/version
47   (concat (get-version-string tm-gnus/RCS-ID) " for September"))
48
49
50 ;;; @ variables
51 ;;;
52
53 (defvar tm-gnus/automatic-mime-preview t
54   "*If non-nil, show MIME processed article.
55 This variable is set to `gnus-show-mime'.")
56
57 (setq gnus-show-mime tm-gnus/automatic-mime-preview)
58
59
60 ;;; @ command functions
61 ;;;
62
63 (defun tm-gnus/view-message (arg)
64   "MIME decode and play this message."
65   (interactive "P")
66   (let ((gnus-break-pages nil))
67     (gnus-summary-select-article t t)
68     )
69   (pop-to-buffer gnus-original-article-buffer t)
70   (let (buffer-read-only)
71     (if (text-property-any (point-min) (point-max) 'invisible t)
72         (remove-text-properties (point-min) (point-max)
73                                 gnus-hidden-properties)
74       ))
75   (mime/viewer-mode nil nil nil gnus-original-article-buffer
76                     gnus-article-buffer)
77   )
78
79 (defun tm-gnus/summary-scroll-down ()
80   "Scroll down one line current article."
81   (interactive)
82   (gnus-summary-scroll-up -1)
83   )
84
85 (defun tm-gnus/summary-toggle-header (&optional arg)
86   (interactive "P")
87   (if tm-gnus/automatic-mime-preview
88       (let* ((hidden
89               (save-excursion
90                 (set-buffer gnus-article-buffer)
91                 (text-property-any 
92                  (goto-char (point-min)) (search-forward "\n\n")
93                  'invisible t)
94                 ))
95              (mime-viewer/redisplay t)
96              )
97         (gnus-summary-select-article hidden t)
98         )
99     (gnus-summary-toggle-header arg))
100   )
101
102 (define-key gnus-summary-mode-map "v" (function tm-gnus/view-message))
103 (define-key gnus-summary-mode-map
104   "\e\r" (function tm-gnus/summary-scroll-down))
105 (substitute-key-definition
106  'gnus-summary-toggle-header
107  'tm-gnus/summary-toggle-header gnus-summary-mode-map)
108
109
110 ;;; @ for tm-view
111 ;;;
112
113 (defun tm-gnus/content-header-filter ()
114   (goto-char (point-min))
115   (mime-preview/cut-header)
116   (tm-gnus/code-convert-region-to-emacs (point-min)(point-max)
117                                         mime/default-coding-system)
118   (mime/decode-message-header)
119   )
120
121 (set-alist 'mime-viewer/content-header-filter-alist
122            'gnus-original-article-mode
123            (function tm-gnus/content-header-filter))
124
125 (fset 'tm-gnus/code-convert-region-to-emacs
126       (symbol-function 'mime/code-convert-region-to-emacs))
127
128 (set-alist 'mime-viewer/code-converter-alist
129            'gnus-original-article-mode
130            (function tm-gnus/code-convert-region-to-emacs))
131
132 (defun mime-viewer/quitting-method-for-sgnus ()
133   (if (not gnus-show-mime)
134       (mime-viewer/kill-buffer))
135   (delete-other-windows)
136   (gnus-article-show-summary)
137   (if (or (not gnus-show-mime)
138           (null gnus-have-all-headers))
139       (gnus-summary-select-article nil t)
140     ))
141
142 (call-after-loaded
143  'tm-view
144  (lambda ()
145    (set-alist 'mime-viewer/quitting-method-alist
146               'gnus-original-article-mode
147               (function mime-viewer/quitting-method-for-sgnus))
148    (set-alist 'mime-viewer/show-summary-method
149               'gnus-original-article-mode
150               (function mime-viewer/quitting-method-for-sgnus))
151    ))
152
153
154 ;;; @ for tm-partial
155 ;;;
156
157 (defun tm-gnus/partial-preview-function ()
158   (tm-gnus/view-message (gnus-summary-article-number))
159   )
160
161 (call-after-loaded
162  'tm-partial
163  (lambda ()
164    (set-atype 'mime/content-decoding-condition
165               '((type . "message/partial")
166                 (method . mime-article/grab-message/partials)
167                 (major-mode . gnus-original-article-mode)
168                 (summary-buffer-exp . gnus-summary-buffer)
169                 ))
170    (set-alist 'tm-partial/preview-article-method-alist
171               'gnus-original-article-mode
172               'tm-gnus/partial-preview-function)
173    ))
174
175
176 ;;; @ article filter
177 ;;;
178
179 (defun tm-gnus/article-reset-variable ()
180   (setq tm-gnus/automatic-mime-preview nil)
181   )
182
183 (add-hook 'gnus-article-prepare-hook 'tm-gnus/article-reset-variable)
184
185 (defun tm-gnus/preview-article ()
186   (make-local-variable 'tm:mother-button-dispatcher)
187   (setq tm:mother-button-dispatcher
188         (function gnus-article-push-button))
189   (let ((mime-viewer/ignored-field-regexp "^:$"))
190     (mime/viewer-mode nil nil nil gnus-original-article-buffer
191                       gnus-article-buffer)
192     )
193   (setq tm-gnus/automatic-mime-preview t)
194   (run-hooks 'tm-gnus/article-prepare-hook)
195   )
196
197 (setq gnus-show-mime-method (function tm-gnus/preview-article))
198
199 (defun tm-gnus/article-decode-encoded-word ()
200   (tm-gnus/code-convert-region-to-emacs (point-min)(point-max)
201                                         mime/default-coding-system)
202   (mime/decode-message-header)
203   (run-hooks 'tm-gnus/article-prepare-hook)
204   )
205
206 (setq gnus-decode-encoded-word-method
207       (function tm-gnus/article-decode-encoded-word))
208
209 (if (boundp 'MULE)
210     (progn
211       (define-service-coding-system gnus-nntp-service nil *noconv*)
212       (if (and (boundp 'nntp-server-process)
213                (processp nntp-server-process)
214                )
215           (set-process-coding-system nntp-server-process *noconv* *noconv*)
216         )
217       
218       (or (fboundp 'tm-gnus/original-request-article)
219           (fset 'tm-gnus/original-request-article
220                 (symbol-function 'gnus-request-article))
221           )
222       
223       (defun gnus-request-article (article group &optional buffer)
224         (let ((file-coding-system-for-read *noconv*))
225           (tm-gnus/original-request-article article group buffer)
226           ))
227
228       (defun tm-gnus/prepare-save-mail-function ()
229         (setq file-coding-system *noconv*)
230         )
231       (add-hook 'nnfolder-prepare-save-mail-hook
232                 'tm-gnus/prepare-save-mail-function)
233       (add-hook 'nnmbox-prepare-save-mail-hook
234                 'tm-gnus/prepare-save-mail-function)
235       
236       (defun tm-gnus/nnheader-find-file-noselect (&rest args)
237         (let ((file-coding-system-for-read *noconv*))
238           (apply (function find-file-noselect) args)
239           ))
240       (eval-after-load
241        "nnheader"
242        '(fset 'nnheader-find-file-noselect
243               'tm-gnus/nnheader-find-file-noselect)
244        )
245       ))
246
247
248 ;;; @ summary filter
249 ;;;
250
251 (cond ((not (boundp 'nnheader-encoded-words-decoding))
252        (require 'tm-ew-d)
253        
254        (defun tm-gnus/decode-summary-from-and-subjects ()
255          (mapcar (lambda (header)
256                    (let ((from (mail-header-from header))
257                          (subj (mail-header-subject header))
258                          )
259                      (mail-header-set-from
260                       header
261                       (if from
262                           (mime-eword/decode-string
263                            (code-convert-string
264                             from mime/default-coding-system *internal*))
265                         ""))
266                      (mail-header-set-subject
267                       header
268                       (if subj
269                           (mime-eword/decode-string
270                            (code-convert-string
271                             subj mime/default-coding-system *internal*))
272                         ""))
273                      ))
274                  gnus-newsgroup-headers))
275        
276        (add-hook 'gnus-select-group-hook
277                  (function tm-gnus/decode-summary-from-and-subjects))
278        ))
279
280
281 ;;; @ for tm-edit
282 ;;;
283
284 (defun tm-gnus/forward-insert-buffer (buffer)
285   (save-excursion
286     (save-restriction
287       (if gnus-signature-before-forwarded-message
288           (goto-char (point-max))
289         (goto-char (point-min))
290         (re-search-forward
291          (concat "^" (regexp-quote mail-header-separator) "$"))
292         (forward-line 1))
293       ;; Narrow to the area we are to insert.
294       (narrow-to-region (point) (point))
295       ;; Insert the separators and the forwarded buffer.
296       (mime-editor/insert-tag "message" "rfc822")
297       (insert-buffer-substring buffer)
298       ;; Delete any invisible text.
299       (goto-char (point-min))
300       (let (beg)
301         (while (setq beg (next-single-property-change (point) 'invisible))
302           (goto-char beg)
303           (delete-region beg (or (next-single-property-change 
304                                   (point) 'invisible)
305                                  (point-max))))))))
306
307 (call-after-loaded
308  'mime-setup
309  (lambda ()
310    (cond ((string-match "XEmacs" emacs-version)
311           (require 'gnus-msg)
312           (fset 'gnus-forward-insert-buffer 'tm-gnus/forward-insert-buffer)
313           )
314          (t
315           (eval-after-load
316            "gnus-msg"
317            '(fset 'gnus-forward-insert-buffer 'tm-gnus/forward-insert-buffer)
318            )
319           ))))
320
321
322 ;;; @ for BBDB
323 ;;;
324
325 (defun tm-gnus/bbdb-setup ()
326   (if (memq 'bbdb/gnus-update-record gnus-article-prepare-hook)
327       (progn
328         (remove-hook 'gnus-article-prepare-hook 'bbdb/gnus-update-record)
329         (add-hook 'tm-gnus/article-prepare-hook 'bbdb/gnus-update-record)
330         )))
331
332 (add-hook 'gnus-startup-hook 'tm-gnus/bbdb-setup t)
333
334 (tm-gnus/bbdb-setup)
335
336 (call-after-loaded
337  'bbdb
338  (lambda ()
339    (require 'tm-bbdb)
340    ))
341
342
343 ;;; @ end
344 ;;;
345
346 (provide 'tm-sgnus)
347
348 ;;; tm-sgnus.el ends here