00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _MIMETIC_MIMEENTITY_H_
00017 #define _MIMETIC_MIMEENTITY_H_
00018 #include <string>
00019 #include <iostream>
00020 #include <streambuf>
00021 #include <fstream>
00022 #include <iterator>
00023 #include <algorithm>
00024 #include <mimetic/strutils.h>
00025 #include <mimetic/utils.h>
00026 #include <mimetic/contenttype.h>
00027 #include <mimetic/contenttransferencoding.h>
00028 #include <mimetic/contentdisposition.h>
00029 #include <mimetic/mimeversion.h>
00030 #include <mimetic/mimeentitylist.h>
00031 #include <mimetic/codec/codec.h>
00032 #include <mimetic/os/file.h>
00033 #include <mimetic/header.h>
00034 #include <mimetic/body.h>
00035 #include <mimetic/parser/itparserdecl.h>
00036 #include <mimetic/streambufs.h>
00037
00038
00039 namespace mimetic
00040 {
00041
00042 class MimeEntity;
00043
00044
00045
00046 class MimeEntity
00047 {
00048 friend class Body;
00049 friend class MimeEntityLoader;
00050 typedef std::list<std::string> BoundaryList;
00051 typedef unsigned long int size_type;
00052 public:
00053
00054
00055
00056 MimeEntity();
00057
00058
00059
00060 template<typename Iterator>
00061 MimeEntity(Iterator beg, Iterator end, int mask = imNone);
00062
00063
00064
00065 MimeEntity(std::istream&);
00066
00067 virtual ~MimeEntity();
00068
00069
00070
00071
00072 template<typename OutputIt>
00073 size_type copy(OutputIt out);
00074
00075 Header& header();
00076 const Header& header() const;
00077
00078 Body& body();
00079 const Body& body() const;
00080
00081
00082
00083
00084
00085
00086
00087
00088 template<typename Iterator>
00089 void load(Iterator, Iterator, int mask = imNone);
00090 void load(std::istream&, int mask = imNone);
00091
00092
00093
00094
00095 bool hasField(const std::string&) const;
00096
00097
00098
00099
00100
00101 size_type size() const;
00102 friend std::ostream& operator<<(std::ostream&, const MimeEntity&);
00103 protected:
00104 void commonInit();
00105
00106 virtual std::ostream& write(std::ostream&, const char* eol = 0) const;
00107
00108 protected:
00109 Header m_header;
00110 Body m_body;
00111 size_type m_lines;
00112 size_type m_size;
00113
00114 private:
00115
00116
00117 };
00118
00119
00120
00121 template<typename Iterator>
00122 MimeEntity::MimeEntity(Iterator bit, Iterator eit, int mask)
00123 {
00124 commonInit();
00125 load(bit, eit, mask);
00126 }
00127
00128
00129 template<typename Iterator>
00130 void MimeEntity::load(Iterator bit, Iterator eit, int mask)
00131 {
00132 IteratorParser<Iterator,
00133 typename std::iterator_traits<Iterator>::iterator_category> prs(*this);
00134 prs.iMask(mask);
00135 prs.run(bit, eit);
00136 }
00137
00138 template<typename OutputIt>
00139 MimeEntity::size_type MimeEntity::copy(OutputIt out)
00140 {
00141 passthrough_streambuf<OutputIt> psb(out);
00142 std::ostream os(&psb);
00143 os << *this;
00144 return psb.size();
00145 }
00146
00147 }
00148
00149 #endif