/[debian]/mimetic/branches/upstream/current/mimetic/message.h
ViewVC logotype

Contents of /mimetic/branches/upstream/current/mimetic/message.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 128 - (show annotations)
Sat Feb 25 16:49:20 2006 UTC (15 years, 5 months ago) by gregoa
File MIME type: text/plain
File size: 7069 byte(s)
[svn-inject] Installing original source of mimetic
1 /***************************************************************************
2 copyright : (C) 2002-2005 by Stefano Barbato
3 email : stefano@codesink.org
4
5 $Id: message.h,v 1.11 2005/03/07 15:35:08 tat Exp $
6 ***************************************************************************/
7
8 /***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16 #ifndef _MIMETIC_MESSAGE_H_
17 #define _MIMETIC_MESSAGE_H_
18 #include <time.h>
19 #include <sys/types.h>
20 #include <mimetic/libconfig.h>
21 #include <mimetic/mimeentity.h>
22 #include <mimetic/utils.h>
23 #include <mimetic/codec/codec.h>
24 #ifdef HAVE_UNISTD_H
25 #include <unistd.h>
26 #endif
27
28 namespace mimetic
29 {
30
31 class ContentType;
32
33 /// Base class for text/* MIME entities.
34 struct TextEntity: public MimeEntity
35 {
36 /**
37 * Sets its content-type to "text/unknown"
38 */
39 TextEntity();
40 TextEntity(const std::string& text);
41 /**
42 * Sets its content-type to "text/unknown",
43 * sets its body with the "text" variable and adds
44 * "charset=us-ascii" content-type parameter
45 */
46 TextEntity(const std::string& text, const std::string& charset);
47 };
48
49 /// text/plain entity class
50 /*!
51 TextPlain is a MimeEntity that defaults its ContentType to "text/plain"
52 and its charset to "us-ascii".
53 */
54 struct TextPlain: public TextEntity
55 {
56 TextPlain(const std::string& text);
57 /**
58 * constructs a TextPlain object, assigns <i>text</i> to its body and adds
59 * a ContentType::Param("charset", <i>charset</i>) to ContentType parameter list
60 */
61 TextPlain(const std::string& text, const std::string& charset);
62 };
63
64
65 /// text/enriched entity class
66 struct TextEnriched: public TextEntity
67 {
68 TextEnriched(const std::string& text);
69 /**
70 * constructs a TextPlain object, assigns <i>text</i> to its body and adds
71 * a ContentType::Param("charset", <i>charset</i>) to ContentType parameter list
72 */
73 TextEnriched(const std::string& text, const std::string& charset);
74 };
75
76 /// Base multipart/* class
77 /**
78 Base multipart/ * class. Its constructor sets the content-type
79 to "multipart/unknown" and adds and fills a "boundary" parameter
80 */
81 struct MultipartEntity: public MimeEntity
82 {
83 MultipartEntity();
84 };
85
86 /// multipart/mixed entity class
87 struct MultipartMixed: public MultipartEntity
88 {
89 MultipartMixed();
90 };
91
92 /// multipart/parallel entity class
93 struct MultipartParallel: public MultipartEntity
94 {
95 MultipartParallel();
96 };
97
98 /// multipart/alternative entity class
99 struct MultipartAlternative: public MultipartEntity
100 {
101 MultipartAlternative();
102 };
103
104 /// multipart/digest entity class
105 struct MultipartDigest: public MultipartEntity
106 {
107 MultipartDigest();
108 };
109
110
111 /// application/octect-stream entity class
112 struct ApplicationOctStream: public MimeEntity
113 {
114 ApplicationOctStream();
115 template<typename Codec>
116 ApplicationOctStream(const std::string&, const Codec& c=Base64::Encoder());
117 std::string type() const;
118 void type(const std::string&);
119 uint padding() const;
120 void padding(unsigned int);
121 bool operator()() const { return isValid(); }
122 bool isValid() const { return m_status; }
123 protected:
124 std::string m_fqn;
125 bool m_status;
126 };
127
128 /// Helper class to embed file attachments
129 struct Attachment: public MimeEntity
130 {
131 /**
132 * defaults to application/octect-stream
133 */
134 Attachment(const std::string&);
135 Attachment(const std::string&, const ContentType&);
136 template<typename Codec>
137 Attachment(const std::string&, const Codec& c );
138 template<typename Codec>
139 Attachment(const std::string&, const ContentType&, const Codec& c);
140 bool operator()() const { return isValid(); }
141 bool isValid() const { return m_status; }
142 private:
143 template<typename Codec>
144 void set(const std::string&, const ContentType&, const Codec& c);
145 std::string m_fqn;
146 bool m_status;
147 };
148
149 /// image/jpeg attachment
150 struct ImageJpeg: public Attachment
151 {
152 ImageJpeg(const std::string& fqn)
153 : Attachment(fqn, ContentType("image","jpeg"))
154 {
155 }
156 template<typename Codec>
157 ImageJpeg(const std::string& fqn, const Codec& c)
158 : Attachment(fqn, ContentType("image","jpeg"), c)
159 {
160 }
161 };
162
163 /// audio/basic attachment
164 struct AudioBasic: public Attachment
165 {
166 AudioBasic(const std::string& fqn)
167 : Attachment(fqn, ContentType("audio","basic"))
168 {
169 }
170 template<typename Codec>
171 AudioBasic(const std::string& fqn, const Codec& c)
172 : Attachment(fqn, ContentType("audio","basic"), c)
173 {
174 }
175 };
176
177
178
179 /// message/rfc822 entity type
180 struct MessageRfc822: public MimeEntity
181 {
182 MessageRfc822(const MimeEntity&);
183 protected:
184 std::ostream& write(std::ostream&,const char*) const;
185 private:
186 const MimeEntity& m_me;
187 };
188
189
190
191 /**
192 * defaults to application/octect-stream
193 */
194 template<typename Codec>
195 Attachment::Attachment(const std::string& fqn, const Codec& codec)
196 {
197 set(fqn, ContentType("application","octect-stream"), codec);
198 }
199
200 template<typename Codec>
201 Attachment::Attachment(const std::string& fqn, const ContentType& ctype, const Codec& codec)
202 {
203 set(fqn, ctype, codec);
204 }
205
206 template<typename Codec>
207 void Attachment::set(const std::string& fqn, const ContentType& ctype, const Codec& codec)
208 {
209 Header& h = header();
210 m_fqn = fqn;
211 m_status = false;
212 std::string filename = utils::extractFilename(m_fqn);
213 // Content-Type
214 h.contentType(ctype);
215 h.contentType().paramList().push_back(ContentType::Param("name", filename));
216
217 // Content-Transfer-Encoding
218 h.contentTransferEncoding().mechanism(codec.name());
219
220 // Content-Disposition
221 h.contentDisposition().type("attachment");
222 h.contentDisposition().paramList().push_back(ContentDisposition::Param("filename", filename));
223
224 m_status = body().load(m_fqn, codec);
225 }
226
227
228 template<typename Codec>
229 ApplicationOctStream::ApplicationOctStream(const std::string& fqn, const Codec& codec)
230 {
231 Header& h = header();
232 m_fqn = fqn;
233 m_status = false;
234 std::string filename = utils::extractFilename(m_fqn);
235 // Content-Type
236 h.contentType(ContentType("application", "octet-stream"));
237 h.contentType().paramList().push_back(ContentType::Param("name", filename));
238
239 // Content-Transfer-Encoding
240 h.contentTransferEncoding().mechanism(codec.name());
241
242 // Content-Disposition
243 h.contentDisposition().type("attachment");
244 h.contentDisposition().paramList().push_back(ContentDisposition::Param("filename", filename));
245
246 m_status = body().load(m_fqn, codec);
247 }
248
249 }
250
251
252 #endif
253

  ViewVC Help
Powered by ViewVC 1.1.26