2 ;;; tm-def.el --- definition module for tm
4 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;;; Copyright (C) 1995 MORIOKA Tomohiko
7 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
9 ;;; $Id: tm-def.el,v 7.1 1995/11/10 10:43:15 morioka Exp $
10 ;;; Keywords: mail, news, MIME, multimedia, definition
12 ;;; This file is part of tm (Tools for MIME).
22 (defvar mime/tmp-dir (or (getenv "TM_TMP_DIR") "/tmp/"))
24 (defvar mime/use-multi-frame
25 (and (>= emacs-major-version 19) window-system))
27 (defvar mime/find-file-function
28 (if mime/use-multi-frame
29 (function find-file-other-frame)
37 (defconst mime/output-buffer-name "*MIME-out*")
38 (defconst mime/decoding-buffer-name "*MIME-decoding*")
41 ;;; @ for various Emacs variants
44 (cond ((boundp 'MULE) (require 'tm-mule))
45 ((boundp 'NEMACS)(require 'tm-nemacs))
46 (t (require 'tm-orig))
53 (defun tm:set-face-region (b e face)
54 (let ((overlay (tl:make-overlay b e)))
55 (tl:overlay-put overlay 'face face)
58 (setq tm:button-face 'bold)
59 (setq tm:mouse-face 'highlight)
61 (defun tm:add-button (from to func &optional data)
62 "Create a button between FROM and TO with callback FUNC and data DATA."
64 (tl:overlay-put (tl:make-overlay from to) 'face tm:button-face))
65 (tl:add-text-properties from to
66 (append (and tm:mouse-face
67 (list 'mouse-face tm:mouse-face))
68 (list 'tm-callback func)
69 (and data (list 'tm-data data))
73 (defvar tm:mother-button-dispatcher nil)
75 (defun tm:button-dispatcher (event)
76 "Select the button under point."
78 (mouse-set-point event)
79 (let ((func (get-text-property (point) 'tm-callback))
80 (data (get-text-property (point) 'tm-data))
84 (if (fboundp tm:mother-button-dispatcher)
85 (funcall tm:mother-button-dispatcher event)
94 "\\(http\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*[-a-zA-Z0-9_=#$@~`%&*+|\\/]")
96 (defvar browse-url-browser-function nil)
98 (defun tm:browse-url ()
99 (if (fboundp browse-url-browser-function)
100 (call-interactively browse-url-browser-function)
101 (if (fboundp tm:mother-button-dispatcher)
102 (call-interactively tm:mother-button-dispatcher)
107 ;;; @ definitions about MIME
110 (defconst mime/tspecials "][\000-\040()<>@,\;:\\\"/?.=")
111 (defconst mime/token-regexp (concat "[^" mime/tspecials "]+"))
112 (defconst mime/charset-regexp mime/token-regexp)
114 (defconst mime/content-type-subtype-regexp
115 (concat mime/token-regexp "/" mime/token-regexp))
116 (defconst mime/content-parameter-value-regexp
118 rfc822/quoted-string-regexp
125 (defconst base64-token-regexp "[A-Za-z0-9+/=]")
127 (defconst mime/B-encoded-text-regexp
134 (defconst mime/B-encoding-and-encoded-text-regexp
135 (concat "\\(B\\)\\?" mime/B-encoded-text-regexp))
138 ;;; @@ Quoted-Printable
141 (defconst quoted-printable-hex-chars "0123456789ABCDEF")
142 (defconst quoted-printable-octet-regexp
143 (concat "=[" quoted-printable-hex-chars
144 "][" quoted-printable-hex-chars "]"))
146 (defconst mime/Q-encoded-text-regexp
147 (concat "\\([^=?]\\|" quoted-printable-octet-regexp "\\)+"))
148 (defconst mime/Q-encoding-and-encoded-text-regexp
149 (concat "\\(Q\\)\\?" mime/Q-encoded-text-regexp))
154 ;; caesar-region written by phr@prep.ai.mit.edu Nov 86
155 ;; modified by tower@prep Nov 86
156 ;; gnus-caesar-region
157 ;; Modified by umerin@flab.flab.Fujitsu.JUNET for ROT47.
158 (defun tm:caesar-region (&optional n)
159 "Caesar rotation of region by N, default 13, for decrypting netnews.
160 ROT47 will be performed for Japanese text in any case."
161 (interactive (if current-prefix-arg ; Was there a prefix arg?
162 (list (prefix-numeric-value current-prefix-arg))
164 (cond ((not (numberp n)) (setq n 13))
165 (t (setq n (mod n 26)))) ;canonicalize N
166 (if (not (zerop n)) ; no action needed for a rot of 0
168 (if (or (not (boundp 'caesar-translate-table))
169 (/= (aref caesar-translate-table ?a) (+ ?a n)))
170 (let ((i 0) (lower "abcdefghijklmnopqrstuvwxyz") upper)
171 (message "Building caesar-translate-table...")
172 (setq caesar-translate-table (make-vector 256 0))
174 (aset caesar-translate-table i i)
176 (setq lower (concat lower lower) upper (upcase lower) i 0)
178 (aset caesar-translate-table (+ ?a i) (aref lower (+ i n)))
179 (aset caesar-translate-table (+ ?A i) (aref upper (+ i n)))
181 ;; ROT47 for Japanese text.
182 ;; Thanks to ichikawa@flab.fujitsu.junet.
184 (let ((t1 (logior ?O 128))
186 (t3 (logior ?~ 128)))
188 (aset caesar-translate-table i
189 (let ((v (aref caesar-translate-table i)))
190 (if (<= v t1) (if (< v t2) v (+ v 47))
191 (if (<= v t3) (- v 47) v))))
193 (message "Building caesar-translate-table...done")))
194 (let ((from (region-beginning))
197 (setq str (buffer-substring from to))
198 (setq len (length str))
200 (aset str i (aref caesar-translate-table (aref str i)))
203 (delete-region from to)