annotate lisp/mel/mel-q.el @ 8:4b173ad71786 r19-15b5

Import from CVS: tag r19-15b5
author cvs
date Mon, 13 Aug 2007 08:47:35 +0200
parents b82b59fe008d
children 49a24b4fd526
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1 ;;; mel-q.el: Quoted-Printable and Q-encoding encoder/decoder for GNU Emacs
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
2
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1995,1996 Free Software Foundation, Inc.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
6 ;; Created: 1995/6/25
8
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 4
diff changeset
7 ;; Version: $Id: mel-q.el,v 1.2 1996/12/22 00:29:16 steve Exp $
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
8 ;; Keywords: MIME, Quoted-Printable, Q-encoding
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
9
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
10 ;; This file is part of MEL (MIME Encoding Library).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
11
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
12 ;; This program is free software; you can redistribute it and/or
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
13 ;; modify it under the terms of the GNU General Public License as
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
14 ;; published by the Free Software Foundation; either version 2, or (at
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
15 ;; your option) any later version.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
16
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
17 ;; This program is distributed in the hope that it will be useful, but
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
20 ;; General Public License for more details.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
21
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
26
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
27 ;;; Code:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
28
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
29 (require 'emu)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
30
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
31
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
32 ;;; @ constants
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
33 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
34
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
35 (defconst quoted-printable-hex-chars "0123456789ABCDEF")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
36 (defconst quoted-printable-octet-regexp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
37 (concat "=[" quoted-printable-hex-chars
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
38 "][" quoted-printable-hex-chars "]"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
39
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
40
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
41 ;;; @ variables
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
42 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
43
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
44 (defvar quoted-printable-external-encoder '("mmencode" "-q")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
45 "*list of quoted-printable encoder program name and its arguments.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
46
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
47 (defvar quoted-printable-external-decoder '("mmencode" "-q" "-u")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
48 "*list of quoted-printable decoder program name and its arguments.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
49
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
50 (defvar quoted-printable-internal-encoding-limit 10000
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
51 "*limit size to use internal quoted-printable encoder.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
52 If size of input to encode is larger than this limit,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
53 external encoder is called.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
54
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
55 (defvar quoted-printable-internal-decoding-limit nil
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
56 "*limit size to use internal quoted-printable decoder.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
57 If size of input to decode is larger than this limit,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
58 external decoder is called.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
59
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
60
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
61 ;;; @ Quoted-Printable (Q-encode) encoder/decoder
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
62 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
63
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
64 (defun byte-to-hex-string (num)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
65 (concat (char-to-string (elt quoted-printable-hex-chars (ash num -4)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
66 (char-to-string (elt quoted-printable-hex-chars (logand num 15)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
67 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
68
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
69 (defun quoted-printable-quote-char (chr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
70 (concat "="
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
71 (char-to-string (elt quoted-printable-hex-chars (ash chr -4)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
72 (char-to-string (elt quoted-printable-hex-chars (logand chr 15)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
73 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
74
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
75
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
76 ;;; @@ Quoted-Printable encoder/decoder for string
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
77 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
78
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
79 (defun quoted-printable-encode-string (str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
80 (let ((i 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
81 (mapconcat (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
82 (lambda (chr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
83 (cond ((eq chr ?\n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
84 (setq i 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
85 "\n")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
86 ((or (< chr 32) (< 126 chr) (eq chr ?=))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
87 (if (>= i 73)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
88 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
89 (setq i 3)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
90 (concat "=\n" (quoted-printable-quote-char chr))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
91 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
92 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
93 (setq i (+ i 3))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
94 (quoted-printable-quote-char chr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
95 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
96 (t (if (>= i 75)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
97 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
98 (setq i 1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
99 (concat "=\n" (char-to-string chr))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
100 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
101 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
102 (setq i (1+ i))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
103 (char-to-string chr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
104 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
105 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
106 str "")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
107
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
108 (defun quoted-printable-decode-string (str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
109 (let (q h l)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
110 (mapconcat (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
111 (lambda (chr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
112 (cond ((eq chr ?=)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
113 (setq q t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
114 "")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
115 (q (setq h
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
116 (cond ((<= ?a chr) (+ (- chr ?a) 10))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
117 ((<= ?A chr) (+ (- chr ?A) 10))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
118 ((<= ?0 chr) (- chr ?0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
119 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
120 (setq q nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
121 "")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
122 (h (setq l (cond ((<= ?a chr) (+ (- chr ?a) 10))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
123 ((<= ?A chr) (+ (- chr ?A) 10))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
124 ((<= ?0 chr) (- chr ?0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
125 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
126 (prog1
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
127 (char-to-string (logior (ash h 4) l))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
128 (setq h nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
129 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
130 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
131 (t (char-to-string chr))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
132 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
133 str "")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
134
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
135
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
136 ;;; @@ Quoted-Printable encoder/decoder for region
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
137 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
138
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
139 (defun quoted-printable-internal-encode-region (beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
140 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
141 (save-restriction
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
142 (narrow-to-region beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
143 (let ((str (buffer-substring beg end)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
144 (delete-region beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
145 (insert (quoted-printable-encode-string str))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
146 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
147 (or (bolp)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
148 (insert "=\n")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
149 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
150 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
151
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
152 (defun quoted-printable-internal-decode-region (beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
153 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
154 (save-restriction
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
155 (narrow-to-region beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
156 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
157 (while (re-search-forward "=\n" nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
158 (replace-match "")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
159 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
160 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
161 (let (b e str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
162 (while (re-search-forward quoted-printable-octet-regexp nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
163 (setq b (match-beginning 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
164 (setq e (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
165 (setq str (buffer-substring b e))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
166 (delete-region b e)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
167 (insert (quoted-printable-decode-string str))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
168 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
169 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
170
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
171 (defun quoted-printable-external-encode-region (beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
172 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
173 (save-restriction
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
174 (narrow-to-region beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
175 (as-binary-process
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
176 (apply (function call-process-region)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
177 beg end (car quoted-printable-external-encoder)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
178 t t nil (cdr quoted-printable-external-encoder))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
179 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
180 ;; for OS/2
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
181 ;; regularize line break code
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
182 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
183 (while (re-search-forward "\r$" nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
184 (replace-match "")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
185 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
186 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
187
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
188 (defun quoted-printable-external-decode-region (beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
189 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
190 (as-binary-process
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
191 (apply (function call-process-region)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
192 beg end (car quoted-printable-external-decoder)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
193 t t nil (cdr quoted-printable-external-decoder))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
194 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
195
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
196 (defun quoted-printable-encode-region (beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
197 (interactive "r")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
198 (if (and quoted-printable-internal-encoding-limit
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
199 (> (- end beg) quoted-printable-internal-encoding-limit))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
200 (quoted-printable-external-encode-region beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
201 (quoted-printable-internal-encode-region beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
202 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
203
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
204 (defun quoted-printable-decode-region (beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
205 (interactive "r")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
206 (if (and quoted-printable-internal-decoding-limit
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
207 (> (- end beg) quoted-printable-internal-decoding-limit))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
208 (quoted-printable-external-decode-region beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
209 (quoted-printable-internal-decode-region beg end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
210 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
211
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
212
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
213 ;;; @@ Quoted-Printable encoder/decoder for file
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
214 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
215
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
216 (defun quoted-printable-insert-encoded-file (filename)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
217 (interactive (list (read-file-name "Insert encoded file: ")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
218 (apply (function call-process) (car quoted-printable-external-encoder)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
219 filename t nil (cdr quoted-printable-external-encoder))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
220 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
221
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
222
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
223 ;;; @ Q-encoding encode/decode string
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
224 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
225
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
226 (defconst q-encoding-special-chars-alist
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
227 '((text ?= ?? ?_)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
228 (comment ?= ?? ?_ ?\( ?\) ?\\)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
229 (phrase ?= ?? ?_ ?\( ?\) ?\\ ?\" ?# ?$ ?% ?& ?' ?, ?. ?/
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
230 ?: ?\; ?< ?> ?@ ?\[ ?\] ?^ ?` ?{ ?| ?} ?~)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
231 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
232
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
233 (defun q-encoding-encode-string (str &optional mode)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
234 (let ((specials (cdr (or (assq mode q-encoding-special-chars-alist)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
235 (assq 'phrase q-encoding-special-chars-alist)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
236 ))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
237 (mapconcat (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
238 (lambda (chr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
239 (cond ((eq chr 32) "_")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
240 ((or (< chr 32) (< 126 chr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
241 (memq chr specials)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
242 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
243 (quoted-printable-quote-char chr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
244 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
245 (t
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
246 (char-to-string chr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
247 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
248 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
249 str "")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
250 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
251
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
252 (defun q-encoding-decode-string (str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
253 (let (q h l)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
254 (mapconcat (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
255 (lambda (chr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
256 (cond ((eq chr ?_) " ")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
257 ((eq chr ?=)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
258 (setq q t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
259 "")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
260 (q (setq h (cond ((<= ?a chr) (+ (- chr ?a) 10))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
261 ((<= ?A chr) (+ (- chr ?A) 10))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
262 ((<= ?0 chr) (- chr ?0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
263 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
264 (setq q nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
265 "")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
266 (h (setq l (cond ((<= ?a chr) (+ (- chr ?a) 10))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
267 ((<= ?A chr) (+ (- chr ?A) 10))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
268 ((<= ?0 chr) (- chr ?0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
269 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
270 (prog1
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
271 (char-to-string (logior (ash h 4) l))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
272 (setq h nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
273 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
274 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
275 (t (char-to-string chr))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
276 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
277 str "")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
278
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
279
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
280 ;;; @@ etc
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
281 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
282
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
283 (defun q-encoding-printable-char-p (chr mode)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
284 (and (not (memq chr '(?= ?? ?_)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
285 (<= ?\ chr)(<= chr ?~)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
286 (cond ((eq mode 'text) t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
287 ((eq mode 'comment)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
288 (not (memq chr '(?\( ?\) ?\\)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
289 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
290 (t
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
291 (string-match "[A-Za-z0-9!*+/=_---]" (char-to-string chr))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
292 ))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
293
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
294 (defun q-encoding-encoded-length (string &optional mode)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
295 (let ((l 0)(i 0)(len (length string)) chr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
296 (while (< i len)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
297 (setq chr (elt string i))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
298 (if (q-encoding-printable-char-p chr mode)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
299 (setq l (+ l 1))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
300 (setq l (+ l 3))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
301 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
302 (setq i (+ i 1)) )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
303 l))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
304
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
305
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
306 ;;; @ end
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
307 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
308
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
309 (provide 'mel-q)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
310
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
311 ;;; mel-q.el ends here