Browse code
2006-01-26 Kevin Layer <layer@gemini>
layer authored on 27/01/2006 01:28:58
Showing 2 changed files
Showing 2 changed files
... | ... |
@@ -1,6 +1,8 @@ |
1 | 1 |
2006-01-26 Kevin Layer <layer@gemini> |
2 | 2 |
|
3 | 3 |
* mime.cl: provide |
4 |
+ * mime-transfer-encoding.cl: remove excl::*to-base64* and |
|
5 |
+ base64-encode-stream (since they're in the base lisp now) |
|
4 | 6 |
* smtp.cl: require streamp and mime |
5 | 7 |
|
6 | 8 |
2006-01-26 Ahmon Dancy <dancy@dancy> |
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-;; $Id: mime-transfer-encoding.cl,v 1.1 2006/01/26 23:53:27 dancy Exp $ |
|
1 |
+;; $Id: mime-transfer-encoding.cl,v 1.2 2006/01/27 01:28:58 layer Exp $ |
|
2 | 2 |
|
3 | 3 |
(defpackage :net.post-office |
4 | 4 |
(:use #:lisp #:excl) |
... | ... |
@@ -21,85 +21,6 @@ |
21 | 21 |
(while (/= 0 (setf got (read-vector buf instream))) |
22 | 22 |
(write-vector buf outstream :end got)))) |
23 | 23 |
|
24 |
-;; Temporary until this change is made in excl.cl. |
|
25 |
-(defparameter excl::*to-base64* |
|
26 |
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/") |
|
27 |
- |
|
28 |
-;; This should be added to the excl package. |
|
29 |
-(defun base64-encode-stream (instream outstream &key (wrap-at 72)) |
|
30 |
- (declare (optimize (speed 3))) |
|
31 |
- ;; inbuf _must_ be a size which is a multiple of three. The |
|
32 |
- ;; encoding code depends on it. outbuf must be 4/3rds bigger than |
|
33 |
- ;; inbuf. |
|
34 |
- (let ((inbuf (make-array #.(* 3 4096) :element-type '(unsigned-byte 8))) |
|
35 |
- (outbuf (make-array #.(* 4 4096) :element-type 'character)) |
|
36 |
- remaining end outpos inpos value) |
|
37 |
- (declare (dynamic-extent inbuf outbuf) |
|
38 |
- (fixnum remaining outpos end inpos value)) |
|
39 |
- |
|
40 |
- (macrolet ((outchar (char) |
|
41 |
- `(progn |
|
42 |
- (setf (schar outbuf outpos) ,char) |
|
43 |
- (incf outpos))) |
|
44 |
- (outchar-base64 (x) |
|
45 |
- `(outchar (schar excl::*to-base64* (logand ,x 63))))) |
|
46 |
- |
|
47 |
- (flet ((read-full-vector (buf stream) |
|
48 |
- (let ((pos 0) |
|
49 |
- (max (length buf)) |
|
50 |
- newpos) |
|
51 |
- (declare (fixnum pos max got newpos)) |
|
52 |
- (while (< pos max) |
|
53 |
- (setf newpos (read-vector buf stream :start pos)) |
|
54 |
- (if* (= newpos pos) |
|
55 |
- then (return)) |
|
56 |
- (setf pos newpos)) |
|
57 |
- pos))) |
|
58 |
- |
|
59 |
- (while (/= 0 (setf end (read-full-vector inbuf instream))) |
|
60 |
- (setf remaining end) |
|
61 |
- (setf inpos 0) |
|
62 |
- (setf outpos 0) |
|
63 |
- (while (> remaining 0) |
|
64 |
- (if* (>= remaining 3) |
|
65 |
- then (setf value (logior (ash (aref inbuf inpos) 16) |
|
66 |
- (ash (aref inbuf (+ 1 inpos)) 8) |
|
67 |
- (aref inbuf (+ 2 inpos)))) |
|
68 |
- (incf inpos 3) |
|
69 |
- (decf remaining 3) |
|
70 |
- (outchar-base64 (ash value -18)) |
|
71 |
- (outchar-base64 (ash value -12)) |
|
72 |
- (outchar-base64 (ash value -6)) |
|
73 |
- (outchar-base64 value) |
|
74 |
- elseif (= remaining 2) |
|
75 |
- then (setf value (logior (ash (aref inbuf inpos) 16) |
|
76 |
- (ash (aref inbuf (+ 1 inpos)) 8))) |
|
77 |
- (incf inpos 2) |
|
78 |
- (decf remaining 2) |
|
79 |
- (outchar-base64 (ash value -18)) |
|
80 |
- (outchar-base64 (ash value -12)) |
|
81 |
- (outchar-base64 (ash value -6)) |
|
82 |
- (outchar #\=) |
|
83 |
- else (setf value (ash (aref inbuf inpos) 16)) |
|
84 |
- (incf inpos) |
|
85 |
- (decf remaining) |
|
86 |
- (outchar-base64 (ash value -18)) |
|
87 |
- (outchar-base64 (ash value -12)) |
|
88 |
- (outchar #\=) |
|
89 |
- (outchar #\=))) |
|
90 |
- |
|
91 |
- ;; generate output. |
|
92 |
- (if* (null wrap-at) |
|
93 |
- then (write-string outbuf outstream :end outpos) |
|
94 |
- else (setf inpos 0) |
|
95 |
- (while (< inpos outpos) |
|
96 |
- (let ((len (min (- outpos inpos) wrap-at))) |
|
97 |
- (write-string outbuf outstream |
|
98 |
- :start inpos |
|
99 |
- :end (+ inpos len)) |
|
100 |
- (incf inpos len) |
|
101 |
- (write-char #\newline outstream))))))))) |
|
102 |
- |
|
103 | 24 |
(defconstant *qp-hex-digits* "0123456789ABCDEF") |
104 | 25 |
|
105 | 26 |
;; wrap-at is not a hard limit but more of a suggestion. it may be |