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., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, 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 nil nil nil nil nil nil 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
154 ((= r0 (char-int ?_))
156 ((= r0 (char-int ?=))
165 mel-ccl-256-to-16-table)))
172 `((write r0 ,(vconcat
175 (logior (lsh r0 4) v))
179 mel-ccl-256-to-16-table)))
182 `(write-repeat ,r0))))
183 mel-ccl-256-table))))))
187 (defun mel-ccl-encode-q-generic (raw)
196 ((= r0 32) `(write-repeat ?_))
197 ((member r0 raw) `(write-repeat ,r0))
201 (write r0 ,mel-ccl-high-table)
202 (write r0 ,mel-ccl-low-table)
205 ;; On xemacs, generated program counts iso-8859-1 8bit character as 6bytes.
206 (defun mel-ccl-count-q-length (raw)
214 (if (or (= r1 32) (member r1 raw))
215 '((r0 += 1) (repeat))
216 '((r0 += 3) (repeat))))
217 mel-ccl-256-table))))))
221 (define-ccl-program mel-ccl-encode-uq
222 (mel-ccl-encode-q-generic mel-ccl-u-raw))
223 (define-ccl-program mel-ccl-encode-cq
224 (mel-ccl-encode-q-generic mel-ccl-c-raw))
225 (define-ccl-program mel-ccl-encode-pq
226 (mel-ccl-encode-q-generic mel-ccl-p-raw))
228 (define-ccl-program mel-ccl-count-uq
229 (mel-ccl-count-q-length mel-ccl-u-raw))
230 (define-ccl-program mel-ccl-count-cq
231 (mel-ccl-count-q-length mel-ccl-c-raw))
232 (define-ccl-program mel-ccl-count-pq
233 (mel-ccl-count-q-length mel-ccl-p-raw))
239 (defvar eof-block-branches)
240 (defvar eof-block-reg)
241 (defun mel-ccl-set-eof-block (branch)
242 (let ((p (assoc branch eof-block-branches)))
244 (setq p (cons branch (length eof-block-branches))
245 eof-block-branches (cons p eof-block-branches)))
246 `(,eof-block-reg = ,(cdr p))))
252 (defun mel-ccl-try-to-read-crlf (input-crlf reg
258 `(,(mel-ccl-set-eof-block cr-eof)
259 (read-if (,reg == ?\r)
260 (,(mel-ccl-set-eof-block lf-eof)
261 (read-if (,reg == ?\n)
265 `(,(mel-ccl-set-eof-block crlf-eof)
266 (read-if (,reg == ?\n)
274 ;; Generated CCL program works not properly on 20.2 because CCL_EOF_BLOCK
276 (defun mel-ccl-encode-quoted-printable-generic (input-crlf output-crlf)
277 (let ((hard (if output-crlf "\r\n" "\n"))
278 (soft (if output-crlf "=\r\n" "=\n"))
279 (eof-block-branches nil)
293 ,(mel-ccl-set-eof-block '(end))
295 (loop ; invariant: column <= 75
302 (let ((tmp (aref mel-ccl-qp-table r0)))
304 ((eq r0 (char-int ?F))
306 (,(mel-ccl-set-eof-block '((write "F") (end)))
308 (,(mel-ccl-set-eof-block '((write "Fr") (end)))
310 (,(mel-ccl-set-eof-block '((write "Fro") (end)))
312 (,(mel-ccl-set-eof-block '((write "From") (end)))
316 ,(mel-ccl-set-eof-block '((write "From=20") (end)))
318 (write-repeat "=46rom "))
320 (write-repeat "From"))))
322 (write-repeat "Fro"))))
324 (write-repeat "Fr"))))
326 (write-repeat "F"))))
327 ((,type = ,type-raw) (break)) ; RAW
329 ((eq r0 (char-int ?.))
331 ,(mel-ccl-try-to-read-crlf
333 ;; "." CR LF (input-crlf: t)
334 ;; "." LF (input-crlf: nil)
335 `((write ,(concat "=2E" hard))
336 ,(mel-ccl-set-eof-block '(end))
341 ;; "." noCR (input-crlf: t)
344 ;; "." CR <EOF> (input-crlf: t)
345 '((write ".=0D") (end))
346 ;; "." CR noLF (input-crlf: t)
348 (write-repeat ".=0D"))
349 ;; "." <EOF> (input-crlf: nil)
351 ;; "." noLF (input-crlf: nil)
354 ((,type = ,type-raw) (break)) ; RAW
356 ((eq tmp 'raw) `((,type = ,type-raw) (break)))
357 ((eq tmp 'enc) `((,type = ,type-enc) (break)))
358 ((eq tmp 'wsp) `((,type = ,type-wsp) (break)))
359 ((eq tmp 'cr) `((,type = ,(if input-crlf type-brk type-enc))
361 ((eq tmp 'lf) `((,type = ,(if input-crlf type-enc type-brk))
365 ;; r0:type{raw,enc,wsp,brk}
372 ,(mel-ccl-set-eof-block '(end))
373 (write-read-repeat r0))
376 ,@(mel-ccl-try-to-read-crlf
380 ,(mel-ccl-set-eof-block `((write ,hard) (end)))
382 (write-repeat ,hard))
385 (write ,soft) (write-repeat r1))
386 `((write ,soft) (write r1) (write "=0D") (end))
388 (write ,soft) (write r1) (write-repeat "=0D"))
391 (write ,soft) (write-repeat r1)))))
397 (write r0 ,mel-ccl-high-table)
398 ,(mel-ccl-set-eof-block '(end))
399 (write-read-repeat r0 ,mel-ccl-low-table))
403 ,@(mel-ccl-try-to-read-crlf
407 (write r1 ,mel-ccl-high-table)
408 (write r1 ,mel-ccl-low-table)
410 ,(mel-ccl-set-eof-block '(end))
414 (write r1 ,mel-ccl-high-table)
415 (write r1 ,mel-ccl-low-table)
418 (write ,(concat soft "="))
419 (write r1 ,mel-ccl-high-table)
420 (write r1 ,mel-ccl-low-table)
422 `((write ,(concat soft "="))
423 (write r1 ,mel-ccl-high-table)
424 (write r1 ,mel-ccl-low-table)
428 (write ,(concat soft "="))
429 (write r1 ,mel-ccl-high-table)
430 (write r1 ,mel-ccl-low-table)
431 (write-repeat "=0D"))
433 (write r1 ,mel-ccl-high-table)
434 (write r1 ,mel-ccl-low-table)
437 (write ,(concat soft "="))
438 (write r1 ,mel-ccl-high-table)
439 (write r1 ,mel-ccl-low-table)
442 (write ,(concat soft "="))
443 (write r0 ,mel-ccl-high-table)
444 ,(mel-ccl-set-eof-block '(end))
445 (write-read-repeat r0 ,mel-ccl-low-table)))))
449 ,@(mel-ccl-try-to-read-crlf
454 (write r1 ,mel-ccl-high-table)
455 (write r1 ,mel-ccl-low-table)
457 ,(mel-ccl-set-eof-block `(end))
461 (write r1 ,mel-ccl-high-table)
462 (write r1 ,mel-ccl-low-table)
473 (write-repeat "=0D"))
475 (write r1 ,mel-ccl-high-table)
476 (write r1 ,mel-ccl-low-table)
483 ,@(mel-ccl-try-to-read-crlf
488 (write r1 ,mel-ccl-high-table)
489 (write r1 ,mel-ccl-low-table)
491 ,(mel-ccl-set-eof-block `(end))
495 (write r1 ,mel-ccl-high-table)
496 (write r1 ,mel-ccl-low-table)
502 (write ,(concat soft "=0D"))
507 (write-repeat ,(concat soft "=0D")))
509 (write r1 ,mel-ccl-high-table)
510 (write r1 ,mel-ccl-low-table)
518 ,(mel-ccl-set-eof-block `((write ,soft) (end)))
519 (write-read-repeat r0))
527 `((if ((,column > 73) & ,after-wsp)
531 ,(mel-ccl-set-eof-block `((if (,column > 73) (write ,soft))
532 (write "=0D") (end)))
537 (write ,(concat soft hard))
538 ,(mel-ccl-set-eof-block '(end))
544 ,(mel-ccl-set-eof-block '(end))
550 (write-repeat "=0D"))
554 ,(mel-ccl-set-eof-block
555 `((write ,(concat soft "=0D=0D")) (end)))
558 ,(mel-ccl-set-eof-block
559 `((write ,(concat "=0D" hard)) (end)))
561 (write-repeat ,(concat "=0D" hard)))
563 (write-repeat ,(concat soft "=0D=0D")))))
566 (write-repeat ,(concat soft "=0D"))))
569 (write-repeat ,(concat soft "=0D")))))))
572 ;; WSP ; r0{LF}:type-brk
575 (write ,(concat soft (if output-crlf "\r" "")))
576 ,(mel-ccl-set-eof-block `(end))
577 (write-read-repeat r0))
578 ;; noWSP ; r0{LF}:type-brk
581 ,@(if output-crlf '((write ?\r)) '())
582 ,(mel-ccl-set-eof-block `(end))
583 (write-read-repeat r0)))
587 ,@(reverse (mapcar 'car eof-block-branches))))))
589 (defun mel-ccl-decode-quoted-printable-generic (input-crlf output-crlf)
597 (let ((tmp (aref mel-ccl-qp-table r0)))
599 ((eq tmp 'raw) `(write-read-repeat r0))
600 ((eq tmp 'wsp) (if (eq r0 (char-int ? ))
610 ;; hard line break found.
613 (write-read-repeat r0))
614 '(write-read-repeat r0))
616 ;; invalid control character (bare CR) found.
617 ;; -> ignore it and rescan from r0.
620 ;; invalid character (bare CR) found.
627 ;; invalid character (bare LF) found.
632 ;; hard line break found.
635 (write-read-repeat r0))
636 '(write-read-repeat r0))))
637 ((eq r0 (char-int ?=))
642 (if ((r0 == ? ) | r1)
644 ;; Skip transport-padding.
645 ;; It should check CR LF after
646 ;; transport-padding.
653 ;; '=' [\t ]* r0:[^\t ]
659 ((eq r0 (char-int ?\r))
661 ;; '=' [\t ]* r0='\r'
663 ;; '=' [\t ]* '\r' r0
665 ;; '=' [\t ]* '\r' r0='\n'
666 ;; soft line break found.
669 ;; '=' [\t ]* '\r' r0:[^\n]
671 ;; output "=" and rescan from r0.
674 ;; '=' [\t ]* r0='\r'
675 ;; invalid input (bare CR found) ->
676 ;; output "=" and rescan from next.
680 ((eq r0 (char-int ?\n))
682 ;; '=' [\t ]* r0='\n'
683 ;; invalid input (bare LF found) ->
684 ;; output "=" and rescan from next.
688 ;; '=' [\t ]* r0='\r\n'
689 ;; soft line break found.
692 ((setq tmp (nth r0 mel-ccl-256-to-16-table))
693 ;; '=' [\t ]* r0:[0-9A-F]
694 ;; upper nibble of hexadecimal digit found.
698 ;; '=' [\t ]* r0:[^\r0-9A-F]
700 ;; output "=" and rescan from r0.
704 ;; '=' [\t ]* r1:r0:[0-9A-F]
709 (if (setq tmp (nth r2 mel-ccl-256-to-16-table))
710 ;; '=' [\t ]* r1:r0:[0-9A-F] r2:[0-9A-F]
716 (logior (lsh r0 4) tmp))
718 ;; '=' [\t ]* r1:r0:[0-9A-F] r2:[^0-9A-F]
723 ;; '=' [\t ]* r1:r0:[0-9A-F] r2:[^0-9A-F]
725 ;; output "=" with hex digit and rescan from r2.
731 ;; invalid character found.
742 (let ((reg (aref [r1 r2 r3 r4 r5] regnum)))
755 ((r6 = ,(+ (* regnum 28) bit))
759 (,reg |= ,(lsh 1 bit))
761 ((r6 = ,(+ (* regnum 28) bit))
765 ;; white space buffer exhaust.
766 ;; error: line length limit (76bytes) violation.
767 ;; -> ignore these white spaces.
773 ;; trailing white spaces found.
774 ;; -> ignore these white spacs.
775 ((write ,(if output-crlf "\r\n" "\n"))
778 ;; [\t ]* \r r0:[^\n]
779 ;; error: bare CR found.
780 ;; -> output white spaces and ignore bare CR.
783 ;; middle white spaces found.
786 ;; trailing white spaces found.
787 ;; -> ignore these white spacs.
788 ((write ,(if output-crlf "\r\n" "\n"))
792 ;; middle white spaces found.
798 (let ((reg (aref [r1 r2 r3 r4 r5] regnum)))
803 `((if (,reg & ,(lsh 1 bit))
806 (if (r6 == ,(+ (* regnum 28) bit 1))
815 (define-ccl-program mel-ccl-encode-quoted-printable-crlf-crlf
816 (mel-ccl-encode-quoted-printable-generic t t))
818 (define-ccl-program mel-ccl-encode-quoted-printable-crlf-lf
819 (mel-ccl-encode-quoted-printable-generic t nil))
821 (define-ccl-program mel-ccl-encode-quoted-printable-lf-crlf
822 (mel-ccl-encode-quoted-printable-generic nil t))
824 (define-ccl-program mel-ccl-encode-quoted-printable-lf-lf
825 (mel-ccl-encode-quoted-printable-generic nil nil))
827 (define-ccl-program mel-ccl-decode-quoted-printable-crlf-crlf
828 (mel-ccl-decode-quoted-printable-generic t t))
830 (define-ccl-program mel-ccl-decode-quoted-printable-crlf-lf
831 (mel-ccl-decode-quoted-printable-generic t nil))
833 (define-ccl-program mel-ccl-decode-quoted-printable-lf-crlf
834 (mel-ccl-decode-quoted-printable-generic nil t))
836 (define-ccl-program mel-ccl-decode-quoted-printable-lf-lf
837 (mel-ccl-decode-quoted-printable-generic nil nil))
843 (make-ccl-coding-system
844 'mel-ccl-uq-rev ?Q "MIME Q-encoding in unstructured field (reversed)"
845 'mel-ccl-encode-uq 'mel-ccl-decode-q)
847 (make-ccl-coding-system
848 'mel-ccl-cq-rev ?Q "MIME Q-encoding in comment (reversed)"
849 'mel-ccl-encode-cq 'mel-ccl-decode-q)
851 (make-ccl-coding-system
852 'mel-ccl-pq-rev ?Q "MIME Q-encoding in phrase (reversed)"
853 'mel-ccl-encode-pq 'mel-ccl-decode-q)
855 (make-ccl-coding-system
856 'mel-ccl-quoted-printable-crlf-crlf-rev
857 ?Q "MIME Quoted-Printable-encoding (reversed)"
858 'mel-ccl-encode-quoted-printable-crlf-crlf
859 'mel-ccl-decode-quoted-printable-crlf-crlf)
861 (make-ccl-coding-system
862 'mel-ccl-quoted-printable-lf-crlf-rev
863 ?Q "MIME Quoted-Printable-encoding (LF encoding) (reversed)"
864 'mel-ccl-encode-quoted-printable-crlf-lf
865 'mel-ccl-decode-quoted-printable-lf-crlf)
867 (make-ccl-coding-system
868 'mel-ccl-quoted-printable-crlf-lf-rev
869 ?Q "MIME Quoted-Printable-encoding (LF internal) (reversed)"
870 'mel-ccl-encode-quoted-printable-lf-crlf
871 'mel-ccl-decode-quoted-printable-crlf-lf)
873 (make-ccl-coding-system
874 'mel-ccl-quoted-printable-lf-lf-rev
875 ?Q "MIME Quoted-Printable-encoding (LF encoding) (LF internal) (reversed)"
876 'mel-ccl-encode-quoted-printable-lf-lf
877 'mel-ccl-decode-quoted-printable-lf-lf)
880 ;;; @ quoted-printable
883 (check-broken-facility ccl-execute-eof-block-on-decoding-some)
885 (unless-broken ccl-execute-eof-block-on-decoding-some
887 (defun quoted-printable-ccl-encode-string (string)
888 "Encode STRING with quoted-printable encoding."
889 (decode-coding-string
891 'mel-ccl-quoted-printable-lf-lf-rev))
893 (defun quoted-printable-ccl-encode-region (start end)
894 "Encode the region from START to END with quoted-printable encoding."
896 (decode-coding-region start end 'mel-ccl-quoted-printable-lf-lf-rev))
898 (defun quoted-printable-ccl-insert-encoded-file (filename)
899 "Encode contents of the file named as FILENAME, and insert it."
900 (interactive "*fInsert encoded file: ")
901 (let ((coding-system-for-read 'mel-ccl-quoted-printable-lf-lf-rev)
903 (insert-file-contents filename)))
905 (mel-define-method-function
906 (mime-encode-string string (nil "quoted-printable"))
907 'quoted-printable-ccl-encode-string)
908 (mel-define-method-function
909 (mime-encode-region start end (nil "quoted-printable"))
910 'quoted-printable-ccl-encode-region)
911 (mel-define-method-function
912 (mime-insert-encoded-file filename (nil "quoted-printable"))
913 'quoted-printable-ccl-insert-encoded-file)
916 (defun quoted-printable-ccl-decode-string (string)
917 "Decode quoted-printable encoded STRING."
918 (encode-coding-string
920 'mel-ccl-quoted-printable-lf-lf-rev))
922 (defun quoted-printable-ccl-decode-region (start end)
923 "Decode the region from START to END with quoted-printable
926 (encode-coding-region start end 'mel-ccl-quoted-printable-lf-lf-rev))
928 (defun quoted-printable-ccl-write-decoded-region (start end filename)
929 "Decode quoted-printable encoded current region and write out to FILENAME."
930 (interactive "*r\nFWrite decoded region to file: ")
931 (let ((coding-system-for-write 'mel-ccl-quoted-printable-lf-lf-rev)
932 jka-compr-compression-info-list jam-zcat-filename-list)
933 (write-region start end filename)))
935 (mel-define-method-function
936 (mime-decode-string string (nil "quoted-printable"))
937 'quoted-printable-ccl-decode-string)
938 (mel-define-method-function
939 (mime-decode-region start end (nil "quoted-printable"))
940 'quoted-printable-ccl-decode-region)
941 (mel-define-method-function
942 (mime-write-decoded-region start end filename (nil "quoted-printable"))
943 'quoted-printable-ccl-write-decoded-region)
949 (defun q-encoding-ccl-encode-string (string &optional mode)
950 "Encode STRING to Q-encoding of encoded-word, and return the result.
951 MODE allows `text', `comment', `phrase' or nil. Default value is
953 (decode-coding-string
956 ((eq mode 'text) 'mel-ccl-uq-rev)
957 ((eq mode 'comment) 'mel-ccl-cq-rev)
958 (t 'mel-ccl-pq-rev))))
960 (defun q-encoding-ccl-decode-string (string)
961 "Decode Q encoded STRING and return the result."
962 (encode-coding-string
966 (unless (featurep 'xemacs)
967 (defun q-encoding-ccl-encoded-length (string &optional mode)
968 (let ((status [nil nil nil nil nil nil nil nil nil]))
969 (fillarray status nil) ; XXX: Is this necessary?
970 (ccl-execute-on-string
972 ((eq mode 'text) 'mel-ccl-count-uq)
973 ((eq mode 'comment) 'mel-ccl-count-cq)
974 (t 'mel-ccl-count-pq))
980 (mel-define-method-function (encoded-text-encode-string string (nil "Q"))
981 'q-encoding-ccl-encode-string)
983 (mel-define-method encoded-text-decode-string (string (nil "Q"))
984 (if (string-match (eval-when-compile
985 (concat "\\`" Q-encoded-text-regexp "\\'"))
987 (q-encoding-ccl-decode-string string)
988 (error "Invalid encoded-text %s" string)))
996 ;;; mel-q-ccl.el ends here.