00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _MIMETIC_MESSAGE_H_
00017 #define _MIMETIC_MESSAGE_H_
00018 #include <time.h>
00019 #include <sys/types.h>
00020 #include <mimetic/libconfig.h>
00021 #include <mimetic/mimeentity.h>
00022 #include <mimetic/utils.h>
00023 #include <mimetic/codec/codec.h>
00024 #ifdef HAVE_UNISTD_H
00025 #include <unistd.h>
00026 #endif
00027
00028 namespace mimetic
00029 {
00030
00031 class ContentType;
00032
00033
00034 struct TextEntity: public MimeEntity
00035 {
00036
00037
00038
00039 TextEntity();
00040 TextEntity(const std::string& text);
00041
00042
00043
00044
00045
00046 TextEntity(const std::string& text, const std::string& charset);
00047 };
00048
00049
00050
00051
00052
00053
00054 struct TextPlain: public TextEntity
00055 {
00056 TextPlain(const std::string& text);
00057
00058
00059
00060
00061 TextPlain(const std::string& text, const std::string& charset);
00062 };
00063
00064
00065
00066 struct TextEnriched: public TextEntity
00067 {
00068 TextEnriched(const std::string& text);
00069
00070
00071
00072
00073 TextEnriched(const std::string& text, const std::string& charset);
00074 };
00075
00076
00077
00078
00079
00080
00081 struct MultipartEntity: public MimeEntity
00082 {
00083 MultipartEntity();
00084 };
00085
00086
00087 struct MultipartMixed: public MultipartEntity
00088 {
00089 MultipartMixed();
00090 };
00091
00092
00093 struct MultipartParallel: public MultipartEntity
00094 {
00095 MultipartParallel();
00096 };
00097
00098
00099 struct MultipartAlternative: public MultipartEntity
00100 {
00101 MultipartAlternative();
00102 };
00103
00104
00105 struct MultipartDigest: public MultipartEntity
00106 {
00107 MultipartDigest();
00108 };
00109
00110
00111
00112 struct ApplicationOctStream: public MimeEntity
00113 {
00114 ApplicationOctStream();
00115 template<typename Codec>
00116 ApplicationOctStream(const std::string&, const Codec& c=Base64::Encoder());
00117 std::string type() const;
00118 void type(const std::string&);
00119 uint padding() const;
00120 void padding(unsigned int);
00121 bool operator()() const { return isValid(); }
00122 bool isValid() const { return m_status; }
00123 protected:
00124 std::string m_fqn;
00125 bool m_status;
00126 };
00127
00128
00129 struct Attachment: public MimeEntity
00130 {
00131
00132
00133
00134 Attachment(const std::string&);
00135 Attachment(const std::string&, const ContentType&);
00136 template<typename Codec>
00137 Attachment(const std::string&, const Codec& c );
00138 template<typename Codec>
00139 Attachment(const std::string&, const ContentType&, const Codec& c);
00140 bool operator()() const { return isValid(); }
00141 bool isValid() const { return m_status; }
00142 private:
00143 template<typename Codec>
00144 void set(const std::string&, const ContentType&, const Codec& c);
00145 std::string m_fqn;
00146 bool m_status;
00147 };
00148
00149
00150 struct ImageJpeg: public Attachment
00151 {
00152 ImageJpeg(const std::string& fqn)
00153 : Attachment(fqn, ContentType("image","jpeg"))
00154 {
00155 }
00156 template<typename Codec>
00157 ImageJpeg(const std::string& fqn, const Codec& c)
00158 : Attachment(fqn, ContentType("image","jpeg"), c)
00159 {
00160 }
00161 };
00162
00163
00164 struct AudioBasic: public Attachment
00165 {
00166 AudioBasic(const std::string& fqn)
00167 : Attachment(fqn, ContentType("audio","basic"))
00168 {
00169 }
00170 template<typename Codec>
00171 AudioBasic(const std::string& fqn, const Codec& c)
00172 : Attachment(fqn, ContentType("audio","basic"), c)
00173 {
00174 }
00175 };
00176
00177
00178
00179
00180 struct MessageRfc822: public MimeEntity
00181 {
00182 MessageRfc822(const MimeEntity&);
00183 protected:
00184 std::ostream& write(std::ostream&,const char*) const;
00185 private:
00186 const MimeEntity& m_me;
00187 };
00188
00189
00190
00191
00192
00193
00194 template<typename Codec>
00195 Attachment::Attachment(const std::string& fqn, const Codec& codec)
00196 {
00197 set(fqn, ContentType("application","octect-stream"), codec);
00198 }
00199
00200 template<typename Codec>
00201 Attachment::Attachment(const std::string& fqn, const ContentType& ctype, const Codec& codec)
00202 {
00203 set(fqn, ctype, codec);
00204 }
00205
00206 template<typename Codec>
00207 void Attachment::set(const std::string& fqn, const ContentType& ctype, const Codec& codec)
00208 {
00209 Header& h = header();
00210 m_fqn = fqn;
00211 m_status = false;
00212 std::string filename = utils::extractFilename(m_fqn);
00213
00214 h.contentType(ctype);
00215 h.contentType().paramList().push_back(ContentType::Param("name", filename));
00216
00217
00218 h.contentTransferEncoding().mechanism(codec.name());
00219
00220
00221 h.contentDisposition().type("attachment");
00222 h.contentDisposition().paramList().push_back(ContentDisposition::Param("filename", filename));
00223
00224 m_status = body().load(m_fqn, codec);
00225 }
00226
00227
00228 template<typename Codec>
00229 ApplicationOctStream::ApplicationOctStream(const std::string& fqn, const Codec& codec)
00230 {
00231 Header& h = header();
00232 m_fqn = fqn;
00233 m_status = false;
00234 std::string filename = utils::extractFilename(m_fqn);
00235
00236 h.contentType(ContentType("application", "octet-stream"));
00237 h.contentType().paramList().push_back(ContentType::Param("name", filename));
00238
00239
00240 h.contentTransferEncoding().mechanism(codec.name());
00241
00242
00243 h.contentDisposition().type("attachment");
00244 h.contentDisposition().paramList().push_back(ContentDisposition::Param("filename", filename));
00245
00246 m_status = body().load(m_fqn, codec);
00247 }
00248
00249 }
00250
00251
00252 #endif
00253