root/trunk/thirdparty/cl-mime/headers.lisp

Revision 2045, 2.7 kB (checked in by hhubner, 2 years ago)

merge back from branches/xml-class-rework to trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to author date id revision
Line 
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;;;; headers.lisp: Tools for handling headers
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 (defgeneric get-header (mime-obj header)
26   (:documentation
27    "Returns a cons of header name (in keyword format) and value"))
28    
29
30 (defmethod get-header ((mime-obj mime) (header (eql :content-type)))
31   (cons header
32         (format nil "~A/~A~A~A"
33                 (content-type mime-obj)
34                 (content-subtype mime-obj)
35                 ;; Required parameters for particular MIME types
36                 (typecase mime-obj
37                   (text-mime
38                    (format nil "; charset=~A"
39                            (charset mime-obj)))
40                   (multipart-mime
41                    (format nil "; boundary=\"~A\""
42                            (boundary mime-obj)))
43                   (otherwise ""))
44                 ;; All remaining parameters defined by the user
45                 (format nil "~{~{;~%~5,5T~A=\"~A\"~}~}"
46                         (mapcar
47                          (lambda (parm-pair)
48                            (cons (string-downcase (symbol-name (car parm-pair)))
49                                  (cdr parm-pair)))
50                          (content-type-parameters mime-obj))))))
51
52
53 (defmethod get-header ((mime-obj mime) (header (eql :content-disposition)))
54   (when (content-disposition mime-obj)
55     (cons header
56           (format nil "~A~A"
57                   (content-disposition mime-obj)
58                   (format nil "~{~{;~%~5,5T~A=\"~A\"~}~}"
59                           (mapcar
60                            (lambda (parm-pair)
61                              (cons (string-downcase (symbol-name (car parm-pair)))
62                                    (cdr parm-pair)))
63                            (content-disposition-parameters mime-obj)))))))
64
65
66 (defmethod get-header ((mime-obj mime) (header symbol))
67   (aif (slot-value mime-obj (intern (string header) :mime))
68        (cons (ensure-keyword header) it)))
69
70
71 (defun get-mime-headers (mime-obj)
72   "Retrieves all known headers in mime-obj"
73   (declare (mime mime-obj))
74   (delete nil (mapcar (lambda (header)
75                         (get-header mime-obj header))
76                       '(:mime-version
77                         :content-type
78                         :content-transfer-encoding
79                         :content-description
80                         :content-id
81                         :content-disposition))))
Note: See TracBrowser for help on using the browser.