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.27 1997-02-27 08:05:45 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.
31 (defvar running-xemacs (string-match "XEmacs" emacs-version))
41 (defvar mime/tmp-dir (or (getenv "TM_TMP_DIR") "/tmp/"))
43 (defvar mime/use-multi-frame
44 (and (>= emacs-major-version 19) window-system))
46 (defvar mime/find-file-function
47 (if mime/use-multi-frame
48 (function find-file-other-frame)
52 (defvar mime/output-buffer-window-is-shared-with-bbdb t
53 "*If t, mime/output-buffer window is shared with BBDB window.")
59 (defconst mime/output-buffer-name "*MIME-out*")
60 (defconst mime/temp-buffer-name " *MIME-temp*")
66 (defvar mime-button-face 'bold
67 "Face used for content-button or URL-button of MIME-Preview buffer.")
69 (defvar mime-button-mouse-face 'highlight
70 "Face used for MIME-preview buffer mouse highlighting.")
72 (defun mime-add-button (from to func &optional data)
73 "Create a button between FROM and TO with callback FUNC and data DATA."
75 (overlay-put (make-overlay from to) 'face mime-button-face))
76 (add-text-properties from to
78 (and mime-button-mouse-face
79 (list 'mouse-face mime-button-mouse-face))
80 (list 'mime-button-callback func)
81 (and data (list 'mime-button-data data))
85 (defvar mime-button-mother-dispatcher nil)
87 (defun mime-button-dispatcher (event)
88 "Select the button under point."
90 (let (buf point func data)
91 (save-window-excursion
92 (mouse-set-point event)
93 (setq buf (current-buffer)
95 func (get-text-property (point) 'mime-button-callback)
96 data (get-text-property (point) 'mime-button-data)
104 (if (fboundp mime-button-mother-dispatcher)
105 (funcall mime-button-mother-dispatcher event)
113 (defvar pgp-function-alist
116 (verify mc-verify "mc-toplev")
117 (decrypt mc-decrypt "mc-toplev")
118 (fetch-key mc-pgp-fetch-key "mc-pgp")
119 (snarf-keys mc-snarf-keys "mc-toplev")
121 (mime-sign tm:mc-pgp-sign-region "mime-mc")
122 (traditional-sign mc-pgp-sign-region "mc-pgp")
123 (encrypt tm:mc-pgp-encrypt-region "mime-mc")
124 (insert-key mc-insert-public-key "mc-toplev")
126 "Alist of service names vs. corresponding functions and its filenames.
127 Each element looks like (SERVICE FUNCTION FILE).
129 SERVICE is a symbol of PGP processing. It allows `verify', `decrypt',
130 `fetch-key', `snarf-keys', `mime-sign', `traditional-sign', `encrypt'
133 Function is a symbol of function to do specified SERVICE.
135 FILE is string of filename which has definition of corresponding
138 (defmacro pgp-function (method)
139 "Return function to do service METHOD."
140 (` (car (cdr (assq (, method) (symbol-value 'pgp-function-alist)))))
145 (autoload (second method)(third method))
150 ;;; @ definitions about MIME
153 (defconst mime/tspecials "][\000-\040()<>@,\;:\\\"/?.=")
154 (defconst mime/token-regexp (concat "[^" mime/tspecials "]+"))
155 (defconst mime-charset-regexp mime/token-regexp)
157 (defconst mime/content-type-subtype-regexp
158 (concat mime/token-regexp "/" mime/token-regexp))
160 (defconst mime/disposition-type-regexp mime/token-regexp)
165 ;; caesar-region written by phr@prep.ai.mit.edu Nov 86
166 ;; modified by tower@prep Nov 86
167 ;; gnus-caesar-region
168 ;; Modified by umerin@flab.flab.Fujitsu.JUNET for ROT47.
169 (defun tm:caesar-region (&optional n)
170 "Caesar rotation of region by N, default 13, for decrypting netnews.
171 ROT47 will be performed for Japanese text in any case."
172 (interactive (if current-prefix-arg ; Was there a prefix arg?
173 (list (prefix-numeric-value current-prefix-arg))
175 (cond ((not (numberp n)) (setq n 13))
176 (t (setq n (mod n 26)))) ;canonicalize N
177 (if (not (zerop n)) ; no action needed for a rot of 0
179 (if (or (not (boundp 'caesar-translate-table))
180 (/= (aref caesar-translate-table ?a) (+ ?a n)))
181 (let ((i 0) (lower "abcdefghijklmnopqrstuvwxyz") upper)
182 (message "Building caesar-translate-table...")
183 (setq caesar-translate-table (make-vector 256 0))
185 (aset caesar-translate-table i i)
187 (setq lower (concat lower lower) upper (upcase lower) i 0)
189 (aset caesar-translate-table (+ ?a i) (aref lower (+ i n)))
190 (aset caesar-translate-table (+ ?A i) (aref upper (+ i n)))
192 ;; ROT47 for Japanese text.
193 ;; Thanks to ichikawa@flab.fujitsu.junet.
195 (let ((t1 (logior ?O 128))
197 (t3 (logior ?~ 128)))
199 (aset caesar-translate-table i
200 (let ((v (aref caesar-translate-table i)))
201 (if (<= v t1) (if (< v t2) v (+ v 47))
202 (if (<= v t3) (- v 47) v))))
204 (message "Building caesar-translate-table...done")))
205 (let ((from (region-beginning))
208 (setq str (buffer-substring from to))
209 (setq len (length str))
211 (aset str i (aref caesar-translate-table (aref str i)))
214 (delete-region from to)
221 (defsubst regexp-or (&rest args)
222 (concat "\\(" (mapconcat (function identity) args "\\|") "\\)"))
224 (defun tm:set-fields (sym field-list &optional regexp-sym)
227 (let ((name (symbol-name sym)))
229 (concat (if (string-match "\\(.*\\)-list" name)
230 (substring name 0 (match-end 1))
237 (concat "^" (apply (function regexp-or) field-list) ":"))
240 (defun tm:add-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))
251 (let ((fields (eval sym)))
254 (or (member field fields)
255 (setq fields (cons field fields))
261 (concat "^" (apply (function regexp-or) fields) ":"))
265 (defun tm:delete-fields (sym field-list &optional regexp-sym)
268 (let ((name (symbol-name sym)))
270 (concat (if (string-match "\\(.*\\)-list" name)
271 (substring name 0 (match-end 1))
276 (let ((fields (eval sym)))
279 (setq fields (delete field fields))
283 (concat "^" (apply (function regexp-or) fields) ":"))
291 (defsubst get-version-string (id)
292 "Return a version-string from RCS ID."
293 (and (string-match ",v \\([0-9][0-9.][0-9.]+\\)" id)
294 (substring id (match-beginning 1)(match-end 1))
303 ;;; mime-def.el ends here