Use `turn-on-mime-edit' instead of `mime-edit-mode'.
[elisp/semi.git] / mime-setup.el
1 ;;; mime-setup.el --- setup file for MIME 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.9 1997-03-07 14:30:34 morioka 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 (require 'alist)
31
32 (autoload 'turn-on-mime-edit "mime-edit"
33   "Unconditionally turn on MIME-Edit minor mode." t)
34
35 (autoload 'eword-decode-header "eword-decode"
36   "Decode MIME encoded-words in header fields." t)
37
38 (defun mime-setup-decode-message-header ()
39   (save-excursion
40     (save-restriction
41       (goto-char (point-min))
42       (narrow-to-region
43        (point-min)
44        (if (re-search-forward
45             (concat "^" (regexp-quote mail-header-separator) "$")
46             nil t)
47            (match-beginning 0)
48          (point-max)
49          ))
50       (eword-decode-header)
51       (set-buffer-modified-p nil)
52       )))
53
54 (add-hook 'mime-edit-mode-hook 'mime-setup-decode-message-header)
55
56
57 ;;; @ variables
58 ;;;
59
60 (defvar mime-setup-use-signature t
61   "If it is not nil, mime-setup sets up to use signature.el.
62 \[mime-setup.el]")
63
64 (defvar mime-setup-default-signature-key "\C-c\C-s"
65   "*Key to insert signature. [mime-setup.el]")
66
67 (defvar mime-setup-signature-key-alist '((mail-mode . "\C-c\C-w"))
68   "Alist of major-mode vs. key to insert signature. [mime-setup.el]")
69
70
71 ;;; @ for signature
72 ;;;
73
74 (defun mime-setup-set-signature-key ()
75   (let ((key (or (cdr (assq major-mode mime-setup-signature-key-alist))
76                  mime-setup-default-signature-key)))
77     (define-key (current-local-map) key (function insert-signature))
78     ))
79
80 (if mime-setup-use-signature
81     (progn
82       (autoload 'insert-signature "signature" "Insert signature" t)
83       (add-hook 'mime-edit-mode-hook 'mime-setup-set-signature-key)
84       (setq gnus-signature-file nil)
85       (setq mail-signature nil)
86       (setq message-signature nil)
87       ))
88
89
90 ;;; @ for mu-cite
91 ;;;
92
93 (add-hook 'mu-cite/pre-cite-hook 'eword-decode-header)
94
95
96 ;;; @ for mail-mode, RMAIL and VM
97 ;;;
98
99 (add-hook 'mail-setup-hook 'eword-decode-header)
100 (add-hook 'mail-setup-hook 'turn-on-mime-edit 'append)
101 (add-hook 'mail-send-hook  'mime-edit-maybe-translate)
102 (set-alist 'mime-edit-split-message-sender-alist
103            'mail-mode (function
104                        (lambda ()
105                          (interactive)
106                          (funcall send-mail-function)
107                          )))
108
109 ;;; @ for mh-e
110 ;;;
111
112 (defun mime-setup-mh-draft-setting ()
113   (turn-on-mime-edit)
114   (make-local-variable 'mail-header-separator)
115   (setq mail-header-separator "--------")
116   (save-excursion
117     (goto-char (point-min))
118     (setq buffer-read-only nil)
119     (if (re-search-forward "^-*$" nil t)
120         (progn
121           (replace-match mail-header-separator)
122           (set-buffer-modified-p (buffer-modified-p))
123           ))
124     ))
125
126 (add-hook 'mh-letter-mode-hook 'mime-setup-mh-draft-setting t)
127 (add-hook 'mh-before-send-letter-hook 'mime-edit-maybe-translate)
128
129
130 ;;; @ for message (September Gnus 0.58 or later)
131 ;;;
132
133 (defun message-maybe-setup-default-charset ()
134   (let ((charset
135          (and (boundp 'gnus-summary-buffer)
136               (buffer-live-p gnus-summary-buffer)
137               (save-excursion
138                 (set-buffer gnus-summary-buffer)
139                 default-mime-charset))))
140     (if charset
141         (progn
142           (make-local-variable 'default-mime-charset)
143           (setq default-mime-charset charset)
144           ))))
145
146 (or (boundp 'epoch::version)
147     (progn
148       (add-hook 'message-setup-hook  'turn-on-mime-edit)
149       (add-hook 'message-setup-hook  'message-maybe-setup-default-charset)
150       (add-hook 'message-send-hook   'mime-edit-maybe-translate)
151       (add-hook 'message-header-hook 'eword-encode-header)
152       
153       (call-after-loaded
154        'message
155        (function
156         (lambda ()
157           (require 'message-mime)
158           )))
159       ))
160
161
162 ;;; @ end
163 ;;;
164
165 (provide 'mime-setup)
166
167 (run-hooks 'mime-setup-load-hook)
168
169 ;;; mime-setup.el ends here