2 ;;; tm-sgnus.el --- MIME extender for Gnus 5.2
4 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;;; Copyright (C) 1995,1996 MORIOKA Tomohiko
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.63 $
11 ;;; Keywords: news, MIME, multimedia, multilingual, encoded-word
13 ;;; This file is part of tm (Tools for MIME).
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.
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.
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.
37 (eval-when-compile (require 'cl))
43 (defconst tm-gnus/RCS-ID
44 "$Id: tm-sgnus.el,v 7.63 1996/05/27 03:48:56 morioka Exp $")
46 (defconst tm-gnus/version
47 (concat (get-version-string tm-gnus/RCS-ID) " for September"))
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'.")
57 (setq gnus-show-mime tm-gnus/automatic-mime-preview)
60 ;;; @ command functions
63 (defun tm-gnus/view-message (arg)
64 "MIME decode and play this message."
66 (let ((gnus-break-pages nil))
67 (gnus-summary-select-article t t)
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)
75 (mime/viewer-mode nil nil nil gnus-original-article-buffer
79 (defun tm-gnus/summary-scroll-down ()
80 "Scroll down one line current article."
82 (gnus-summary-scroll-up -1)
85 (defun tm-gnus/summary-toggle-header (&optional arg)
87 (if tm-gnus/automatic-mime-preview
90 (set-buffer gnus-article-buffer)
92 (goto-char (point-min)) (search-forward "\n\n")
95 (mime-viewer/redisplay t)
97 (gnus-summary-select-article hidden t)
99 (gnus-summary-toggle-header arg))
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)
113 (defun tm-gnus/content-header-filter ()
114 (goto-char (point-min))
115 (mime-preview/cut-header)
116 (mime-charset-decode-region (point-min)(point-max)
117 mime/default-coding-system)
118 (mime/decode-message-header)
121 (set-alist 'mime-viewer/content-header-filter-alist
122 'gnus-original-article-mode
123 (function tm-gnus/content-header-filter))
125 (set-alist 'mime-viewer/code-converter-alist
126 'gnus-original-article-mode
127 (function mime-charset-decode-region))
129 (defun mime-viewer/quitting-method-for-sgnus ()
130 (if (not gnus-show-mime)
131 (mime-viewer/kill-buffer))
132 (delete-other-windows)
133 (gnus-article-show-summary)
134 (if (or (not gnus-show-mime)
135 (null gnus-have-all-headers))
136 (gnus-summary-select-article nil t)
139 (set-alist 'mime-viewer/quitting-method-alist
140 'gnus-original-article-mode
141 (function mime-viewer/quitting-method-for-sgnus))
142 (set-alist 'mime-viewer/show-summary-method
143 'gnus-original-article-mode
144 (function mime-viewer/quitting-method-for-sgnus))
150 (defun tm-gnus/partial-preview-function ()
151 (tm-gnus/view-message (gnus-summary-article-number))
157 (set-atype 'mime/content-decoding-condition
158 '((type . "message/partial")
159 (method . mime-article/grab-message/partials)
160 (major-mode . gnus-original-article-mode)
161 (summary-buffer-exp . gnus-summary-buffer)
163 (set-alist 'tm-partial/preview-article-method-alist
164 'gnus-original-article-mode
165 'tm-gnus/partial-preview-function)
172 (defun tm-gnus/article-reset-variable ()
173 (setq tm-gnus/automatic-mime-preview nil)
176 (add-hook 'gnus-article-prepare-hook 'tm-gnus/article-reset-variable)
178 (defun tm-gnus/preview-article ()
179 (make-local-variable 'tm:mother-button-dispatcher)
180 (setq tm:mother-button-dispatcher
181 (function gnus-article-push-button))
182 (let ((mime-viewer/ignored-field-regexp "^:$")
183 (mime/default-coding-system
185 (set-buffer gnus-summary-buffer)
186 mime/default-coding-system)))
187 (mime/viewer-mode nil nil nil gnus-original-article-buffer
190 (setq tm-gnus/automatic-mime-preview t)
191 (run-hooks 'tm-gnus/article-prepare-hook)
194 (setq gnus-show-mime-method (function tm-gnus/preview-article))
196 (defun tm-gnus/article-decode-encoded-word ()
197 (character-decode-region (point-min)(point-max)
199 (set-buffer gnus-summary-buffer)
200 mime/default-coding-system))
201 (mime/decode-message-header)
202 (run-hooks 'tm-gnus/article-prepare-hook)
205 (setq gnus-decode-encoded-word-method
206 (function tm-gnus/article-decode-encoded-word))
212 (defvar gnus-newsgroup-default-coding-system-alist nil)
214 (defun gnus-set-newsgroup-default-coding-system (ng cs)
215 "Define CS as default coding system for newsgroup NG."
216 (set-alist 'gnus-newsgroup-default-coding-system-alist
217 (concat "^" (regexp-quote ng) "\\($\\|\\.\\)")
222 (cond ((boundp 'MULE)
223 (define-service-coding-system gnus-nntp-service nil *noconv*)
224 (if (and (boundp 'nntp-server-process)
225 (processp nntp-server-process)
227 (set-process-coding-system nntp-server-process *noconv* *noconv*)
231 (if (and (boundp 'nntp-server-process)
232 (processp nntp-server-process)
234 (set-process-input-coding-system nntp-server-process 'noconv)
240 (defun nnmail-find-file (file)
241 "Insert FILE in server buffer safely. [tm-sgnus.el]"
242 (set-buffer nntp-server-buffer)
244 (let ((format-alist nil)
245 (after-insert-file-functions nil)
246 (file-coding-system-for-read *noconv*))
248 (progn (insert-file-contents file) t)
250 (defun nnheader-insert-file-contents-literally
251 (filename &optional visit beg end replace)
252 (let ((file-coding-system-for-read *noconv*))
253 (insert-file-contents-literally filename visit beg end replace)
255 ;; compatibility for September Gnus 0.80 .. 0.94
256 (fset 'nnheader-insert-raw-file-contents
257 'nnheader-insert-file-contents-literally)
258 (defun nnheader-find-file-noselect (filename &optional nowarn rawfile)
259 (let ((file-coding-system-for-read *noconv*))
260 (find-file-noselect filename nowarn rawfile)
263 (defun tm-gnus/prepare-save-mail-function ()
264 (setq file-coding-system *noconv*)
266 (add-hook 'nnmail-prepare-save-mail-hook
267 'tm-gnus/prepare-save-mail-function)
269 (gnus-set-newsgroup-default-coding-system "alt.chinese.text" *hz*)
270 (gnus-set-newsgroup-default-coding-system "alt.chinese.text.big5" *big5*)
271 (gnus-set-newsgroup-default-coding-system "han" *euc-kr*)
272 (and (boundp '*koi8*)
273 (gnus-set-newsgroup-default-coding-system "relcom" *koi8*))
280 (defun tm-gnus/decode-summary-from-and-subjects ()
281 (let ((rest gnus-newsgroup-default-coding-system-alist)
284 (while (setq cell (car rest))
285 (if (string-match (car cell) gnus-newsgroup-name)
288 (make-local-variable 'mime/default-coding-system)
289 (setq mime/default-coding-system (cdr cell))
291 (setq rest (cdr rest))
295 (let ((from (or (mail-header-from header) ""))
296 (subj (or (mail-header-subject header) ""))
297 (method (car gnus-current-select-method))
299 (if (eq method 'nntp)
302 (character-decode-string from mime/default-coding-system))
304 (character-decode-string subj mime/default-coding-system))
306 (mail-header-set-from
307 header (mime-eword/decode-string from))
308 (mail-header-set-subject
309 header (mime-eword/decode-string subj))
311 gnus-newsgroup-headers))
313 (or (boundp 'nnheader-encoded-words-decoding)
314 (add-hook 'gnus-select-group-hook
315 'tm-gnus/decode-summary-from-and-subjects)
328 (autoload 'tm-bbdb/update-record "tm-bbdb")
330 (defun tm-gnus/bbdb-setup ()
331 (if (memq 'bbdb/gnus-update-record gnus-article-prepare-hook)
333 (remove-hook 'gnus-article-prepare-hook 'bbdb/gnus-update-record)
334 (add-hook 'gnus-article-display-hook 'tm-bbdb/update-record)
337 (add-hook 'gnus-startup-hook 'tm-gnus/bbdb-setup t)
347 ;;; tm-sgnus.el ends here