1 ;;; mime-def.el --- definition module for SEMI
3 ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: mime-def.el,v 0.46 1997-03-27 20:46:40 morioka Exp $
7 ;; Keywords: definition, MIME, multimedia, mail, news
9 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
35 (defvar mime/use-multi-frame
36 (and (>= emacs-major-version 19) window-system))
38 (defvar mime/find-file-function
39 (if mime/use-multi-frame
40 (function find-file-other-frame)
48 (defconst mime-echo-buffer-name "*MIME-echo*"
49 "Name of buffer to display MIME-playing information.")
51 (defconst mime/temp-buffer-name " *MIME-temp*")
54 ;;; @ definitions about MIME
57 (defconst mime/tspecials "][\000-\040()<>@,\;:\\\"/?.=")
58 (defconst mime/token-regexp (concat "[^" mime/tspecials "]+"))
59 (defconst mime-charset-regexp mime/token-regexp)
61 (defconst mime/content-type-subtype-regexp
62 (concat mime/token-regexp "/" mime/token-regexp))
64 (defconst mime/disposition-type-regexp mime/token-regexp)
74 (defvar mime-button-face 'bold
75 "Face used for content-button or URL-button of MIME-Preview buffer.")
77 (defvar mime-button-mouse-face 'highlight
78 "Face used for MIME-preview buffer mouse highlighting.")
80 (defsubst mime-add-button (from to func &optional data)
81 "Create a button between FROM and TO with callback FUNC and data DATA."
83 (overlay-put (make-overlay from to) 'face mime-button-face))
84 (let ((props (cons 'mime-button-callback
87 (list 'mime-button-data data)
89 (if mime-button-mouse-face
90 (setq props (cons 'mouse-face (cons mime-button-mouse-face props)))
92 (add-text-properties from to props)
95 (defvar mime-button-mother-dispatcher nil)
97 (defun mime-button-dispatcher (event)
98 "Select the button under point."
100 (let (buf point func data)
101 (save-window-excursion
102 (mouse-set-point event)
103 (setq buf (current-buffer)
105 func (get-text-property (point) 'mime-button-callback)
106 data (get-text-property (point) 'mime-button-data)
114 (if (fboundp mime-button-mother-dispatcher)
115 (funcall mime-button-mother-dispatcher event)
123 (defvar pgp-function-alist
126 (verify mc-verify "mc-toplev")
127 (decrypt mc-decrypt "mc-toplev")
128 (fetch-key mc-pgp-fetch-key "mc-pgp")
129 (snarf-keys mc-snarf-keys "mc-toplev")
131 (mime-sign mime-mc-pgp-sign-region "mime-mc")
132 (traditional-sign mc-pgp-sign-region "mc-pgp")
133 (encrypt mime-mc-pgp-encrypt-region "mime-mc")
134 (insert-key mc-insert-public-key "mc-toplev")
136 "Alist of service names vs. corresponding functions and its filenames.
137 Each element looks like (SERVICE FUNCTION FILE).
139 SERVICE is a symbol of PGP processing. It allows `verify', `decrypt',
140 `fetch-key', `snarf-keys', `mime-sign', `traditional-sign', `encrypt'
143 Function is a symbol of function to do specified SERVICE.
145 FILE is string of filename which has definition of corresponding
148 (defmacro pgp-function (method)
149 "Return function to do service METHOD."
150 (` (car (cdr (assq (, method) (symbol-value 'pgp-function-alist)))))
155 (autoload (second method)(third method))
160 ;;; @ method selector kernel
168 (defun field-unifier-for-mode (a b)
180 ;; caesar-region written by phr@prep.ai.mit.edu Nov 86
181 ;; modified by tower@prep Nov 86
182 ;; gnus-caesar-region
183 ;; Modified by umerin@flab.flab.Fujitsu.JUNET for ROT47.
184 (defun tm:caesar-region (&optional n)
185 "Caesar rotation of region by N, default 13, for decrypting netnews.
186 ROT47 will be performed for Japanese text in any case."
187 (interactive (if current-prefix-arg ; Was there a prefix arg?
188 (list (prefix-numeric-value current-prefix-arg))
190 (cond ((not (numberp n)) (setq n 13))
191 (t (setq n (mod n 26)))) ;canonicalize N
192 (if (not (zerop n)) ; no action needed for a rot of 0
194 (if (or (not (boundp 'caesar-translate-table))
195 (/= (aref caesar-translate-table ?a) (+ ?a n)))
196 (let ((i 0) (lower "abcdefghijklmnopqrstuvwxyz") upper)
197 (message "Building caesar-translate-table...")
198 (setq caesar-translate-table (make-vector 256 0))
200 (aset caesar-translate-table i i)
202 (setq lower (concat lower lower) upper (upcase lower) i 0)
204 (aset caesar-translate-table (+ ?a i) (aref lower (+ i n)))
205 (aset caesar-translate-table (+ ?A i) (aref upper (+ i n)))
207 ;; ROT47 for Japanese text.
208 ;; Thanks to ichikawa@flab.fujitsu.junet.
210 (let ((t1 (logior ?O 128))
212 (t3 (logior ?~ 128)))
214 (aset caesar-translate-table i
215 (let ((v (aref caesar-translate-table i)))
216 (if (<= v t1) (if (< v t2) v (+ v 47))
217 (if (<= v t3) (- v 47) v))))
219 (message "Building caesar-translate-table...done")))
220 (let ((from (region-beginning))
223 (setq str (buffer-substring from to))
224 (setq len (length str))
226 (aset str i (aref caesar-translate-table (aref str i)))
229 (delete-region from to)
236 (defsubst regexp-or (&rest args)
237 (concat "\\(" (mapconcat (function identity) args "\\|") "\\)"))
239 (defun tm:set-fields (sym field-list &optional regexp-sym)
242 (let ((name (symbol-name sym)))
244 (concat (if (string-match "\\(.*\\)-list" name)
245 (substring name 0 (match-end 1))
252 (concat "^" (apply (function regexp-or) field-list) ":"))
255 (defun tm:add-fields (sym field-list &optional regexp-sym)
258 (let ((name (symbol-name sym)))
260 (concat (if (string-match "\\(.*\\)-list" name)
261 (substring name 0 (match-end 1))
266 (let ((fields (eval sym)))
269 (or (member field fields)
270 (setq fields (cons field fields))
276 (concat "^" (apply (function regexp-or) fields) ":"))
280 (defun tm:delete-fields (sym field-list &optional regexp-sym)
283 (let ((name (symbol-name sym)))
285 (concat (if (string-match "\\(.*\\)-list" name)
286 (substring name 0 (match-end 1))
291 (let ((fields (eval sym)))
294 (setq fields (delete field fields))
298 (concat "^" (apply (function regexp-or) fields) ":"))
306 (defsubst get-version-string (id)
307 "Return a version-string from RCS ID."
308 (and (string-match ",v \\([0-9][0-9.][0-9.]+\\)" id)
309 (substring id (match-beginning 1)(match-end 1))
316 (defsubst eliminate-top-spaces (string)
317 "Eliminate top sequence of space or tab in STRING."
318 (if (string-match "^[ \t]+" string)
319 (substring string (match-end 0))
322 (defun call-after-loaded (module func &optional hook-name)
323 "If MODULE is provided, then FUNC is called.
324 Otherwise func is set to MODULE-load-hook.
325 If optional argument HOOK-NAME is specified,
326 it is used as hook to set."
327 (if (featurep module)
330 (setq hook-name (intern (concat (symbol-name module) "-load-hook")))
332 (add-hook hook-name func)
341 ;;; mime-def.el ends here