Main Page   Class Hierarchy   Alphabetical List   Compound List   Examples  
mimeentity.h
1/***************************************************************************
2 copyright : (C) 2002-2008 by Stefano Barbato
3 email : stefano@codesink.org
4
5 $Id: mimeentity.h,v 1.29 2008-10-07 11:06:25 tat Exp $
6 ***************************************************************************/
7#ifndef _MIMETIC_MIMEENTITY_H_
8#define _MIMETIC_MIMEENTITY_H_
9#include <string>
10#include <iostream>
11#include <streambuf>
12#include <fstream>
13#include <iterator>
14#include <algorithm>
15#include <mimetic/strutils.h>
16#include <mimetic/utils.h>
17#include <mimetic/contenttype.h>
18#include <mimetic/contenttransferencoding.h>
19#include <mimetic/contentdisposition.h>
20#include <mimetic/mimeversion.h>
21#include <mimetic/mimeentitylist.h>
22#include <mimetic/codec/codec.h>
23#include <mimetic/os/file.h>
24#include <mimetic/header.h>
25#include <mimetic/body.h>
26#include <mimetic/parser/itparserdecl.h>
27#include <mimetic/streambufs.h>
28
29
30namespace mimetic
31{
32
33class MimeEntity;
34
35
36/// Represent a MIME entity
38{
39 friend class Body;
40 friend class MimeEntityLoader;
41 typedef std::list<std::string> BoundaryList;
42 typedef unsigned long int size_type;
43public:
44 /**
45 * Blank MIME entity
46 */
48 /**
49 * Parse [beg, end] and build entity based on content
50 */
51 template<typename Iterator>
52 MimeEntity(Iterator beg, Iterator end, int mask = imNone);
53 /**
54 * Parse istream and build entity based on content
55 */
56 MimeEntity(std::istream&);
57
58 virtual ~MimeEntity();
59
60 /**
61 * copy text rapresentation of the MimeEntity to the output iterator
62 */
63 template<typename OutputIt>
64 size_type copy(OutputIt out);
65
66 Header& header();
67 const Header& header() const;
68
69 Body& body();
70 const Body& body() const;
71
72 /**
73 * single step load functions: parse the input provided and build the
74 * entity
75 *
76 * use load(..., mask) to ignore some part of the message when it's
77 * not needed saving memory space and execution time
78 */
79 template<typename Iterator>
80 void load(Iterator, Iterator, int mask = imNone);
81 void load(std::istream&, int mask = imNone);
82
83 /**
84 * helper functions: return header().hasField(str)
85 */
86 bool hasField(const std::string&) const;
87
88 /**
89 * returns entity size
90 * Note: this function is slow, use it if you really need
91 */
92 size_type size() const;
93 friend std::ostream& operator<<(std::ostream&, const MimeEntity&);
94protected:
95 void commonInit();
96
97 virtual std::ostream& write(std::ostream&, const char* eol = 0) const;
98
99protected:
100 Header m_header;
101 Body m_body;
102 size_type m_lines;
103 size_type m_size;
104
105private:
106 //MimeEntity(const MimeEntity&);
107 //MimeEntity& operator=(const MimeEntity&);
108};
109
110
111
112template<typename Iterator>
113MimeEntity::MimeEntity(Iterator bit, Iterator eit, int mask)
114{
115 commonInit();
116 load(bit, eit, mask);
117}
118
119
120template<typename Iterator>
121void MimeEntity::load(Iterator bit, Iterator eit, int mask)
122{
123 IteratorParser<Iterator,
124 typename std::iterator_traits<Iterator>::iterator_category> prs(*this);
125 prs.iMask(mask);
126 prs.run(bit, eit);
127}
128
129template<typename OutputIt>
130MimeEntity::size_type MimeEntity::copy(OutputIt out)
131{
132 passthrough_streambuf<OutputIt> psb(out);
133 std::ostream os(&psb);
134 os << *this;
135 return psb.size();
136}
137
138}
139
140#endif
MIME message body.
Definition: body.h:22
Represent a MIME entity
Definition: mimeentity.h:38
MimeEntity(std::istream &)
void load(Iterator, Iterator, int mask=imNone)
Definition: mimeentity.h:121
size_type size() const
size_type copy(OutputIt out)
Definition: mimeentity.h:130
bool hasField(const std::string &) const
Definition: body.h:18
MIME message header class.
Definition: header.h:24
Parse the input reading from an iterator.
Definition: itparser.h:21