10 (defconst mel-ccl-4-table
13 (defconst mel-ccl-16-table
14 '( 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))
16 (defconst mel-ccl-28-table
17 '( 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
18 16 17 18 19 20 21 22 23 24 25 26 27))
20 (defconst mel-ccl-64-table
21 '( 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
22 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
23 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
24 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63))
26 (defconst mel-ccl-256-table
27 '( 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
28 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
29 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
30 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
31 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
32 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
33 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
34 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
35 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
36 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
37 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
38 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
39 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
40 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
41 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
42 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255))
44 (defconst mel-ccl-256-to-16-table
45 '(nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
46 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
47 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
48 0 1 2 3 4 5 6 7 8 9 nil nil nil nil nil nil
49 nil 10 11 12 13 14 15 nil nil nil nil nil nil nil nil nil
50 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
51 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
52 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
53 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
54 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
55 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
56 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
57 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
58 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
59 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
60 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil))
62 (defconst mel-ccl-16-to-256-table
63 (mapcar 'char-int "0123456789ABCDEF"))
65 (defconst mel-ccl-high-table
68 (lambda (v) (nth (lsh v -4) mel-ccl-16-to-256-table))
71 (defconst mel-ccl-low-table
74 (lambda (v) (nth (logand v 15) mel-ccl-16-to-256-table))
77 (defconst mel-ccl-u-raw
81 ABCDEFGHIJKLMNOPQRSTUVWXYZ\
82 abcdefghijklmnopqrstuvwxyz\
83 !@#$%&'()*+,-./:;<>@[\\]^`{|}~"))
85 (defconst mel-ccl-c-raw
89 ABCDEFGHIJKLMNOPQRSTUVWXYZ\
90 abcdefghijklmnopqrstuvwxyz\
91 !@#$%&'*+,-./:;<>@[]^`{|}~"))
93 (defconst mel-ccl-p-raw
97 ABCDEFGHIJKLMNOPQRSTUVWXYZ\
98 abcdefghijklmnopqrstuvwxyz\
101 (defconst mel-ccl-256-to-64-table
102 '(nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
103 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
104 nil nil nil nil nil nil nil nil nil nil nil 62 nil nil nil 63
105 52 53 54 55 56 57 58 59 60 61 nil nil nil t nil nil
106 nil 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
107 15 16 17 18 19 20 21 22 23 24 25 nil nil nil nil nil
108 nil 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
109 41 42 43 44 45 46 47 48 49 50 51 nil nil nil nil nil
110 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
111 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
112 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
113 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
114 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
115 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
116 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
117 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil))
119 (defconst mel-ccl-64-to-256-table
122 "ABCDEFGHIJKLMNOPQRSTUVWXYZ\
123 abcdefghijklmnopqrstuvwxyz\
127 (defconst mel-ccl-qp-table
128 [enc enc enc enc enc enc enc enc enc wsp lf enc enc cr enc enc
129 enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc
130 wsp raw raw raw raw raw raw raw raw raw raw raw raw raw raw raw
131 raw raw raw raw raw raw raw raw raw raw raw raw raw enc raw raw
132 raw raw raw raw raw raw raw raw raw raw raw raw raw raw raw raw
133 raw raw raw raw raw raw raw raw raw raw raw raw raw raw raw raw
134 raw raw raw raw raw raw raw raw raw raw raw raw raw raw raw raw
135 raw raw raw raw raw raw raw raw raw raw raw raw raw raw raw enc
136 enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc
137 enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc
138 enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc
139 enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc
140 enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc
141 enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc
142 enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc
143 enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc enc])
153 (define-ccl-program mel-ccl-decode-q
161 ((= r0 (char-int ?_))
163 ((= r0 (char-int ?=))
172 mel-ccl-256-to-16-table)))
179 `((write r0 ,(vconcat
182 (logior (lsh r0 4) v))
186 mel-ccl-256-to-16-table)))
189 `(write-repeat ,r0))))
190 mel-ccl-256-table))))))
192 (define-ccl-program mel-ccl-encode-uq
201 ((= r0 32) `(write-repeat ?_))
202 ((member r0 mel-ccl-u-raw) `(write-repeat ,r0))
206 (write r0 ,mel-ccl-high-table)
207 (write r0 ,mel-ccl-low-table)
210 (define-ccl-program mel-ccl-encode-cq
219 ((= r0 32) `(write-repeat ?_))
220 ((member r0 mel-ccl-c-raw) `(write-repeat ,r0))
224 (write r0 ,mel-ccl-high-table)
225 (write r0 ,mel-ccl-low-table)
228 (define-ccl-program mel-ccl-encode-pq
237 ((= r0 32) `(write-repeat ?_))
238 ((member r0 mel-ccl-p-raw) `(write-repeat ,r0))
242 (write r0 ,mel-ccl-high-table)
243 (write r0 ,mel-ccl-low-table)
249 (defun mel-ccl-decode-b-bit-ex (v)
251 (lsh (logand v (lsh 255 16)) -16)
252 (logand v (lsh 255 8))
253 (lsh (logand v 255) 16)))
255 (defconst mel-ccl-decode-b-0-table
260 (mel-ccl-decode-b-bit-ex (lsh v 18))
262 mel-ccl-256-to-64-table)))
264 (defconst mel-ccl-decode-b-1-table
269 (mel-ccl-decode-b-bit-ex (lsh v 12))
271 mel-ccl-256-to-64-table)))
273 (defconst mel-ccl-decode-b-2-table
278 (mel-ccl-decode-b-bit-ex (lsh v 6))
280 mel-ccl-256-to-64-table)))
282 (defconst mel-ccl-decode-b-3-table
287 (mel-ccl-decode-b-bit-ex v)
289 mel-ccl-256-to-64-table)))
293 (define-ccl-program mel-ccl-decode-b
297 (r4 = r0 ,mel-ccl-decode-b-0-table)
298 (r5 = r1 ,mel-ccl-decode-b-1-table)
300 (r5 = r2 ,mel-ccl-decode-b-2-table)
302 (r5 = r3 ,mel-ccl-decode-b-3-table)
304 (if (r4 & ,(lognot (1- (lsh 1 24))))
306 (if (r4 & ,(lsh 1 24))
307 ((r0 = r1) (r1 = r2) (r2 = r3) (read r3)
308 (r4 >>= 1) (r4 &= ,(logior (lsh 7 24)))
309 (r5 = r3 ,mel-ccl-decode-b-3-table)
314 (if (r4 & ,(lsh 1 25))
315 ((r1 = r2) (r2 = r3) (read r3)
316 (r4 >>= 1) (r4 &= ,(logior (lsh 7 24)))
317 (r5 = r3 ,mel-ccl-decode-b-3-table)
323 (if (r4 & ,(lsh 1 26))
325 (r4 >>= 1) (r4 &= ,(logior (lsh 7 24)))
326 (r5 = r3 ,mel-ccl-decode-b-3-table)
335 (if (r4 & ,(lsh 1 27))
337 (r4 = r3 ,mel-ccl-decode-b-3-table)
342 (r4 = r0 ,mel-ccl-decode-b-0-table)
343 (r5 = r1 ,mel-ccl-decode-b-1-table)
348 ((r5 = r2 ,mel-ccl-decode-b-2-table)
350 (r5 = r3 ,mel-ccl-decode-b-3-table)
361 ((r5 = r2 ,mel-ccl-decode-b-2-table)
374 (write-repeat r4))))))
378 ;; mel-ccl-encode-b works only 20.3 or later because CCL_EOF_BLOCK
379 ;; is not executed on 20.2 (or former?).
380 (define-ccl-program mel-ccl-encode-b
388 `((write ,(nth (lsh r1 -2) mel-ccl-64-to-256-table))
389 (r0 = ,(logand r1 3))))
396 `((write r0 ,(vconcat
399 (nth (logior (lsh r0 4)
401 mel-ccl-64-to-256-table))
403 (r0 = ,(logand r1 15))))
410 `((write r0 ,(vconcat
413 (nth (logior (lsh r0 2)
415 mel-ccl-64-to-256-table))
416 mel-ccl-16-table)))))
422 (nth r1 mel-ccl-64-to-256-table))
431 (nth (lsh r0 4) mel-ccl-64-to-256-table))
437 (nth (lsh r0 2) mel-ccl-64-to-256-table))
444 ;; mel-ccl-encode-base64 does not works on 20.2 by same reason of mel-ccl-encode-b
445 (define-ccl-program mel-ccl-encode-base64-crlf-crlf
454 `((write ,(nth (lsh r1 -2) mel-ccl-64-to-256-table))
455 (r0 = ,(logand r1 3))))
462 `((write r0 ,(vconcat
465 (nth (logior (lsh r0 4)
467 mel-ccl-64-to-256-table))
469 (r0 = ,(logand r1 15))))
476 `((write r0 ,(vconcat
479 (nth (logior (lsh r0 2)
481 mel-ccl-64-to-256-table))
482 mel-ccl-16-table)))))
488 (nth r1 mel-ccl-64-to-256-table))
491 (if (r3 == 19) ; 4 * 19 = 76 --> line break.
497 (if (r0 > 0) (write "\r\n"))
501 (nth (lsh r0 4) mel-ccl-64-to-256-table))
507 (nth (lsh r0 2) mel-ccl-64-to-256-table))
512 ;; produce newline as LF instead of CRLF.
513 (define-ccl-program mel-ccl-encode-base64-crlf-lf
522 `((write ,(nth (lsh r1 -2) mel-ccl-64-to-256-table))
523 (r0 = ,(logand r1 3))))
530 `((write r0 ,(vconcat
533 (nth (logior (lsh r0 4)
535 mel-ccl-64-to-256-table))
537 (r0 = ,(logand r1 15))))
544 `((write r0 ,(vconcat
547 (nth (logior (lsh r0 2)
549 mel-ccl-64-to-256-table))
550 mel-ccl-16-table)))))
556 (nth r1 mel-ccl-64-to-256-table))
559 (if (r3 == 19) ; 4 * 19 = 76 --> line break.
565 (if (r0 > 0) (write "\n"))
569 (nth (lsh r0 4) mel-ccl-64-to-256-table))
575 (nth (lsh r0 2) mel-ccl-64-to-256-table))
584 ;; mel-ccl-encode-quoted-printable does not works on 20.2 by same reason of mel-ccl-encode-b
585 (defun mel-ccl-encode-quoted-printable-generic (input-crlf output-crlf)
588 (r5 = 0) ; previous character is white space
598 (let ((tmp (aref mel-ccl-qp-table r0)))
600 ((eq tmp 'raw) '((r3 = 0) (break))) ; RAW
601 ((eq tmp 'enc) '((r3 = 1) (break))) ; ENC
602 ((eq tmp 'wsp) '((r3 = 2) (break))) ; WSP
603 ((eq tmp 'cr) (if input-crlf
604 '((r3 = 3) (break)) ; CR
605 '((r3 = 1) (break)))) ; ENC
606 ((eq tmp 'lf) (if input-crlf
607 '((r3 = 1) (break)) ; ENC
608 '((r3 = 3) (break)))) ; CRLF
618 (write-read-repeat r0))
625 (write r0 ,mel-ccl-high-table)
627 (write-read-repeat r0 ,mel-ccl-low-table))
630 (write ,(if output-crlf "=\r\n=" "=\n="))
631 (write r0 ,mel-ccl-high-table)
633 (write-read-repeat r0 ,mel-ccl-low-table))
640 (write-read-repeat r0))
642 (write ,(if output-crlf "=\r\n" "=\n"))
644 (write-read-repeat r0))))
648 `((if ((r6 > 73) & r5)
651 (write ,(if output-crlf "=\r\n" "=\n"))))
658 (write ,(if output-crlf "=\r\n" "=\n"))
659 ,@(if output-crlf '((write ?\r)) '())
660 (write-read-repeat r0))
661 ;; noWSP ; r0:r3=CRLF
664 ,@(if output-crlf '((write ?\r)) '())
665 (write-read-repeat r0)))
667 ;; r0:r3={RAW,ENC,CR}
670 (lambda (after-cr after-raw-enc)
683 ;; r5=WSP ; CR:r3=CR r0=LF
686 (write ,(if output-crlf "=\r\n\r\n" "=\n\n"))
690 ;; r5=noWSP ; CR:r3=CR r0=LF
693 (write ,(if output-crlf "\r\n" "\n"))
713 (write ,(if output-crlf "=0D\r\n" "=0D\n"))
720 (write ,(if output-crlf "=\r\n=0D=0D" "=\n=0D=0D"))
722 ;; CR:r3=CR r0=noLFnorCR
725 (write ,(if output-crlf "=\r\n=0D" "=\n=0D"))
729 (write ,(if output-crlf "=\r\n=0D" "=\n=0D"))
732 (lambda (after-newline after-cr-nolf after-nonewline)
737 ;; r0:r3={RAW,ENC} r1
739 ;; r0:r3={RAW,ENC} r1=CR
742 ;; r0:r3={RAW,ENC} CR r1
744 ;; r0:r3=RAW CR r1=LF
746 ;; r0:r3=RAW CR r1=noLF
748 ;; r0:r3={RAW,ENC} r1:noCR
753 ;; r0:r3={RAW,ENC} r1
755 ;; r0:r3={RAW,ENC} r1=CRLF
757 ;; r0:r3={RAW,ENC} r1:noCRLF
759 ;; r0:r3={RAW,ENC} CR r1=LF
760 ;; r0:r3={RAW,ENC} r1=CRLF
765 ;; r0:r3=RAW CR r1=LF
768 (write ,(if output-crlf "\r\n" "\n"))
772 ;; r0:r3=ENC CR r1=LF
775 (write r0 ,mel-ccl-high-table)
776 (write r0 ,mel-ccl-low-table)
777 (write ,(if output-crlf "\r\n" "\n"))
781 ;; r0:r3={RAW,ENC} CR r1=noLF
784 ;; r0:r3=RAW CR r1:noLF
787 (write ,(if output-crlf "=\r\n" "=\n"))
792 ;; r0:r3=ENC CR r1:noLF
795 (write ,(if output-crlf "=\r\n=" "=\n="))
796 (write r0 ,mel-ccl-high-table)
797 (write r0 ,mel-ccl-low-table)
801 ;; r0:r3={RAW,ENC} r1:noCR
802 ;; r0:r3={RAW,ENC} r1:noCRLF
806 ;; r0:r3=RAW r1:noCRLF
809 (write ,(if output-crlf "=\r\n" "=\n"))
814 ;; r0:r3=ENC r1:noCRLF
817 (write ,(if output-crlf "=\r\n=" "=\n="))
818 (write r0 ,mel-ccl-high-table)
819 (write r0 ,mel-ccl-low-table)
824 ( ;(write "[EOF:") (write r4 ,mel-ccl-high-table) (write r4 ,mel-ccl-low-table) (write "]")
833 ;; 3: SOFTBREAK r0:r3=ENC ;
836 ((write ,(if output-crlf "=\r\n" "=\n")) (end))
837 ;; 5: SOFTBREAK r0:r3=WSP ;
838 ((write ,(if output-crlf "=\r\n" "=\n")) (end))
841 ((write "=0D") (end))
842 ((write ,(if output-crlf "=\r\n=0D" "=\n=0D")) (end)))
843 ;; 7: r5=WSP SOFTBREAK CR:r3=CR r0=LF ;
845 ;; 8: r5=noWSP CR:r3=CR r0=LF ;
847 ;; 9: (r6=73) ; CR:r3=CR r0=CR
848 ((write ,(if output-crlf "=\r\n=0D=0D" "=\n=0D=0D")) (end))
849 ;; 10: (r6=73) CR:r3=CR CR LF ;
851 ;; 11: ; r0:r3={RAW,ENC}
856 (write r0 ,mel-ccl-high-table)
857 (write r0 ,mel-ccl-low-table)
859 ;; 12: ; r0:r3={RAW,ENC} r1=CR
863 ((write ,(if output-crlf "=\r\n" "=\n"))
868 ((write ,(if output-crlf "=\r\n=" "=\n="))
869 (write r0 ,mel-ccl-high-table)
870 (write r0 ,mel-ccl-low-table)
873 ;; 13: r0:r3=RAW CR LF ;
874 ;; 13: r0:r3=RAW CRLF ;
876 ;; 14: r0:r3=ENC CR LF ;
877 ;; 14: r0:r3=ENC CRLF ;
882 (defun mel-ccl-decode-quoted-printable-generic (input-crlf output-crlf)
890 (let ((tmp (aref mel-ccl-qp-table r0)))
892 ((eq tmp 'raw) `(write-read-repeat r0))
893 ((eq tmp 'wsp) (if (eq r0 (char-int ? ))
903 ;; hard line break found.
906 (write-read-repeat r0))
907 '(write-read-repeat r0))
909 ;; invalid control character (bare CR) found.
910 ;; -> ignore it and rescan from r0.
913 ;; invalid character (bare CR) found.
920 ;; invalid character (bare LF) found.
925 ;; hard line break found.
928 (write-read-repeat r0))
929 '(write-read-repeat r0))))
930 ((eq r0 (char-int ?=))
935 (if ((r0 == ? ) | r1)
937 ;; Skip transport-padding.
938 ;; It should check CR LF after
939 ;; transport-padding.
946 ;; '=' [\t ]* r0:[^\t ]
952 ((eq r0 (char-int ?\r))
954 ;; '=' [\t ]* r0='\r'
956 ;; '=' [\t ]* '\r' r0
958 ;; '=' [\t ]* '\r' r0='\n'
959 ;; soft line break found.
962 ;; '=' [\t ]* '\r' r0:[^\n]
964 ;; output "=" and rescan from r0.
967 ;; '=' [\t ]* r0='\r'
968 ;; invalid input (bare CR found) ->
969 ;; output "=" and rescan from next.
973 ((eq r0 (char-int ?\n))
975 ;; '=' [\t ]* r0='\n'
976 ;; invalid input (bare LF found) ->
977 ;; output "=" and rescan from next.
981 ;; '=' [\t ]* r0='\r\n'
982 ;; soft line break found.
985 ((setq tmp (nth r0 mel-ccl-256-to-16-table))
986 ;; '=' [\t ]* r0:[0-9A-F]
987 ;; upper nibble of hexadecimal digit found.
991 ;; '=' [\t ]* r0:[^\r0-9A-F]
993 ;; output "=" and rescan from r0.
997 ;; '=' [\t ]* r1:r0:[0-9A-F]
1002 (if (setq tmp (nth r2 mel-ccl-256-to-16-table))
1003 ;; '=' [\t ]* r1:r0:[0-9A-F] r2:[0-9A-F]
1009 (logior (lsh r0 4) tmp))
1011 ;; '=' [\t ]* r1:r0:[0-9A-F] r2:[^0-9A-F]
1016 ;; '=' [\t ]* r1:r0:[0-9A-F] r2:[^0-9A-F]
1018 ;; output "=" with hex digit and rescan from r2.
1024 ;; invalid character found.
1035 (let ((reg (aref [r1 r2 r3 r4 r5] regnum)))
1048 ((r6 = ,(+ (* regnum 28) bit))
1052 (,reg |= ,(lsh 1 bit))
1054 ((r6 = ,(+ (* regnum 28) bit))
1056 mel-ccl-28-table))))
1058 ;; white space buffer exhaust.
1059 ;; error: line length limit (76bytes) violation.
1060 ;; -> ignore these white spaces.
1066 ;; trailing white spaces found.
1067 ;; -> ignore these white spacs.
1068 ((write ,(if output-crlf "\r\n" "\n"))
1071 ;; [\t ]* \r r0:[^\n]
1072 ;; error: bare CR found.
1073 ;; -> output white spaces and ignore bare CR.
1076 ;; middle white spaces found.
1079 ;; trailing white spaces found.
1080 ;; -> ignore these white spacs.
1081 ((write ,(if output-crlf "\r\n" "\n"))
1085 ;; middle white spaces found.
1091 (let ((reg (aref [r1 r2 r3 r4 r5] regnum)))
1096 `((if (,reg & ,(lsh 1 bit))
1099 (if (r6 == ,(+ (* regnum 28) bit 1))
1101 mel-ccl-28-table))))
1108 (define-ccl-program mel-ccl-encode-quoted-printable-crlf-crlf
1109 (mel-ccl-encode-quoted-printable-generic t t))
1111 (define-ccl-program mel-ccl-encode-quoted-printable-crlf-lf
1112 (mel-ccl-encode-quoted-printable-generic t nil))
1114 (define-ccl-program mel-ccl-encode-quoted-printable-lf-crlf
1115 (mel-ccl-encode-quoted-printable-generic nil t))
1117 (define-ccl-program mel-ccl-encode-quoted-printable-lf-lf
1118 (mel-ccl-encode-quoted-printable-generic nil nil))
1120 (define-ccl-program mel-ccl-decode-quoted-printable-crlf-crlf
1121 (mel-ccl-decode-quoted-printable-generic t t))
1123 (define-ccl-program mel-ccl-decode-quoted-printable-crlf-lf
1124 (mel-ccl-decode-quoted-printable-generic t nil))
1126 (define-ccl-program mel-ccl-decode-quoted-printable-lf-crlf
1127 (mel-ccl-decode-quoted-printable-generic nil t))
1129 (define-ccl-program mel-ccl-decode-quoted-printable-lf-lf
1130 (mel-ccl-decode-quoted-printable-generic nil nil))
1136 (make-ccl-coding-system
1137 'mel-ccl-uq-rev ?Q "MIME Q-encoding in unstructured field (reversed)"
1138 'mel-ccl-encode-uq 'mel-ccl-decode-q)
1140 (make-ccl-coding-system
1141 'mel-ccl-cq-rev ?Q "MIME Q-encoding in comment (reversed)"
1142 'mel-ccl-encode-cq 'mel-ccl-decode-q)
1144 (make-ccl-coding-system
1145 'mel-ccl-pq-rev ?Q "MIME Q-encoding in phrase (reversed)"
1146 'mel-ccl-encode-pq 'mel-ccl-decode-q)
1148 (make-ccl-coding-system
1149 'mel-ccl-b-rev ?B "MIME B-encoding (reversed)"
1150 'mel-ccl-encode-b 'mel-ccl-decode-b)
1152 (make-ccl-coding-system
1153 'mel-ccl-quoted-printable-crlf-crlf-rev
1154 ?Q "MIME Quoted-Printable-encoding (reversed)"
1155 'mel-ccl-encode-quoted-printable-crlf-crlf
1156 'mel-ccl-decode-quoted-printable-crlf-crlf)
1158 (make-ccl-coding-system
1159 'mel-ccl-quoted-printable-lf-crlf-rev
1160 ?Q "MIME Quoted-Printable-encoding (LF encoding) (reversed)"
1161 'mel-ccl-encode-quoted-printable-crlf-lf
1162 'mel-ccl-decode-quoted-printable-lf-crlf)
1164 (make-ccl-coding-system
1165 'mel-ccl-quoted-printable-crlf-lf-rev
1166 ?Q "MIME Quoted-Printable-encoding (LF internal) (reversed)"
1167 'mel-ccl-encode-quoted-printable-lf-crlf
1168 'mel-ccl-decode-quoted-printable-crlf-lf)
1170 (make-ccl-coding-system
1171 'mel-ccl-quoted-printable-lf-lf-rev
1172 ?Q "MIME Quoted-Printable-encoding (LF encoding) (LF internal) (reversed)"
1173 'mel-ccl-encode-quoted-printable-lf-lf
1174 'mel-ccl-decode-quoted-printable-lf-lf)
1176 (make-ccl-coding-system
1177 'mel-ccl-base64-crlf-rev
1178 ?B "MIME Base64-encoding (reversed)"
1179 'mel-ccl-encode-base64-crlf-crlf
1182 (make-ccl-coding-system
1183 'mel-ccl-base64-lf-rev
1184 ?B "MIME Base64-encoding (LF encoding) (reversed)"
1185 'mel-ccl-encode-base64-crlf-lf
1192 (unless (and (boundp 'ccl-encoder-eof-block-is-broken)
1193 ccl-encoder-eof-block-is-broken)
1195 (defun base64-ccl-encode-string (string)
1196 "Encode STRING with base64 encoding."
1197 (decode-coding-string string 'mel-ccl-b-rev))
1199 (defun base64-ccl-encode-region (start end)
1200 "Encode region from START to END with base64 encoding."
1202 (decode-coding-region start end 'mel-ccl-b-rev))
1204 (defun base64-ccl-insert-encoded-file (filename)
1205 "Encode contents of file FILENAME to base64, and insert the result."
1206 (interactive (list (read-file-name "Insert encoded file: ")))
1207 (let ((coding-system-for-read 'mel-ccl-b-rev))
1208 (insert-file-contents filename)))
1212 (defun base64-ccl-decode-string (string)
1213 "Decode base64 encoded STRING"
1214 (string-as-unibyte (encode-coding-string string 'mel-ccl-b-rev)))
1216 (defun base64-ccl-decode-region (start end)
1217 "Decode base64 encoded the region from START to END."
1219 (encode-coding-region start end 'mel-ccl-b-rev))
1221 (defun base64-ccl-write-decoded-region (start end filename)
1222 "Decode the region from START to END and write out to FILENAME."
1224 (list (region-beginning) (region-end)
1225 (read-file-name "Write decoded region to file: ")))
1226 (let ((coding-system-for-write 'mel-ccl-b-rev))
1227 (write-region start end filename)))
1230 ;;; @ quoted-printable
1233 (unless (and (boundp 'ccl-encoder-eof-block-is-broken)
1234 ccl-encoder-eof-block-is-broken)
1236 (defun quoted-printable-ccl-encode-string (string)
1237 "Encode STRING with quoted-printable encoding."
1238 (decode-coding-string
1240 'mel-ccl-quoted-printable-lf-lf-rev))
1242 (defun quoted-printable-ccl-encode-region (start end)
1243 "Encode the region from START to END with quoted-printable
1246 (decode-coding-region start end 'mel-ccl-quoted-printable-lf-lf-rev))
1248 (defun quoted-printable-ccl-insert-encoded-file (filename)
1249 "Encode contents of the file named as FILENAME, and insert it."
1250 (interactive (list (read-file-name "Insert encoded file: ")))
1251 (let ((start (point)) end
1252 (coding-system-for-read 'mel-ccl-quoted-printable-lf-lf-rev))
1253 (insert-file-contents filename)))
1257 (defun quoted-printable-ccl-decode-string (string)
1258 "Decode quoted-printable encoded STRING."
1259 (encode-coding-string
1261 'mel-ccl-quoted-printable-lf-lf-rev))
1263 (defun quoted-printable-ccl-decode-region (start end)
1264 "Decode the region from START to END with quoted-printable
1267 (encode-coding-region start end 'mel-ccl-quoted-printable-lf-lf-rev))
1269 (defun quoted-printable-ccl-write-decoded-region
1270 (start end filename)
1271 "Decode quoted-printable encoded current region and write out to FILENAME."
1273 (list (region-beginning) (region-end)
1274 (read-file-name "Write decoded region to file: ")))
1275 (let ((coding-system-for-write 'mel-ccl-quoted-printable-lf-lf-rev))
1276 (write-region start end filename)))
1282 (defun q-encoding-ccl-encode-string (string &optional mode)
1283 "Encode STRING to Q-encoding of encoded-word, and return the result.
1284 MODE allows `text', `comment', `phrase' or nil. Default value is
1286 (decode-coding-string
1289 ((eq mode 'text) 'mel-ccl-uq-rev)
1290 ((eq mode 'comment) 'mel-ccl-cq-rev)
1291 (t 'mel-ccl-pq-rev))))
1293 (defun q-encoding-ccl-decode-string (string)
1294 "Decode Q encoded STRING and return the result."
1296 (encode-coding-string
1307 (let ((str0 "a\f \t\r
1308 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r
1309 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r
1310 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r
1311 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\f\r
1312 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\f\r
1313 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\f\r
1317 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \r
1318 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \r
1319 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \r
1320 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \r
1323 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\rccc\r
1324 ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\r\r\nccc\r
1325 ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\r\rccc\r
1326 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\rccc\r
1327 dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\r\neee\r
1328 dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\reee\r
1329 ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddeee\r
1331 str1 encoded decoded)
1332 (setq str1 (ew-crlf-to-lf str0)
1335 (decode-coding-string
1337 'mel-ccl-quoted-printable-crlf-crlf-rev)
1338 (decode-coding-string
1340 'mel-ccl-quoted-printable-lf-crlf-rev)
1341 (decode-coding-string
1343 'mel-ccl-quoted-printable-crlf-lf-rev)
1344 (decode-coding-string
1346 'mel-ccl-quoted-printable-lf-lf-rev))
1349 (encode-coding-string
1351 'mel-ccl-quoted-printable-crlf-crlf-rev)
1352 (encode-coding-string
1354 'mel-ccl-quoted-printable-lf-crlf-rev)
1355 (encode-coding-string
1357 'mel-ccl-quoted-printable-crlf-lf-rev)
1358 (encode-coding-string
1360 'mel-ccl-quoted-printable-lf-lf-rev)))
1362 (string= str0 (nth 0 decoded))
1363 (string= str0 (nth 1 decoded))
1364 (string= str1 (nth 2 decoded))
1365 (string= str1 (nth 3 decoded))))
1368 (defun make-ccl-coding-system (name mnemonic doc-string decoder encoder)
1370 name 'ccl doc-string
1371 (list 'mnemonic (char-to-string mnemonic)
1372 'decode (symbol-value decoder)
1373 'encode (symbol-value encoder))))