66fbf61d8538ded444663fb51ed9375f1c15b159
[elisp/tm.git] / gnus / gnus-mime.el
1 ;;; gnus-mime.el --- MIME extensions for Gnus
2
3 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Created: 1996/8/6
7 ;; Version: $Revision: 0.4 $
8 ;; Keywords: news, MIME, multimedia, multilingual, encoded-word
9
10 ;; This file is not part of GNU Emacs yet.
11
12 ;; This program is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
16
17 ;; This program is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with This program.  If not, write to the Free Software
24 ;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25
26 ;;; Code:
27
28 (defun call-after-loaded (module func &optional hook-name)
29   "If MODULE is provided, then FUNC is called.
30 Otherwise func is set to MODULE-load-hook.
31 If optional argument HOOK-NAME is specified,
32 it is used as hook to set. [gnus-mime.el]"
33   (if (featurep module)
34       (funcall func)
35     (progn
36       (if (null hook-name)
37           (setq hook-name
38                 (intern (concat (symbol-name module) "-load-hook")))
39         )
40       (add-hook hook-name func)
41       )))
42
43 (defun get-version-string (id)
44   "Return a version-string from RCS ID. [gnus-mime.el]"
45   (and (string-match ",v \\([0-9][0-9.][0-9.]+\\)" id)
46        (substring id (match-beginning 1)(match-end 1))
47        ))
48
49
50 ;;; @ version
51 ;;;
52
53 (defconst gnus-mime-RCS-ID
54   "$Id: gnus-mime.el,v 0.4 1996/08/12 08:57:33 morioka Exp $")
55
56 (defconst gnus-mime-version
57   (get-version-string gnus-mime-RCS-ID))
58
59
60 ;;; @ variables
61 ;;;
62
63 (defvar gnus-show-mime t
64   "*If non-nil, do mime processing of articles.
65 The articles will simply be fed to the function given by
66 `gnus-show-mime-method'.")
67
68 (defvar gnus-show-mime-method 'gnus-article-preview-mime-message
69   "*Function to process a MIME message.
70 The function is called from the article buffer.")
71
72 (defvar gnus-decode-encoded-word-method 'gnus-article-decode-encoded-word
73   "*Function to decode a MIME encoded-words.
74 The function is called from the article buffer.")
75
76 (defvar gnus-parse-headers-hook
77   '(gnus-set-summary-default-charset gnus-decode-rfc1522)
78   "*A hook called before parsing the headers.")
79
80
81 ;;; @ load
82 ;;;
83
84 (require 'gnus)
85 (autoload 'gnus-decode-rfc1522               "gnus-art-mime")
86 (autoload 'gnus-article-preview-mime-message "gnus-art-mime")
87 (autoload 'gnus-article-decode-encoded-word  "gnus-art-mime")
88 (autoload 'gnus-set-summary-default-charset  "gnus-sum-mime")
89 (require 'gnus-charset)
90
91
92 ;;; @ for tm-view
93 ;;;
94
95 (defun gnus-content-header-filter ()
96   (goto-char (point-min))
97   (mime-preview/cut-header)
98   (decode-mime-charset-region (point-min)(point-max) default-mime-charset)
99   (mime/decode-message-header)
100   )
101
102 (set-alist 'mime-viewer/content-header-filter-alist
103            'gnus-original-article-mode
104            (function gnus-content-header-filter))
105
106
107 (set-alist 'mime-viewer/code-converter-alist
108            'gnus-original-article-mode
109            (function mime-charset/decode-buffer))
110
111
112 (defun mime-viewer/quitting-method-for-gnus ()
113   (if (not gnus-show-mime)
114       (mime-viewer/kill-buffer))
115   (delete-other-windows)
116   (gnus-article-show-summary)
117   (if (or (not gnus-show-mime)
118           (null gnus-have-all-headers))
119       (gnus-summary-select-article nil t)
120     ))
121
122 (set-alist 'mime-viewer/quitting-method-alist
123            'gnus-original-article-mode
124            (function mime-viewer/quitting-method-for-gnus))
125 (set-alist 'mime-viewer/show-summary-method
126            'gnus-original-article-mode
127            (function mime-viewer/quitting-method-for-gnus))
128
129
130 ;;; @ for tm-partial
131 ;;;
132
133 (defun gnus-mime-partial-preview-function ()
134   (gnus-summary-preview-mime-message (gnus-summary-article-number))
135   )
136
137 (call-after-loaded
138  'tm-partial
139  (function
140   (lambda ()
141     (set-atype 'mime/content-decoding-condition
142                '((type . "message/partial")
143                  (method . mime-article/grab-message/partials)
144                  (major-mode . gnus-original-article-mode)
145                  (summary-buffer-exp . gnus-summary-buffer)
146                  ))
147     (set-alist 'tm-partial/preview-article-method-alist
148                'gnus-original-article-mode
149                'gnus-mime-partial-preview-function)
150     )))
151
152
153 ;;; @ for tm-edit
154 ;;;
155
156 ;;; modified by Steven L. Baur <steve@miranova.com>
157 ;;;     1995/12/6 (c.f. [tm-en:209])
158 (defun mime-editor/attach-to-news-reply-menu ()
159   "Arrange to attach MIME editor's popup menu to VM's"
160   (if (boundp 'news-reply-menu)
161       (progn
162         (setq news-reply-menu (append news-reply-menu
163                                       '("---")
164                                       mime-editor/popup-menu-for-xemacs))
165         (remove-hook 'news-setup-hook
166                      'mime-editor/attach-to-news-reply-menu)
167         )))
168
169 (call-after-loaded
170  'tm-edit
171  (function
172   (lambda ()
173     (if (string-match "XEmacs\\|Lucid" emacs-version)
174         (add-hook 'news-setup-hook 'mime-editor/attach-to-news-reply-menu)
175       )
176     )))
177
178
179 ;;; @ end
180 ;;;
181
182 (provide 'gnus-mime)
183
184 (or (featurep 'gnus-load)
185     (progn
186       ;; for Gnus 5.0 .. 5.3
187       (provide 'gnus-sum)
188       (provide 'gnus-art)
189       
190       (or (boundp 'gnus-original-article-buffer)
191           (progn
192             ;; for Gnus 5.0.* and 5.1
193             (defvar gnus-original-article-buffer " *Original Article*")
194             
195             (defun gnus-article-setup-original-article-buffer ()
196               (save-excursion
197                 (set-buffer (get-buffer-create gnus-original-article-buffer))
198                 (erase-buffer)
199                 (insert-buffer gnus-article-buffer)
200                 (setq major-mode 'gnus-original-article-mode)
201                 ))
202             
203             (add-hook 'gnus-article-prepare-hook
204                       'gnus-article-setup-original-article-buffer)
205             
206             (setq gnus-strict-mime nil)
207             ))
208       ))
209
210 (run-hooks 'gnus-mime-load-hook)
211
212 ;;; gnus-mime.el ends here