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.39 1997-03-03 17:25:51 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/tmp-dir (or (getenv "TM_TMP_DIR") "/tmp/"))
37 (defvar mime/use-multi-frame
38 (and (>= emacs-major-version 19) window-system))
40 (defvar mime/find-file-function
41 (if mime/use-multi-frame
42 (function find-file-other-frame)
46 (defvar mime/output-buffer-window-is-shared-with-bbdb t
47 "*If t, mime/output-buffer window is shared with BBDB window.")
53 (defconst mime/output-buffer-name "*MIME-out*")
54 (defconst mime/temp-buffer-name " *MIME-temp*")
57 ;;; @ definitions about MIME
60 (defconst mime/tspecials "][\000-\040()<>@,\;:\\\"/?.=")
61 (defconst mime/token-regexp (concat "[^" mime/tspecials "]+"))
62 (defconst mime-charset-regexp mime/token-regexp)
64 (defconst mime/content-type-subtype-regexp
65 (concat mime/token-regexp "/" mime/token-regexp))
67 (defconst mime/disposition-type-regexp mime/token-regexp)
77 (defvar mime-button-face 'bold
78 "Face used for content-button or URL-button of MIME-Preview buffer.")
80 (defvar mime-button-mouse-face 'highlight
81 "Face used for MIME-preview buffer mouse highlighting.")
83 (defun mime-add-button (from to func &optional data)
84 "Create a button between FROM and TO with callback FUNC and data DATA."
86 (overlay-put (make-overlay from to) 'face mime-button-face))
87 (add-text-properties from to
89 (and mime-button-mouse-face
90 (list 'mouse-face mime-button-mouse-face))
91 (list 'mime-button-callback func)
92 (and data (list 'mime-button-data data))
96 (defvar mime-button-mother-dispatcher nil)
98 (defun mime-button-dispatcher (event)
99 "Select the button under point."
101 (let (buf point func data)
102 (save-window-excursion
103 (mouse-set-point event)
104 (setq buf (current-buffer)
106 func (get-text-property (point) 'mime-button-callback)
107 data (get-text-property (point) 'mime-button-data)
115 (if (fboundp mime-button-mother-dispatcher)
116 (funcall mime-button-mother-dispatcher event)
124 (defvar pgp-function-alist
127 (verify mc-verify "mc-toplev")
128 (decrypt mc-decrypt "mc-toplev")
129 (fetch-key mc-pgp-fetch-key "mc-pgp")
130 (snarf-keys mc-snarf-keys "mc-toplev")
132 (mime-sign tm:mc-pgp-sign-region "mime-mc")
133 (traditional-sign mc-pgp-sign-region "mc-pgp")
134 (encrypt tm:mc-pgp-encrypt-region "mime-mc")
135 (insert-key mc-insert-public-key "mc-toplev")
137 "Alist of service names vs. corresponding functions and its filenames.
138 Each element looks like (SERVICE FUNCTION FILE).
140 SERVICE is a symbol of PGP processing. It allows `verify', `decrypt',
141 `fetch-key', `snarf-keys', `mime-sign', `traditional-sign', `encrypt'
144 Function is a symbol of function to do specified SERVICE.
146 FILE is string of filename which has definition of corresponding
149 (defmacro pgp-function (method)
150 "Return function to do service METHOD."
151 (` (car (cdr (assq (, method) (symbol-value 'pgp-function-alist)))))
156 (autoload (second method)(third method))
161 ;;; @ method selector kernel
169 (defun field-unifier-for-mode (a b)
181 ;; caesar-region written by phr@prep.ai.mit.edu Nov 86
182 ;; modified by tower@prep Nov 86
183 ;; gnus-caesar-region
184 ;; Modified by umerin@flab.flab.Fujitsu.JUNET for ROT47.
185 (defun tm:caesar-region (&optional n)
186 "Caesar rotation of region by N, default 13, for decrypting netnews.
187 ROT47 will be performed for Japanese text in any case."
188 (interactive (if current-prefix-arg ; Was there a prefix arg?
189 (list (prefix-numeric-value current-prefix-arg))
191 (cond ((not (numberp n)) (setq n 13))
192 (t (setq n (mod n 26)))) ;canonicalize N
193 (if (not (zerop n)) ; no action needed for a rot of 0
195 (if (or (not (boundp 'caesar-translate-table))
196 (/= (aref caesar-translate-table ?a) (+ ?a n)))
197 (let ((i 0) (lower "abcdefghijklmnopqrstuvwxyz") upper)
198 (message "Building caesar-translate-table...")
199 (setq caesar-translate-table (make-vector 256 0))
201 (aset caesar-translate-table i i)
203 (setq lower (concat lower lower) upper (upcase lower) i 0)
205 (aset caesar-translate-table (+ ?a i) (aref lower (+ i n)))
206 (aset caesar-translate-table (+ ?A i) (aref upper (+ i n)))
208 ;; ROT47 for Japanese text.
209 ;; Thanks to ichikawa@flab.fujitsu.junet.
211 (let ((t1 (logior ?O 128))
213 (t3 (logior ?~ 128)))
215 (aset caesar-translate-table i
216 (let ((v (aref caesar-translate-table i)))
217 (if (<= v t1) (if (< v t2) v (+ v 47))
218 (if (<= v t3) (- v 47) v))))
220 (message "Building caesar-translate-table...done")))
221 (let ((from (region-beginning))
224 (setq str (buffer-substring from to))
225 (setq len (length str))
227 (aset str i (aref caesar-translate-table (aref str i)))
230 (delete-region from to)
237 (defsubst regexp-or (&rest args)
238 (concat "\\(" (mapconcat (function identity) args "\\|") "\\)"))
240 (defun tm:set-fields (sym field-list &optional regexp-sym)
243 (let ((name (symbol-name sym)))
245 (concat (if (string-match "\\(.*\\)-list" name)
246 (substring name 0 (match-end 1))
253 (concat "^" (apply (function regexp-or) field-list) ":"))
256 (defun tm:add-fields (sym field-list &optional regexp-sym)
259 (let ((name (symbol-name sym)))
261 (concat (if (string-match "\\(.*\\)-list" name)
262 (substring name 0 (match-end 1))
267 (let ((fields (eval sym)))
270 (or (member field fields)
271 (setq fields (cons field fields))
277 (concat "^" (apply (function regexp-or) fields) ":"))
281 (defun tm:delete-fields (sym field-list &optional regexp-sym)
284 (let ((name (symbol-name sym)))
286 (concat (if (string-match "\\(.*\\)-list" name)
287 (substring name 0 (match-end 1))
292 (let ((fields (eval sym)))
295 (setq fields (delete field fields))
299 (concat "^" (apply (function regexp-or) fields) ":"))
307 (defsubst get-version-string (id)
308 "Return a version-string from RCS ID."
309 (and (string-match ",v \\([0-9][0-9.][0-9.]+\\)" id)
310 (substring id (match-beginning 1)(match-end 1))
317 (defsubst eliminate-top-spaces (string)
318 "Eliminate top sequence of space or tab in STRING."
319 (if (string-match "^[ \t]+" string)
320 (substring string (match-end 0))
323 (defun call-after-loaded (module func &optional hook-name)
324 "If MODULE is provided, then FUNC is called.
325 Otherwise func is set to MODULE-load-hook.
326 If optional argument HOOK-NAME is specified,
327 it is used as hook to set."
328 (if (featurep module)
331 (setq hook-name (intern (concat (symbol-name module) "-load-hook")))
333 (add-hook hook-name func)
342 ;;; mime-def.el ends here