Mercurial > hg > xemacs-beta
comparison lisp/mel/mel-q.el @ 155:43dd3413c7c7 r20-3b4
Import from CVS: tag r20-3b4
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:39:39 +0200 |
parents | c0c698873ce1 |
children | 15872534500d |
comparison
equal
deleted
inserted
replaced
154:94141801dd7e | 155:43dd3413c7c7 |
---|---|
1 ;;; mel-q.el: Quoted-Printable and Q-encoding encoder/decoder for GNU Emacs | 1 ;;; mel-q.el: Quoted-Printable and Q-encoding encoder/decoder for GNU Emacs |
2 | 2 |
3 ;; Copyright (C) 1995,1996 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp> | 5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp> |
6 ;; Created: 1995/6/25 | 6 ;; Created: 1995/6/25 |
7 ;; Version: $Id: mel-q.el,v 1.2 1996/12/28 21:02:56 steve Exp $ | 7 ;; Version: $Id: mel-q.el,v 1.3 1997/06/06 00:57:14 steve Exp $ |
8 ;; Keywords: MIME, Quoted-Printable, Q-encoding | 8 ;; Keywords: MIME, Quoted-Printable, Q-encoding |
9 | 9 |
10 ;; This file is part of MEL (MIME Encoding Library). | 10 ;; This file is part of MEL (MIME Encoding Library). |
11 | 11 |
12 ;; This program is free software; you can redistribute it and/or | 12 ;; This program is free software; you can redistribute it and/or |
74 | 74 |
75 | 75 |
76 ;;; @@ Quoted-Printable encoder/decoder for string | 76 ;;; @@ Quoted-Printable encoder/decoder for string |
77 ;;; | 77 ;;; |
78 | 78 |
79 (defun quoted-printable-encode-string (str) | 79 (defun quoted-printable-encode-string (string) |
80 "Encode STRING to quoted-printable, and return the result." | |
80 (let ((i 0)) | 81 (let ((i 0)) |
81 (mapconcat (function | 82 (mapconcat (function |
82 (lambda (chr) | 83 (lambda (chr) |
83 (cond ((eq chr ?\n) | 84 (cond ((eq chr ?\n) |
84 (setq i 0) | 85 (setq i 0) |
101 (progn | 102 (progn |
102 (setq i (1+ i)) | 103 (setq i (1+ i)) |
103 (char-to-string chr) | 104 (char-to-string chr) |
104 ))) | 105 ))) |
105 ))) | 106 ))) |
106 str ""))) | 107 string ""))) |
107 | 108 |
108 (defun quoted-printable-decode-string (str) | 109 (defun quoted-printable-decode-string (string) |
110 "Decode STRING which is encoded in quoted-printable, and return the result." | |
109 (let (q h l) | 111 (let (q h l) |
110 (mapconcat (function | 112 (mapconcat (function |
111 (lambda (chr) | 113 (lambda (chr) |
112 (cond ((eq chr ?=) | 114 (cond ((eq chr ?=) |
113 (setq q t) | 115 (setq q t) |
128 (setq h nil) | 130 (setq h nil) |
129 ) | 131 ) |
130 ) | 132 ) |
131 (t (char-to-string chr)) | 133 (t (char-to-string chr)) |
132 ))) | 134 ))) |
133 str ""))) | 135 string ""))) |
134 | 136 |
135 | 137 |
136 ;;; @@ Quoted-Printable encoder/decoder for region | 138 ;;; @@ Quoted-Printable encoder/decoder for region |
137 ;;; | 139 ;;; |
138 | 140 |
192 beg end (car quoted-printable-external-decoder) | 194 beg end (car quoted-printable-external-decoder) |
193 t t nil (cdr quoted-printable-external-decoder)) | 195 t t nil (cdr quoted-printable-external-decoder)) |
194 ))) | 196 ))) |
195 | 197 |
196 (defun quoted-printable-encode-region (beg end) | 198 (defun quoted-printable-encode-region (beg end) |
199 "Encode current region by quoted-printable. | |
200 START and END are buffer positions. | |
201 This function calls internal quoted-printable encoder if size of | |
202 region is smaller than `quoted-printable-internal-encoding-limit', | |
203 otherwise it calls external quoted-printable encoder specified by | |
204 `quoted-printable-external-encoder'. In this case, you must install | |
205 the program (maybe mmencode included in metamail or XEmacs package)." | |
197 (interactive "r") | 206 (interactive "r") |
198 (if (and quoted-printable-internal-encoding-limit | 207 (if (and quoted-printable-internal-encoding-limit |
199 (> (- end beg) quoted-printable-internal-encoding-limit)) | 208 (> (- end beg) quoted-printable-internal-encoding-limit)) |
200 (quoted-printable-external-encode-region beg end) | 209 (quoted-printable-external-encode-region beg end) |
201 (quoted-printable-internal-encode-region beg end) | 210 (quoted-printable-internal-encode-region beg end) |
202 )) | 211 )) |
203 | 212 |
204 (defun quoted-printable-decode-region (beg end) | 213 (defun quoted-printable-decode-region (beg end) |
214 "Decode current region by quoted-printable. | |
215 START and END are buffer positions. | |
216 This function calls internal quoted-printable decoder if size of | |
217 region is smaller than `quoted-printable-internal-decoding-limit', | |
218 otherwise it calls external quoted-printable decoder specified by | |
219 `quoted-printable-external-decoder'. In this case, you must install | |
220 the program (maybe mmencode included in metamail or XEmacs package)." | |
205 (interactive "r") | 221 (interactive "r") |
206 (if (and quoted-printable-internal-decoding-limit | 222 (if (and quoted-printable-internal-decoding-limit |
207 (> (- end beg) quoted-printable-internal-decoding-limit)) | 223 (> (- end beg) quoted-printable-internal-decoding-limit)) |
208 (quoted-printable-external-decode-region beg end) | 224 (quoted-printable-external-decode-region beg end) |
209 (quoted-printable-internal-decode-region beg end) | 225 (quoted-printable-internal-decode-region beg end) |
212 | 228 |
213 ;;; @@ Quoted-Printable encoder/decoder for file | 229 ;;; @@ Quoted-Printable encoder/decoder for file |
214 ;;; | 230 ;;; |
215 | 231 |
216 (defun quoted-printable-insert-encoded-file (filename) | 232 (defun quoted-printable-insert-encoded-file (filename) |
233 "Encode contents of file FILENAME to quoted-printable, and insert the result. | |
234 It calls external quoted-printable encoder specified by | |
235 `quoted-printable-external-encoder'. So you must install the program | |
236 (maybe mmencode included in metamail or XEmacs package)." | |
217 (interactive (list (read-file-name "Insert encoded file: "))) | 237 (interactive (list (read-file-name "Insert encoded file: "))) |
218 (apply (function call-process) (car quoted-printable-external-encoder) | 238 (apply (function call-process) (car quoted-printable-external-encoder) |
219 filename t nil (cdr quoted-printable-external-encoder)) | 239 filename t nil (cdr quoted-printable-external-encoder)) |
220 ) | 240 ) |
221 | 241 |
228 (comment ?= ?? ?_ ?\( ?\) ?\\) | 248 (comment ?= ?? ?_ ?\( ?\) ?\\) |
229 (phrase ?= ?? ?_ ?\( ?\) ?\\ ?\" ?# ?$ ?% ?& ?' ?, ?. ?/ | 249 (phrase ?= ?? ?_ ?\( ?\) ?\\ ?\" ?# ?$ ?% ?& ?' ?, ?. ?/ |
230 ?: ?\; ?< ?> ?@ ?\[ ?\] ?^ ?` ?{ ?| ?} ?~) | 250 ?: ?\; ?< ?> ?@ ?\[ ?\] ?^ ?` ?{ ?| ?} ?~) |
231 )) | 251 )) |
232 | 252 |
233 (defun q-encoding-encode-string (str &optional mode) | 253 (defun q-encoding-encode-string (string &optional mode) |
254 "Encode STRING to Q-encoding of encoded-word, and return the result. | |
255 MODE allows `text', `comment', `phrase' or nil. Default value is | |
256 `phrase'." | |
234 (let ((specials (cdr (or (assq mode q-encoding-special-chars-alist) | 257 (let ((specials (cdr (or (assq mode q-encoding-special-chars-alist) |
235 (assq 'phrase q-encoding-special-chars-alist) | 258 (assq 'phrase q-encoding-special-chars-alist) |
236 )))) | 259 )))) |
237 (mapconcat (function | 260 (mapconcat (function |
238 (lambda (chr) | 261 (lambda (chr) |
244 ) | 267 ) |
245 (t | 268 (t |
246 (char-to-string chr) | 269 (char-to-string chr) |
247 )) | 270 )) |
248 )) | 271 )) |
249 str "") | 272 string "") |
250 )) | 273 )) |
251 | 274 |
252 (defun q-encoding-decode-string (str) | 275 (defun q-encoding-decode-string (string) |
276 "Decode STRING which is encoded in Q-encoding and return the result." | |
253 (let (q h l) | 277 (let (q h l) |
254 (mapconcat (function | 278 (mapconcat (function |
255 (lambda (chr) | 279 (lambda (chr) |
256 (cond ((eq chr ?_) " ") | 280 (cond ((eq chr ?_) " ") |
257 ((eq chr ?=) | 281 ((eq chr ?=) |
272 (setq h nil) | 296 (setq h nil) |
273 ) | 297 ) |
274 ) | 298 ) |
275 (t (char-to-string chr)) | 299 (t (char-to-string chr)) |
276 ))) | 300 ))) |
277 str ""))) | 301 string ""))) |
278 | 302 |
279 | 303 |
280 ;;; @@ etc | 304 ;;; @@ etc |
281 ;;; | 305 ;;; |
282 | 306 |