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.12 1997-02-25 06:35:05 tmorioka 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.
34 (defvar mime/tmp-dir (or (getenv "TM_TMP_DIR") "/tmp/"))
36 (defvar mime/use-multi-frame
37 (and (>= emacs-major-version 19) window-system))
39 (defvar mime/find-file-function
40 (if mime/use-multi-frame
41 (function find-file-other-frame)
45 (defvar mime/output-buffer-window-is-shared-with-bbdb t
46 "*If t, mime/output-buffer window is shared with BBDB window.")
52 (defconst mime/output-buffer-name "*MIME-out*")
53 (defconst mime/temp-buffer-name " *MIME-temp*")
59 (defvar tm:button-face 'bold
60 "Face used for content-button or URL-button of MIME-Preview buffer.
63 (defvar tm:mouse-face 'highlight
64 "Face used for MIME-preview buffer mouse highlighting. [mime-def.el]")
66 (defun tm:add-button (from to func &optional data)
67 "Create a button between FROM and TO with callback FUNC and data DATA."
69 (tl:overlay-put (tl:make-overlay from to) 'face tm:button-face))
70 (tl:add-text-properties from to
71 (append (and tm:mouse-face
72 (list 'mouse-face tm:mouse-face))
73 (list 'mime-callback func)
74 (and data (list 'mime-data data))
78 (defvar tm:mother-button-dispatcher nil)
80 (defun tm:button-dispatcher (event)
81 "Select the button under point."
83 (let (buf point func data)
84 (save-window-excursion
85 (mouse-set-point event)
86 (setq buf (current-buffer)
88 func (get-text-property (point) 'mime-callback)
89 data (get-text-property (point) 'mime-data)
97 (if (fboundp tm:mother-button-dispatcher)
98 (funcall tm:mother-button-dispatcher event)
106 (defvar tm:URL-regexp
107 "\\(http\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*[-a-zA-Z0-9_=#$@~`%&*+|\\/]")
109 (defvar browse-url-browser-function nil)
111 (defun tm:browse-url (&optional url)
112 (if (fboundp browse-url-browser-function)
114 (funcall browse-url-browser-function url)
115 (call-interactively browse-url-browser-function))
116 (if (fboundp tm:mother-button-dispatcher)
117 (call-interactively tm:mother-button-dispatcher)
125 (defvar pgp-function-alist
128 (verify mc-verify "mc-toplev")
129 (decrypt mc-decrypt "mc-toplev")
130 (fetch-key mc-pgp-fetch-key "mc-pgp")
131 (snarf-keys mc-snarf-keys "mc-toplev")
133 (mime-sign tm:mc-pgp-sign-region "mime-edit-mc")
134 (traditional-sign mc-pgp-sign-region "mc-pgp")
135 (encrypt tm:mc-pgp-encrypt-region "mime-edit-mc")
136 (insert-key mc-insert-public-key "mc-toplev")
138 "Alist of service names vs. corresponding functions and its filenames.
139 Each element looks like (SERVICE FUNCTION FILE).
141 SERVICE is a symbol of PGP processing. It allows `verify', `decrypt',
142 `fetch-key', `snarf-keys', `mime-sign', `traditional-sign', `encrypt'
145 Function is a symbol of function to do specified SERVICE.
147 FILE is string of filename which has definition of corresponding
150 (defmacro pgp-function (method)
151 "Return function to do service METHOD."
152 (` (car (cdr (assq (, method) (symbol-value 'pgp-function-alist)))))
157 (autoload (second method)(third method))
162 ;;; @ definitions about MIME
165 (defconst mime/tspecials "][\000-\040()<>@,\;:\\\"/?.=")
166 (defconst mime/token-regexp (concat "[^" mime/tspecials "]+"))
167 (defconst mime-charset-regexp mime/token-regexp)
169 (defconst mime/content-type-subtype-regexp
170 (concat mime/token-regexp "/" mime/token-regexp))
172 (defconst mime/disposition-type-regexp mime/token-regexp)
177 ;; caesar-region written by phr@prep.ai.mit.edu Nov 86
178 ;; modified by tower@prep Nov 86
179 ;; gnus-caesar-region
180 ;; Modified by umerin@flab.flab.Fujitsu.JUNET for ROT47.
181 (defun tm:caesar-region (&optional n)
182 "Caesar rotation of region by N, default 13, for decrypting netnews.
183 ROT47 will be performed for Japanese text in any case."
184 (interactive (if current-prefix-arg ; Was there a prefix arg?
185 (list (prefix-numeric-value current-prefix-arg))
187 (cond ((not (numberp n)) (setq n 13))
188 (t (setq n (mod n 26)))) ;canonicalize N
189 (if (not (zerop n)) ; no action needed for a rot of 0
191 (if (or (not (boundp 'caesar-translate-table))
192 (/= (aref caesar-translate-table ?a) (+ ?a n)))
193 (let ((i 0) (lower "abcdefghijklmnopqrstuvwxyz") upper)
194 (message "Building caesar-translate-table...")
195 (setq caesar-translate-table (make-vector 256 0))
197 (aset caesar-translate-table i i)
199 (setq lower (concat lower lower) upper (upcase lower) i 0)
201 (aset caesar-translate-table (+ ?a i) (aref lower (+ i n)))
202 (aset caesar-translate-table (+ ?A i) (aref upper (+ i n)))
204 ;; ROT47 for Japanese text.
205 ;; Thanks to ichikawa@flab.fujitsu.junet.
207 (let ((t1 (logior ?O 128))
209 (t3 (logior ?~ 128)))
211 (aset caesar-translate-table i
212 (let ((v (aref caesar-translate-table i)))
213 (if (<= v t1) (if (< v t2) v (+ v 47))
214 (if (<= v t3) (- v 47) v))))
216 (message "Building caesar-translate-table...done")))
217 (let ((from (region-beginning))
220 (setq str (buffer-substring from to))
221 (setq len (length str))
223 (aset str i (aref caesar-translate-table (aref str i)))
226 (delete-region from to)
233 (defun tm:set-fields (sym field-list &optional regexp-sym)
236 (let ((name (symbol-name sym)))
238 (concat (if (string-match "\\(.*\\)-list" name)
239 (substring name 0 (match-end 1))
246 (concat "^" (apply (function regexp-or) field-list) ":"))
249 (defun tm:add-fields (sym field-list &optional regexp-sym)
252 (let ((name (symbol-name sym)))
254 (concat (if (string-match "\\(.*\\)-list" name)
255 (substring name 0 (match-end 1))
260 (let ((fields (eval sym)))
263 (or (member field fields)
264 (setq fields (cons field fields))
270 (concat "^" (apply (function regexp-or) fields) ":"))
274 (defun tm:delete-fields (sym field-list &optional regexp-sym)
277 (let ((name (symbol-name sym)))
279 (concat (if (string-match "\\(.*\\)-list" name)
280 (substring name 0 (match-end 1))
285 (let ((fields (eval sym)))
288 (setq fields (delete field fields))
292 (concat "^" (apply (function regexp-or) fields) ":"))
300 (defsubst get-version-string (id)
301 "Return a version-string from RCS ID."
302 (and (string-match ",v \\([0-9][0-9.][0-9.]+\\)" id)
303 (substring id (match-beginning 1)(match-end 1))
312 ;;; mime-def.el ends here