90c6687291a5bfbe2018b535eedb25b4309f9e44
[elisp/semi.git] / mime-setup.el
1 ;;; mime-setup.el --- setup file for tm viewer and composer.
2
3 ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version:
7 ;;      $Id: mime-setup.el,v 0.5 1997-02-24 01:32:33 tmorioka Exp $
8 ;; Keywords: MIME, multimedia, multilingual, mail, news
9
10 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
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 GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Code:
28
29 (require 'semi-setup)
30
31 (autoload 'mime-edit-mode "mime-edit"
32   "Minor mode for editing MIME message." t)
33 (autoload 'eword-decode-message-header "eword-decode"
34   "Decode MIME encoded-words in message header." t)
35
36 (defun mime-setup-decode-message-header ()
37   (save-excursion
38     (save-restriction
39       (goto-char (point-min))
40       (narrow-to-region
41        (point-min)
42        (if (re-search-forward
43             (concat "^" (regexp-quote mail-header-separator) "$")
44             nil t)
45            (match-beginning 0)
46          (point-max)
47          ))
48       (eword-decode-message-header)
49       (set-buffer-modified-p nil)
50       )))
51
52 (add-hook 'mime-edit-mode-hook 'mime-setup-decode-message-header)
53
54
55 ;;; @ variables
56 ;;;
57
58 (defvar mime-setup-use-signature t
59   "If it is not nil, mime-setup sets up to use signature.el.
60 \[mime-setup.el]")
61
62 (defvar mime-setup-default-signature-key "\C-c\C-s"
63   "*Key to insert signature. [mime-setup.el]")
64
65 (defvar mime-setup-signature-key-alist '((mail-mode . "\C-c\C-w"))
66   "Alist of major-mode vs. key to insert signature. [mime-setup.el]")
67
68
69 ;;; @ for signature
70 ;;;
71
72 (defun mime-setup-set-signature-key ()
73   (let ((key (or (cdr (assq major-mode mime-setup-signature-key-alist))
74                  mime-setup-default-signature-key)))
75     (define-key (current-local-map) key (function insert-signature))
76     ))
77
78 (if mime-setup-use-signature
79     (progn
80       (autoload 'insert-signature "signature" "Insert signature" t)
81       (add-hook 'mime-edit-mode-hook 'mime-setup-set-signature-key)
82       (setq gnus-signature-file nil)
83       (setq mail-signature nil)
84       (setq message-signature nil)
85       ))
86
87
88 ;;; @ for mu-cite
89 ;;;
90
91 (add-hook 'mu-cite/pre-cite-hook 'eword-decode-message-header)
92
93
94 ;;; @ for mail-mode, RMAIL and VM
95 ;;;
96
97 (add-hook 'mail-setup-hook 'eword-decode-message-header)
98 (add-hook 'mail-setup-hook 'mime-edit-mode 'append)
99 (add-hook 'mail-send-hook  'mime-edit-maybe-translate)
100 (set-alist 'mime-edit-split-message-sender-alist
101            'mail-mode (function
102                        (lambda ()
103                          (interactive)
104                          (funcall send-mail-function)
105                          )))
106
107 ;;; @ for mh-e
108 ;;;
109
110 (defun mime-setup-mh-draft-setting ()
111   (mime-edit-mode)
112   (make-local-variable 'mail-header-separator)
113   (setq mail-header-separator "--------")
114   (save-excursion
115     (goto-char (point-min))
116     (setq buffer-read-only nil)
117     (if (re-search-forward "^-*$" nil t)
118         (progn
119           (replace-match mail-header-separator)
120           (set-buffer-modified-p (buffer-modified-p))
121           ))
122     ))
123
124 (add-hook 'mh-letter-mode-hook 'mime-setup-mh-draft-setting t)
125 (add-hook 'mh-before-send-letter-hook 'mime-edit-maybe-translate)
126
127
128 ;;; @ for message (September Gnus 0.58 or later)
129 ;;;
130
131 (defun message-maybe-setup-default-charset ()
132   (let ((charset
133          (and (boundp 'gnus-summary-buffer)
134               (buffer-live-p gnus-summary-buffer)
135               (save-excursion
136                 (set-buffer gnus-summary-buffer)
137                 default-mime-charset))))
138     (if charset
139         (progn
140           (make-local-variable 'default-mime-charset)
141           (setq default-mime-charset charset)
142           ))))
143
144 (or (boundp 'epoch::version)
145     (progn
146       (add-hook 'message-setup-hook 'mime-edit-mode)
147       (add-hook 'message-setup-hook 'message-maybe-setup-default-charset)
148       (add-hook 'message-send-hook  'mime-edit-maybe-translate)
149       (add-hook 'message-header-hook 'mime/encode-message-header)
150       
151       (call-after-loaded
152        'message
153        (function
154         (lambda ()
155           (require 'message-mime)
156           )))
157       ))
158
159
160 ;;; @ end
161 ;;;
162
163 (provide 'mime-setup)
164
165 (run-hooks 'mime-setup-load-hook)
166
167 ;;; mime-setup.el ends here