1 ;;; mel-q-ccl.el --- Quoted-Printable encoder/decoder using CCL.
3 ;; Copyright (C) 1998,1999 Tanaka Akira
5 ;; Author: Tanaka Akira <akr@jaist.ac.jp>
7 ;; Keywords: MIME, Quoted-Printable, Q-encoding
9 ;; This file is part of FLIM (Faithful Library about Internet Message).
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 this program; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
38 (defconst mel-ccl-16-table
39 '( 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))
41 (defconst mel-ccl-28-table
42 '( 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
43 16 17 18 19 20 21 22 23 24 25 26 27))
45 (defconst mel-ccl-256-table
46 '( 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
47 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
48 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
49 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
50 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
51 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
52 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
53 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
54 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
55 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
56 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
57 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
58 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
59 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
60 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
61 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255))
63 (defconst mel-ccl-256-to-16-table
64 '(nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
65 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
66 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
67 0 1 2 3 4 5 6 7 8 9 nil nil nil nil nil nil
68 nil 10 11 12 13 14 15 nil nil nil nil nil nil nil nil nil
69 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
70 nil 10 11 12 13 14 15 nil nil nil nil nil nil nil nil nil
71 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
72 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
73 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
74 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
75 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
76 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
77 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
78 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
79 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil))
81 (defconst mel-ccl-16-to-256-table
82 (mapcar 'char-int "0123456789ABCDEF"))
84 (defconst mel-ccl-high-table
87 (lambda (v) (nth (lsh v -4) mel-ccl-16-to-256-table))
90 (defconst mel-ccl-low-table
93 (lambda (v) (nth (logand v 15) mel-ccl-16-to-256-table))
96 (defconst mel-ccl-u-raw
100 ABCDEFGHIJKLMNOPQRSTUVWXYZ\
101 abcdefghijklmnopqrstuvwxyz\
102 !@#$%&'()*+,-./:;<>@[\\]^`{|}~"))
104 (defconst mel-ccl-c-raw
108 ABCDEFGHIJKLMNOPQRSTUVWXYZ\
109 abcdefghijklmnopqrstuvwxyz\
110 !@#$%&'*+,-./:;<>@[]^`{|}~"))
112 (defconst mel-ccl-p-raw
116 ABCDEFGHIJKLMNOPQRSTUVWXYZ\
117 abcdefghijklmnopqrstuvwxyz\
120 (defconst mel-ccl-qp-table
121 [enc enc enc enc enc enc enc enc enc wsp lf enc enc cr enc enc
122 enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc
123 wsp raw raw raw raw raw raw raw raw raw raw raw raw raw raw raw
124 raw raw raw raw raw raw raw raw raw raw raw raw raw enc raw raw
125 raw raw raw raw raw raw raw raw raw raw raw raw raw raw raw raw
126 raw raw raw raw raw raw raw raw raw raw raw raw raw raw raw raw
127 raw raw raw raw raw raw raw raw raw raw raw raw raw raw raw raw
128 raw raw raw raw raw raw raw raw raw raw raw raw raw raw raw enc
129 enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc
130 enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc
131 enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc
132 enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc
133 enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc
134 enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc
135 enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc
136 enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc])
146 (define-ccl-program mel-ccl-decode-q
155 ((= r0 (char-int ?_))
157 ((= r0 (char-int ?=))
166 mel-ccl-256-to-16-table)))
173 `((write r0 ,(vconcat
176 (logior (lsh r0 4) v))
180 mel-ccl-256-to-16-table)))
183 `(write-repeat ,r0))))
184 mel-ccl-256-table))))))
188 (defun mel-ccl-encode-q-generic (raw)
199 ((= r0 32) `(write-repeat ?_))
200 ((member r0 raw) `(write-repeat ,r0))
204 (write r0 ,mel-ccl-high-table)
205 (write r0 ,mel-ccl-low-table)
208 ;; On xemacs, generated program counts iso-8859-1 8bit character as 6bytes.
209 (defun mel-ccl-count-q-length (raw)
217 (if (or (= r1 32) (member r1 raw))
218 '((r0 += 1) (repeat))
219 '((r0 += 3) (repeat))))
220 mel-ccl-256-table))))))
224 (define-ccl-program mel-ccl-encode-uq
225 (mel-ccl-encode-q-generic mel-ccl-u-raw))
226 (define-ccl-program mel-ccl-encode-cq
227 (mel-ccl-encode-q-generic mel-ccl-c-raw))
228 (define-ccl-program mel-ccl-encode-pq
229 (mel-ccl-encode-q-generic mel-ccl-p-raw))
231 (define-ccl-program mel-ccl-count-uq
232 (mel-ccl-count-q-length mel-ccl-u-raw))
233 (define-ccl-program mel-ccl-count-cq
234 (mel-ccl-count-q-length mel-ccl-c-raw))
235 (define-ccl-program mel-ccl-count-pq
236 (mel-ccl-count-q-length mel-ccl-p-raw))
242 (defvar eof-block-branches)
243 (defvar eof-block-reg)
244 (defun mel-ccl-set-eof-block (branch)
245 (let ((p (assoc branch eof-block-branches)))
247 (setq p (cons branch (length eof-block-branches))
248 eof-block-branches (cons p eof-block-branches)))
249 `(,eof-block-reg = ,(cdr p))))
255 (defun mel-ccl-try-to-read-crlf (input-crlf reg
261 `(,(mel-ccl-set-eof-block cr-eof)
262 (read-if (,reg == ?\r)
263 (,(mel-ccl-set-eof-block lf-eof)
264 (read-if (,reg == ?\n)
268 `(,(mel-ccl-set-eof-block crlf-eof)
269 (read-if (,reg == ?\n)
277 ;; Generated CCL program works not properly on 20.2 because CCL_EOF_BLOCK
279 (defun mel-ccl-encode-quoted-printable-generic (input-crlf output-crlf)
280 (let ((hard (if output-crlf "\r\n" "\n"))
281 (soft (if output-crlf "=\r\n" "=\n"))
282 (eof-block-branches nil)
296 ,(mel-ccl-set-eof-block '(end))
298 (loop ; invariant: column <= 75
306 (let ((tmp (aref mel-ccl-qp-table r0)))
308 ((eq r0 (char-int ?F))
310 (,(mel-ccl-set-eof-block '((write "F") (end)))
312 (,(mel-ccl-set-eof-block '((write "Fr") (end)))
314 (,(mel-ccl-set-eof-block '((write "Fro") (end)))
316 (,(mel-ccl-set-eof-block '((write "From") (end)))
320 ,(mel-ccl-set-eof-block '((write "From=20") (end)))
322 (write-repeat "=46rom "))
324 (write-repeat "From"))))
326 (write-repeat "Fro"))))
328 (write-repeat "Fr"))))
330 (write-repeat "F"))))
331 ((,type = ,type-raw) (break)) ; RAW
333 ((eq r0 (char-int ?.))
335 ,(mel-ccl-try-to-read-crlf
337 ;; "." CR LF (input-crlf: t)
338 ;; "." LF (input-crlf: nil)
339 `((write ,(concat "=2E" hard))
340 ,(mel-ccl-set-eof-block '(end))
345 ;; "." noCR (input-crlf: t)
348 ;; "." CR <EOF> (input-crlf: t)
349 '((write ".=0D") (end))
350 ;; "." CR noLF (input-crlf: t)
352 (write-repeat ".=0D"))
353 ;; "." <EOF> (input-crlf: nil)
355 ;; "." noLF (input-crlf: nil)
358 ((,type = ,type-raw) (break)) ; RAW
360 ((eq tmp 'raw) `((,type = ,type-raw) (break)))
361 ((eq tmp 'enc) `((,type = ,type-enc) (break)))
362 ((eq tmp 'wsp) `((,type = ,type-wsp) (break)))
363 ((eq tmp 'cr) `((,type = ,(if input-crlf type-brk type-enc))
365 ((eq tmp 'lf) `((,type = ,(if input-crlf type-enc type-brk))
369 ;; r0:type{raw,enc,wsp,brk}
376 ,(mel-ccl-set-eof-block '(end))
377 (write-read-repeat r0))
380 ,@(mel-ccl-try-to-read-crlf
384 ,(mel-ccl-set-eof-block `((write ,hard) (end)))
386 (write-repeat ,hard))
389 (write ,soft) (write-repeat r1))
390 `((write ,soft) (write r1) (write "=0D") (end))
392 (write ,soft) (write r1) (write-repeat "=0D"))
395 (write ,soft) (write-repeat r1)))))
401 (write r0 ,mel-ccl-high-table)
402 ,(mel-ccl-set-eof-block '(end))
403 (write-read-repeat r0 ,mel-ccl-low-table))
407 ,@(mel-ccl-try-to-read-crlf
411 (write r1 ,mel-ccl-high-table)
412 (write r1 ,mel-ccl-low-table)
414 ,(mel-ccl-set-eof-block '(end))
418 (write r1 ,mel-ccl-high-table)
419 (write r1 ,mel-ccl-low-table)
422 (write ,(concat soft "="))
423 (write r1 ,mel-ccl-high-table)
424 (write r1 ,mel-ccl-low-table)
426 `((write ,(concat soft "="))
427 (write r1 ,mel-ccl-high-table)
428 (write r1 ,mel-ccl-low-table)
432 (write ,(concat soft "="))
433 (write r1 ,mel-ccl-high-table)
434 (write r1 ,mel-ccl-low-table)
435 (write-repeat "=0D"))
437 (write r1 ,mel-ccl-high-table)
438 (write r1 ,mel-ccl-low-table)
441 (write ,(concat soft "="))
442 (write r1 ,mel-ccl-high-table)
443 (write r1 ,mel-ccl-low-table)
446 (write ,(concat soft "="))
447 (write r0 ,mel-ccl-high-table)
448 ,(mel-ccl-set-eof-block '(end))
449 (write-read-repeat r0 ,mel-ccl-low-table)))))
453 ,@(mel-ccl-try-to-read-crlf
458 (write r1 ,mel-ccl-high-table)
459 (write r1 ,mel-ccl-low-table)
461 ,(mel-ccl-set-eof-block `(end))
465 (write r1 ,mel-ccl-high-table)
466 (write r1 ,mel-ccl-low-table)
477 (write-repeat "=0D"))
479 (write r1 ,mel-ccl-high-table)
480 (write r1 ,mel-ccl-low-table)
487 ,@(mel-ccl-try-to-read-crlf
492 (write r1 ,mel-ccl-high-table)
493 (write r1 ,mel-ccl-low-table)
495 ,(mel-ccl-set-eof-block `(end))
499 (write r1 ,mel-ccl-high-table)
500 (write r1 ,mel-ccl-low-table)
506 (write ,(concat soft "=0D"))
511 (write-repeat ,(concat soft "=0D")))
513 (write r1 ,mel-ccl-high-table)
514 (write r1 ,mel-ccl-low-table)
522 ,(mel-ccl-set-eof-block `((write ,soft) (end)))
523 (write-read-repeat r0))
531 `((if ((,column > 73) & ,after-wsp)
535 ,(mel-ccl-set-eof-block `((if (,column > 73) (write ,soft))
536 (write "=0D") (end)))
541 (write ,(concat soft hard))
542 ,(mel-ccl-set-eof-block '(end))
548 ,(mel-ccl-set-eof-block '(end))
554 (write-repeat "=0D"))
558 ,(mel-ccl-set-eof-block
559 `((write ,(concat soft "=0D=0D")) (end)))
562 ,(mel-ccl-set-eof-block
563 `((write ,(concat "=0D" hard)) (end)))
565 (write-repeat ,(concat "=0D" hard)))
567 (write-repeat ,(concat soft "=0D=0D")))))
570 (write-repeat ,(concat soft "=0D"))))
573 (write-repeat ,(concat soft "=0D")))))))
576 ;; WSP ; r0{LF}:type-brk
579 (write ,(concat soft (if output-crlf "\r" "")))
580 ,(mel-ccl-set-eof-block `(end))
581 (write-read-repeat r0))
582 ;; noWSP ; r0{LF}:type-brk
585 ,@(if output-crlf '((write ?\r)) '())
586 ,(mel-ccl-set-eof-block `(end))
587 (write-read-repeat r0)))
591 ,@(reverse (mapcar 'car eof-block-branches))))))
593 (defun mel-ccl-decode-quoted-printable-generic (input-crlf output-crlf)
601 (let ((tmp (aref mel-ccl-qp-table r0)))
603 ((eq tmp 'raw) `(write-read-repeat r0))
604 ((eq tmp 'wsp) (if (eq r0 (char-int ? ))
614 ;; hard line break found.
617 (write-read-repeat r0))
618 '(write-read-repeat r0))
620 ;; invalid control character (bare CR) found.
621 ;; -> ignore it and rescan from r0.
624 ;; invalid character (bare CR) found.
631 ;; invalid character (bare LF) found.
636 ;; hard line break found.
639 (write-read-repeat r0))
640 '(write-read-repeat r0))))
641 ((eq r0 (char-int ?=))
646 (if ((r0 == ? ) | r1)
648 ;; Skip transport-padding.
649 ;; It should check CR LF after
650 ;; transport-padding.
657 ;; '=' [\t ]* r0:[^\t ]
663 ((eq r0 (char-int ?\r))
665 ;; '=' [\t ]* r0='\r'
667 ;; '=' [\t ]* '\r' r0
669 ;; '=' [\t ]* '\r' r0='\n'
670 ;; soft line break found.
673 ;; '=' [\t ]* '\r' r0:[^\n]
675 ;; output "=" and rescan from r0.
678 ;; '=' [\t ]* r0='\r'
679 ;; invalid input (bare CR found) ->
680 ;; output "=" and rescan from next.
684 ((eq r0 (char-int ?\n))
686 ;; '=' [\t ]* r0='\n'
687 ;; invalid input (bare LF found) ->
688 ;; output "=" and rescan from next.
692 ;; '=' [\t ]* r0='\r\n'
693 ;; soft line break found.
696 ((setq tmp (nth r0 mel-ccl-256-to-16-table))
697 ;; '=' [\t ]* r0:[0-9A-F]
698 ;; upper nibble of hexadecimal digit found.
702 ;; '=' [\t ]* r0:[^\r0-9A-F]
704 ;; output "=" and rescan from r0.
708 ;; '=' [\t ]* r1:r0:[0-9A-F]
713 (if (setq tmp (nth r2 mel-ccl-256-to-16-table))
714 ;; '=' [\t ]* r1:r0:[0-9A-F] r2:[0-9A-F]
720 (logior (lsh r0 4) tmp))
722 ;; '=' [\t ]* r1:r0:[0-9A-F] r2:[^0-9A-F]
727 ;; '=' [\t ]* r1:r0:[0-9A-F] r2:[^0-9A-F]
729 ;; output "=" with hex digit and rescan from r2.
735 ;; invalid character found.
737 `((write-read-repeat r0))))))
745 (let ((reg (aref [r1 r2 r3 r4 r5] regnum)))
758 ((r6 = ,(+ (* regnum 28) bit))
762 (,reg |= ,(lsh 1 bit))
764 ((r6 = ,(+ (* regnum 28) bit))
768 ;; white space buffer exhaust.
769 ;; error: line length limit (76bytes) violation.
770 ;; -> ignore these white spaces.
776 ;; trailing white spaces found.
777 ;; -> ignore these white spacs.
778 ((write ,(if output-crlf "\r\n" "\n"))
781 ;; [\t ]* \r r0:[^\n]
782 ;; error: bare CR found.
783 ;; -> output white spaces and ignore bare CR.
786 ;; middle white spaces found.
789 ;; trailing white spaces found.
790 ;; -> ignore these white spacs.
791 ((write ,(if output-crlf "\r\n" "\n"))
795 ;; middle white spaces found.
801 (let ((reg (aref [r1 r2 r3 r4 r5] regnum)))
806 `((if (,reg & ,(lsh 1 bit))
809 (if (r6 == ,(+ (* regnum 28) bit 1))
818 (define-ccl-program mel-ccl-encode-quoted-printable-crlf-crlf
819 (mel-ccl-encode-quoted-printable-generic t t))
821 (define-ccl-program mel-ccl-encode-quoted-printable-crlf-lf
822 (mel-ccl-encode-quoted-printable-generic t nil))
824 (define-ccl-program mel-ccl-encode-quoted-printable-lf-crlf
825 (mel-ccl-encode-quoted-printable-generic nil t))
827 (define-ccl-program mel-ccl-encode-quoted-printable-lf-lf
828 (mel-ccl-encode-quoted-printable-generic nil nil))
830 (define-ccl-program mel-ccl-decode-quoted-printable-crlf-crlf
831 (mel-ccl-decode-quoted-printable-generic t t))
833 (define-ccl-program mel-ccl-decode-quoted-printable-crlf-lf
834 (mel-ccl-decode-quoted-printable-generic t nil))
836 (define-ccl-program mel-ccl-decode-quoted-printable-lf-crlf
837 (mel-ccl-decode-quoted-printable-generic nil t))
839 (define-ccl-program mel-ccl-decode-quoted-printable-lf-lf
840 (mel-ccl-decode-quoted-printable-generic nil nil))
846 (make-ccl-coding-system
847 'mel-ccl-uq-rev ?Q "MIME Q-encoding in unstructured field (reversed)"
848 'mel-ccl-encode-uq 'mel-ccl-decode-q)
850 (make-ccl-coding-system
851 'mel-ccl-cq-rev ?Q "MIME Q-encoding in comment (reversed)"
852 'mel-ccl-encode-cq 'mel-ccl-decode-q)
854 (make-ccl-coding-system
855 'mel-ccl-pq-rev ?Q "MIME Q-encoding in phrase (reversed)"
856 'mel-ccl-encode-pq 'mel-ccl-decode-q)
858 (make-ccl-coding-system
859 'mel-ccl-quoted-printable-crlf-crlf-rev
860 ?Q "MIME Quoted-Printable-encoding (reversed)"
861 'mel-ccl-encode-quoted-printable-crlf-crlf
862 'mel-ccl-decode-quoted-printable-crlf-crlf)
864 (make-ccl-coding-system
865 'mel-ccl-quoted-printable-lf-crlf-rev
866 ?Q "MIME Quoted-Printable-encoding (LF encoding) (reversed)"
867 'mel-ccl-encode-quoted-printable-crlf-lf
868 'mel-ccl-decode-quoted-printable-lf-crlf)
870 (make-ccl-coding-system
871 'mel-ccl-quoted-printable-crlf-lf-rev
872 ?Q "MIME Quoted-Printable-encoding (LF internal) (reversed)"
873 'mel-ccl-encode-quoted-printable-lf-crlf
874 'mel-ccl-decode-quoted-printable-crlf-lf)
876 (make-ccl-coding-system
877 'mel-ccl-quoted-printable-lf-lf-rev
878 ?Q "MIME Quoted-Printable-encoding (LF encoding) (LF internal) (reversed)"
879 'mel-ccl-encode-quoted-printable-lf-lf
880 'mel-ccl-decode-quoted-printable-lf-lf)
883 ;;; @ quoted-printable
886 (check-broken-facility ccl-execute-eof-block-on-decoding-some)
888 (unless-broken ccl-execute-eof-block-on-decoding-some
892 (and (eq emacs-major-version 23)
893 (eq emacs-minor-version 1)))
894 (defun quoted-printable-ccl-encode-string (string)
895 "Encode STRING with quoted-printable encoding."
896 (ccl-execute-on-string 'mel-ccl-encode-quoted-printable-lf-lf
897 (make-vector 9 0) string nil t))
898 (defun quoted-printable-ccl-encode-region (start end)
899 "Encode the region from START to END with quoted-printable encoding."
903 (insert (prog1 (quoted-printable-ccl-encode-string
904 (buffer-substring start end))
905 (delete-region start end)))))
907 (defun quoted-printable-ccl-insert-encoded-file (filename)
908 "Encode contents of the file named as FILENAME, and insert it."
909 (interactive "*fInsert encoded file: ")
911 (ccl-execute-on-string 'mel-ccl-encode-quoted-printable-lf-lf
914 (set-buffer-multibyte nil)
915 (insert-file-contents-as-binary filename)
919 (defun quoted-printable-ccl-encode-string (string)
920 "Encode STRING with quoted-printable encoding."
921 (decode-coding-string
923 'mel-ccl-quoted-printable-lf-lf-rev))
925 (defun quoted-printable-ccl-encode-region (start end)
926 "Encode the region from START to END with quoted-printable encoding."
928 (decode-coding-region start end 'mel-ccl-quoted-printable-lf-lf-rev))
930 (defun quoted-printable-ccl-insert-encoded-file (filename)
931 "Encode contents of the file named as FILENAME, and insert it."
932 (interactive "*fInsert encoded file: ")
934 (decode-coding-string
936 (set-buffer-multibyte nil)
937 (insert-file-contents-as-binary filename)
939 'mel-ccl-quoted-printable-lf-lf-rev)))))
941 (mel-define-method-function
942 (mime-encode-string string (nil "quoted-printable"))
943 'quoted-printable-ccl-encode-string)
944 (mel-define-method-function
945 (mime-encode-region start end (nil "quoted-printable"))
946 'quoted-printable-ccl-encode-region)
947 (mel-define-method-function
948 (mime-insert-encoded-file filename (nil "quoted-printable"))
949 'quoted-printable-ccl-insert-encoded-file)
954 (and (eq emacs-major-version 23)
955 (eq emacs-minor-version 1)))
956 (defun quoted-printable-ccl-decode-string (string)
957 "Decode quoted-printable encoded STRING."
958 (ccl-execute-on-string 'mel-ccl-decode-quoted-printable-lf-lf
959 (make-vector 9 0) string nil t))
961 (defun quoted-printable-ccl-decode-region (start end)
962 "Decode the region from START to END with quoted-printable
967 (insert (prog1 (quoted-printable-ccl-decode-string
968 (buffer-substring start end))
969 (delete-region start end)))))
971 (defun quoted-printable-ccl-write-decoded-region (start end filename)
972 "Decode quoted-printable encoded current region and write out to FILENAME."
973 (interactive "*r\nFWrite decoded region to file: ")
974 (let ((string (quoted-printable-ccl-decode-string
975 (buffer-substring start end)))
976 (coding-system-for-write 'binary)
977 jka-compr-compression-info-list jam-zcat-filename-list)
978 (with-temp-file filename
981 (defun quoted-printable-ccl-decode-string (string)
982 "Decode quoted-printable encoded STRING."
983 (encode-coding-string
985 'mel-ccl-quoted-printable-lf-lf-rev))
987 (defun quoted-printable-ccl-decode-region (start end)
988 "Decode the region from START to END with quoted-printable
991 (encode-coding-region start end 'mel-ccl-quoted-printable-lf-lf-rev))
993 (defun quoted-printable-ccl-write-decoded-region (start end filename)
994 "Decode quoted-printable encoded current region and write out to FILENAME."
995 (interactive "*r\nFWrite decoded region to file: ")
996 (let ((coding-system-for-write
997 (if (coding-system-p 'mel-ccl-quoted-printable-lf-lf-rev-unix)
998 'mel-ccl-quoted-printable-lf-lf-rev-unix
999 'mel-ccl-quoted-printable-lf-lf-rev))
1000 jka-compr-compression-info-list jam-zcat-filename-list)
1001 (write-region start end filename)))))
1003 (mel-define-method-function
1004 (mime-decode-string string (nil "quoted-printable"))
1005 'quoted-printable-ccl-decode-string)
1006 (mel-define-method-function
1007 (mime-decode-region start end (nil "quoted-printable"))
1008 'quoted-printable-ccl-decode-region)
1009 (mel-define-method-function
1010 (mime-write-decoded-region start end filename (nil "quoted-printable"))
1011 'quoted-printable-ccl-write-decoded-region)
1019 (and (eq emacs-major-version 23)
1020 (eq emacs-minor-version 1)))
1021 (defun q-encoding-ccl-encode-string (string &optional mode)
1022 "Encode STRING to Q-encoding of encoded-word, and return the result.
1023 MODE allows `text', `comment', `phrase' or nil. Default value is
1025 (ccl-execute-on-string
1027 ((eq mode 'text) 'mel-ccl-encode-uq)
1028 ((eq mode 'comment) 'mel-ccl-encode-cq)
1029 (t 'mel-ccl-encode-pq))
1030 (make-vector 9 0) string nil t))
1032 (defun q-encoding-ccl-decode-string (string)
1033 "Decode Q encoded STRING and return the result."
1034 (ccl-execute-on-string 'mel-ccl-decode-q
1035 (make-vector 9 0) string nil t)))
1037 (defun q-encoding-ccl-encode-string (string &optional mode)
1038 "Encode STRING to Q-encoding of encoded-word, and return the result.
1039 MODE allows `text', `comment', `phrase' or nil. Default value is
1041 (decode-coding-string
1044 ((eq mode 'text) 'mel-ccl-uq-rev)
1045 ((eq mode 'comment) 'mel-ccl-cq-rev)
1046 (t 'mel-ccl-pq-rev))))
1048 (defun q-encoding-ccl-decode-string (string)
1049 "Decode Q encoded STRING and return the result."
1050 (encode-coding-string
1054 (unless (featurep 'xemacs)
1055 (defun q-encoding-ccl-encoded-length (string &optional mode)
1056 (let ((status [nil nil nil nil nil nil nil nil nil]))
1057 (fillarray status nil) ; XXX: Is this necessary?
1058 (ccl-execute-on-string
1060 ((eq mode 'text) 'mel-ccl-count-uq)
1061 ((eq mode 'comment) 'mel-ccl-count-cq)
1062 (t 'mel-ccl-count-pq))
1068 (mel-define-method-function (encoded-text-encode-string string (nil "Q"))
1069 'q-encoding-ccl-encode-string)
1071 (mel-define-method encoded-text-decode-string (string (nil "Q"))
1072 (if (string-match (eval-when-compile
1073 (concat "\\`" Q-encoded-text-regexp "\\'"))
1075 (q-encoding-ccl-decode-string string)
1076 (error "Invalid encoded-text %s" string)))
1082 (provide 'mel-q-ccl)
1084 ;;; mel-q-ccl.el ends here.