00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _MIMETIC_BODY_H_
00017 #define _MIMETIC_BODY_H_
00018 #include <string>
00019 #include <math.h>
00020 #include <mimetic/rfc822/body.h>
00021 #include <mimetic/codec/code.h>
00022 #include <mimetic/mimeentitylist.h>
00023 #include <mimetic/os/file.h>
00024
00025
00026 namespace mimetic
00027 {
00028
00029
00030 class Body: public Rfc822Body
00031 {
00032 public:
00033 friend class MimeEntity;
00034 Body();
00035
00036
00037
00038
00039 void set(const std::string&);
00040
00041
00042
00043
00044 bool load(const std::string&);
00045
00046
00047
00048
00049 template<typename Codec>
00050 bool load(const std::string&, const Codec&);
00051
00052
00053
00054
00055 template<typename Codec>
00056 bool code(const Codec&);
00057
00058
00059
00060
00061
00062
00063 void preamble(const std::string&);
00064
00065
00066
00067
00068
00069 const std::string& preamble() const;
00070 std::string& preamble();
00071
00072
00073
00074
00075
00076
00077 void epilogue(const std::string&);
00078
00079
00080
00081
00082
00083 const std::string& epilogue() const;
00084 std::string& epilogue();
00085
00086
00087
00088
00089 MimeEntityList& parts();
00090 const MimeEntityList& parts() const;
00091
00092
00093
00094
00095 MimeEntity* owner();
00096 const MimeEntity* owner() const;
00097
00098 protected:
00099 void owner(MimeEntity*);
00100 protected:
00101 MimeEntity* m_owner;
00102 MimeEntityList m_parts;
00103 std::string m_preamble, m_epilogue;
00104 };
00105
00106 template<typename Codec>
00107 bool Body::load(const std::string& fqn, const Codec& cc)
00108 {
00109 File in(fqn);
00110 if(!in)
00111 return false;
00112
00113 File::iterator beg = in.begin(), end = in.end();
00114 Codec codec(cc);
00115
00116 if(codec.codeSizeMultiplier() > 1.0)
00117 {
00118
00119 struct stat st;
00120 if(::stat(fqn.c_str(), &st))
00121 return false;
00122 reserve((size_type)(::ceil(st.st_size * codec.codeSizeMultiplier())));
00123 }
00124
00125 mimetic::code(beg, end, codec, back_inserter(*this) );
00126 return true;
00127 }
00128
00129
00130 template<typename Codec>
00131 bool Body::code(const Codec& cc)
00132 {
00133
00134 std::string coded;
00135 Codec codec(cc);
00136
00137 if(codec.codeSizeMultiplier() > 1.0)
00138 coded.reserve((size_type)::ceil(size() * codec.codeSizeMultiplier()));
00139
00140 mimetic::code(begin(), end(), cc, back_inserter(coded) );
00141 this->assign(coded);
00142 return true;
00143 }
00144
00145 }
00146
00147 #endif