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

Revision 2807, 4.8 kB (checked in by hans, 10 months ago)

update to cl-mime-0.5.3

  • Property svn:eol-style set to native
  • Property svn:keywords set to author date id revision
Line 
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;;;; classes.lisp: MIME classes and generalised method definitions
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 (defclass mime ()
26   ((content-type
27     :reader content-type
28     :initarg :type
29     :initform (error "MIME objects must have a type"))
30    (content-subtype
31     :reader content-subtype
32     :initarg :subtype
33     :initform (error "MIME objects must have a subtype"))
34    (content-type-parameters
35     :accessor content-type-parameters
36     :initarg :parameters
37     :type list
38     :initform nil)
39    (content-id
40     :accessor content-id
41     :initarg :id
42     :initform nil)
43    (content-description
44     :accessor content-description
45     :initform nil
46     :initarg :description)
47    (content-transfer-encoding
48     :accessor content-transfer-encoding
49     :initarg :encoding
50     :initform :7bit
51     :documentation
52     "Encoding to use when printing the MIME content.
53 May be :7BIT :BASE64 or :QUOTED-PRINTABLE")
54    (content-encoding
55     :accessor content-encoding
56     :initarg :content-encoding
57     :initform :7bit
58     :documentation "Encoding the MIME content is currently in.
59 May be :7BIT :BASE64 or :QUOTED-PRINTABLE")
60    (content-disposition
61     :accessor content-disposition
62     :initarg :disposition
63     :initform nil)
64    (content-disposition-parameters
65     :accessor content-disposition-parameters
66     :initarg :disposition-parameters
67     :type list
68     :initform nil)
69    (content
70     :accessor content
71     :initform nil
72     :initarg :content)
73    (mime-version
74     :accessor mime-version
75     :initarg :version
76     :initform "1.0"))
77   (:documentation "Standard MIME Object Representation"))
78
79
80 (defclass text-mime (mime)
81   ((content-type
82     :reader content-type
83     :initform "text")
84    (content-subtype
85     :reader content-subtype
86     :initform "plain"
87     :initarg :subtype)
88    (charset
89     :accessor charset
90     :initarg :charset
91     :initform "us-ascii"))
92   (:documentation "Text MIME Object Representation"))
93
94
95 (defclass multipart-mime (mime)
96   ((content-type
97     :reader content-type
98     :initform "multipart")
99    (content
100     :accessor content
101     :initarg :content
102     :type list)
103    (boundary
104     :accessor boundary
105     :initarg :boundary
106     :initform (make-boundary))
107    (prologue
108     :accessor prologue
109     :initform nil
110     :initarg :prologue
111     :type (or null string))
112    (epilogue
113     :accessor epilogue
114     :initform nil
115     :initarg :epilogue
116     :type (or null string)))
117   (:documentation "Multipart Mime Object Representation"))
118    
119 ;;; This boundary contains text which should never appear in the
120 ;;; message body. Hopefully that big random number converted to base
121 ;;; 36 (all numbers and alphabet) will be good enough for guaranteeing that.
122 (defun make-boundary ()
123   "This just makes a boundary out of random junk"
124   (format nil "=_cl-mime~36,,,,R" (* (get-universal-time)
125                                      (random 100000000000000000000))))
126
127
128 ;;; This content-id needs to be unique for every message. The assumption
129 ;;; here is that in the world make-content-id should only be
130 ;;; called a few (less than 1000000000000000000) times per second. We hope
131 ;;; short-site-name actually returning something to narrow
132 ;;; the value down more.
133 (defun make-content-id ()
134   "Make a Content-ID header value"
135   (format nil "~A.~A.cl-mime@~A"
136           (get-universal-time)
137           (random 1000000000000000000)
138           (short-site-name)))
139
140
141 (defun get-content-type-parameter (mime-obj parameter-name)
142   "Provided a parameter name in the form of a keyword, will get the
143 corresponding value from the parameter list of the Content-Type header"
144   (second (assoc
145            (ensure-keyword parameter-name)
146            (content-type-parameters mime-obj))))
147
148
149 (defun get-content-disposition-parameter (mime-obj parameter-name)
150   "Provided a parameter name in the form of a keyword, will get the
151 corresponding value from the parameter list of the Content-Disposition
152 header"
153   (second (assoc
154            (ensure-keyword parameter-name)
155            (content-disposition-parameters mime-obj))))
156
Note: See TracBrowser for help on using the browser.