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.43 1997-03-10 15:16:26 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)
44 (defvar mime/output-buffer-window-is-shared-with-bbdb t
45 "*If t, mime/output-buffer window is shared with BBDB window.")
51 (defconst mime/output-buffer-name "*MIME-out*")
52 (defconst mime/temp-buffer-name " *MIME-temp*")
55 ;;; @ definitions about MIME
58 (defconst mime/tspecials "][\000-\040()<>@,\;:\\\"/?.=")
59 (defconst mime/token-regexp (concat "[^" mime/tspecials "]+"))
60 (defconst mime-charset-regexp mime/token-regexp)
62 (defconst mime/content-type-subtype-regexp
63 (concat mime/token-regexp "/" mime/token-regexp))
65 (defconst mime/disposition-type-regexp mime/token-regexp)
75 (defvar mime-button-face 'bold
76 "Face used for content-button or URL-button of MIME-Preview buffer.")
78 (defvar mime-button-mouse-face 'highlight
79 "Face used for MIME-preview buffer mouse highlighting.")
81 (defun mime-add-button (from to func &optional data)
82 "Create a button between FROM and TO with callback FUNC and data DATA."
84 (overlay-put (make-overlay from to) 'face mime-button-face))
85 (add-text-properties from to
87 (and mime-button-mouse-face
88 (list 'mouse-face mime-button-mouse-face))
89 (list 'mime-button-callback func)
90 (and data (list 'mime-button-data data))
94 (defvar mime-button-mother-dispatcher nil)
96 (defun mime-button-dispatcher (event)
97 "Select the button under point."
99 (let (buf point func data)
100 (save-window-excursion
101 (mouse-set-point event)
102 (setq buf (current-buffer)
104 func (get-text-property (point) 'mime-button-callback)
105 data (get-text-property (point) 'mime-button-data)
113 (if (fboundp mime-button-mother-dispatcher)
114 (funcall mime-button-mother-dispatcher event)
122 (defvar pgp-function-alist
125 (verify mc-verify "mc-toplev")
126 (decrypt mc-decrypt "mc-toplev")
127 (fetch-key mc-pgp-fetch-key "mc-pgp")
128 (snarf-keys mc-snarf-keys "mc-toplev")
130 (mime-sign mime-mc-pgp-sign-region "mime-mc")
131 (traditional-sign mc-pgp-sign-region "mc-pgp")
132 (encrypt mime-mc-pgp-encrypt-region "mime-mc")
133 (insert-key mc-insert-public-key "mc-toplev")
135 "Alist of service names vs. corresponding functions and its filenames.
136 Each element looks like (SERVICE FUNCTION FILE).
138 SERVICE is a symbol of PGP processing. It allows `verify', `decrypt',
139 `fetch-key', `snarf-keys', `mime-sign', `traditional-sign', `encrypt'
142 Function is a symbol of function to do specified SERVICE.
144 FILE is string of filename which has definition of corresponding
147 (defmacro pgp-function (method)
148 "Return function to do service METHOD."
149 (` (car (cdr (assq (, method) (symbol-value 'pgp-function-alist)))))
154 (autoload (second method)(third method))
159 ;;; @ method selector kernel
167 (defun field-unifier-for-mode (a b)
179 ;; caesar-region written by phr@prep.ai.mit.edu Nov 86
180 ;; modified by tower@prep Nov 86
181 ;; gnus-caesar-region
182 ;; Modified by umerin@flab.flab.Fujitsu.JUNET for ROT47.
183 (defun tm:caesar-region (&optional n)
184 "Caesar rotation of region by N, default 13, for decrypting netnews.
185 ROT47 will be performed for Japanese text in any case."
186 (interactive (if current-prefix-arg ; Was there a prefix arg?
187 (list (prefix-numeric-value current-prefix-arg))
189 (cond ((not (numberp n)) (setq n 13))
190 (t (setq n (mod n 26)))) ;canonicalize N
191 (if (not (zerop n)) ; no action needed for a rot of 0
193 (if (or (not (boundp 'caesar-translate-table))
194 (/= (aref caesar-translate-table ?a) (+ ?a n)))
195 (let ((i 0) (lower "abcdefghijklmnopqrstuvwxyz") upper)
196 (message "Building caesar-translate-table...")
197 (setq caesar-translate-table (make-vector 256 0))
199 (aset caesar-translate-table i i)
201 (setq lower (concat lower lower) upper (upcase lower) i 0)
203 (aset caesar-translate-table (+ ?a i) (aref lower (+ i n)))
204 (aset caesar-translate-table (+ ?A i) (aref upper (+ i n)))
206 ;; ROT47 for Japanese text.
207 ;; Thanks to ichikawa@flab.fujitsu.junet.
209 (let ((t1 (logior ?O 128))
211 (t3 (logior ?~ 128)))
213 (aset caesar-translate-table i
214 (let ((v (aref caesar-translate-table i)))
215 (if (<= v t1) (if (< v t2) v (+ v 47))
216 (if (<= v t3) (- v 47) v))))
218 (message "Building caesar-translate-table...done")))
219 (let ((from (region-beginning))
222 (setq str (buffer-substring from to))
223 (setq len (length str))
225 (aset str i (aref caesar-translate-table (aref str i)))
228 (delete-region from to)
235 (defsubst regexp-or (&rest args)
236 (concat "\\(" (mapconcat (function identity) args "\\|") "\\)"))
238 (defun tm:set-fields (sym field-list &optional regexp-sym)
241 (let ((name (symbol-name sym)))
243 (concat (if (string-match "\\(.*\\)-list" name)
244 (substring name 0 (match-end 1))
251 (concat "^" (apply (function regexp-or) field-list) ":"))
254 (defun tm:add-fields (sym field-list &optional regexp-sym)
257 (let ((name (symbol-name sym)))
259 (concat (if (string-match "\\(.*\\)-list" name)
260 (substring name 0 (match-end 1))
265 (let ((fields (eval sym)))
268 (or (member field fields)
269 (setq fields (cons field fields))
275 (concat "^" (apply (function regexp-or) fields) ":"))
279 (defun tm:delete-fields (sym field-list &optional regexp-sym)
282 (let ((name (symbol-name sym)))
284 (concat (if (string-match "\\(.*\\)-list" name)
285 (substring name 0 (match-end 1))
290 (let ((fields (eval sym)))
293 (setq fields (delete field fields))
297 (concat "^" (apply (function regexp-or) fields) ":"))
305 (defsubst get-version-string (id)
306 "Return a version-string from RCS ID."
307 (and (string-match ",v \\([0-9][0-9.][0-9.]+\\)" id)
308 (substring id (match-beginning 1)(match-end 1))
315 (defsubst eliminate-top-spaces (string)
316 "Eliminate top sequence of space or tab in STRING."
317 (if (string-match "^[ \t]+" string)
318 (substring string (match-end 0))
321 (defun call-after-loaded (module func &optional hook-name)
322 "If MODULE is provided, then FUNC is called.
323 Otherwise func is set to MODULE-load-hook.
324 If optional argument HOOK-NAME is specified,
325 it is used as hook to set."
326 (if (featurep module)
329 (setq hook-name (intern (concat (symbol-name module) "-load-hook")))
331 (add-hook hook-name func)
340 ;;; mime-def.el ends here