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
30 namespace mimetic
31{
32
33 class MimeEntity;
34
35
36/// Represent a MIME entity
37 class MimeEntity
38{
39 friend class Body;
40 friend class MimeEntityLoader;
41 typedef std::list<std::string> BoundaryList;
42 typedef unsigned long int size_type;
43 public:
44 /**
45 * Blank MIME entity
46 */
47 MimeEntity();
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#if __cplusplus >= 201103L
59 MimeEntity(const MimeEntity&) = delete;
60 MimeEntity& operator=(const MimeEntity&) = delete;
61#endif
62
63 virtual ~MimeEntity();
64
65 /**
66 * copy text rapresentation of the MimeEntity to the output iterator
67 */
68 template<typename OutputIt>
69 size_type copy(OutputIt out);
70
71 Header& header();
72 const Header& header() const;
73
74 Body& body();
75 const Body& body() const;
76
77 /**
78 * single step load functions: parse the input provided and build the
79 * entity
80 *
81 * use load(..., mask) to ignore some part of the message when it's
82 * not needed saving memory space and execution time
83 */
84 template<typename Iterator>
85 void load(Iterator, Iterator, int mask = imNone);
86 void load(std::istream&, int mask = imNone);
87
88 /**
89 * helper functions: return header().hasField(str)
90 */
91 bool hasField(const std::string&) const;
92
93 /**
94 * returns entity size
95 * Note: this function is slow, use it if you really need
96 */
97 size_type size() const;
98 friend std::ostream& operator<<(std::ostream&, const MimeEntity&);
99 protected:
100 void commonInit();
101
102 virtual std::ostream& write(std::ostream&, const char* eol = 0) const;
103
104 protected:
105 Header m_header;
106 Body m_body;
107 size_type m_lines;
108 size_type m_size;
109
110 private:
111#if __cplusplus < 201103L
112 MimeEntity(const MimeEntity&);
113 MimeEntity& operator=(const MimeEntity&);
114#endif
115};
116
117
118
119 template<typename Iterator>
120 MimeEntity::MimeEntity(Iterator bit, Iterator eit, int mask)
121{
122 commonInit();
123 load(bit, eit, mask);
124}
125
126
127 template<typename Iterator>
128 void MimeEntity::load(Iterator bit, Iterator eit, int mask)
129{
130 IteratorParser<Iterator,
131 typename std::iterator_traits<Iterator>::iterator_category> prs(*this);
132 prs.iMask(mask);
133 prs.run(bit, eit);
134}
135
136 template<typename OutputIt>
137MimeEntity::size_type MimeEntity::copy(OutputIt out)
138{
139 passthrough_streambuf<OutputIt> psb(out);
140 std::ostream os(&psb);
141 os << *this;
142 return psb.size();
143}
144
145}
146
147#endif
mimetic::MimeEntity
Represent a MIME entity.
Definition mimeentity.h:38
mimetic::MimeEntity::MimeEntity
MimeEntity(std::istream &)
mimetic::MimeEntity::load
void load(Iterator, Iterator, int mask=imNone)
Definition mimeentity.h:128
mimetic::MimeEntity::size
size_type size() const
mimetic::MimeEntity::copy
size_type copy(OutputIt out)
Definition mimeentity.h:137
mimetic::MimeEntity::MimeEntity
MimeEntity()
mimetic::MimeEntity::hasField
bool hasField(const std::string &) const
mimetic
Definition body.h:18
mimetic::Header
MIME message header class.
Definition header.h:24
mimetic::IteratorParser
Parse the input reading from an iterator.
Definition itparser.h:21