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