| 1 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|---|
| 2 |
;;;; encoding.lisp: Tools for converting content encoding |
|---|
| 3 |
;;;; Copyright (C) 2004 Robert Marlow <bobstopper@bobturf.org> |
|---|
| 4 |
;;;; |
|---|
| 5 |
;;;; This library is free software; you can redistribute it and/or |
|---|
| 6 |
;;;; modify it under the terms of the GNU Library General Public |
|---|
| 7 |
;;;; License as published by the Free Software Foundation; either |
|---|
| 8 |
;;;; version 2 of the License, or (at your option) any later version. |
|---|
| 9 |
;;;; |
|---|
| 10 |
;;;; This library is distributed in the hope that it will be useful, |
|---|
| 11 |
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 |
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 13 |
;;;; Library General Public License for more details. |
|---|
| 14 |
;;;; |
|---|
| 15 |
;;;; You should have received a copy of the GNU Library General Public |
|---|
| 16 |
;;;; License along with this library; if not, write to the |
|---|
| 17 |
;;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|---|
| 18 |
;;;; Boston, MA 02111-1307, USA. |
|---|
| 19 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
(in-package :mime) |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
(defun encode-content (mime) |
|---|
| 27 |
(if (eql (content-transfer-encoding mime) |
|---|
| 28 |
(content-encoding mime)) |
|---|
| 29 |
(content mime) |
|---|
| 30 |
(let ((content (decode-content mime))) |
|---|
| 31 |
(ecase (content-transfer-encoding mime) |
|---|
| 32 |
(:7bit content) |
|---|
| 33 |
(:base64 |
|---|
| 34 |
(typecase content |
|---|
| 35 |
(string (string-to-base64-string content :columns 75)) |
|---|
| 36 |
((array (unsigned-byte 8)) |
|---|
| 37 |
(usb8-array-to-base64-string content :columns 75)))) |
|---|
| 38 |
(:quoted-printable (qprint:encode content :columns 75)))))) |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
(defun decode-content (mime) |
|---|
| 42 |
(ecase (content-encoding mime) |
|---|
| 43 |
(:7bit (content mime)) |
|---|
| 44 |
(:base64 (base64-string-to-usb8-array (content mime))) |
|---|
| 45 |
(:quoted-printable (qprint:decode (content mime))))) |
|---|
| 46 |
|
|---|