/[debian]/mimetic/branches/upstream/current/mimetic/mimeentity.h
ViewVC logotype

Contents of /mimetic/branches/upstream/current/mimetic/mimeentity.h

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26