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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2647 - (hide annotations)
Sat Sep 10 15:09:38 2011 UTC (10 years ago) by gregoa
File MIME type: text/plain
File size: 3411 byte(s)
[svn-upgrade] new version mimetic (0.9.7)
1 gregoa 128 /***************************************************************************
2 gregoa 1442 copyright : (C) 2002-2008 by Stefano Barbato
3 gregoa 128 email : stefano@codesink.org
4    
5 gregoa 1457 $Id: mimeentity.h,v 1.29 2008-10-07 11:06:25 tat Exp $
6 gregoa 128 ***************************************************************************/
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     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&);
94     protected:
95     void commonInit();
96    
97     virtual std::ostream& write(std::ostream&, const char* eol = 0) const;
98    
99     protected:
100     Header m_header;
101     Body m_body;
102     size_type m_lines;
103     size_type m_size;
104    
105     private:
106     //MimeEntity(const MimeEntity&);
107     //MimeEntity& operator=(const MimeEntity&);
108     };
109    
110    
111    
112     template<typename Iterator>
113     MimeEntity::MimeEntity(Iterator bit, Iterator eit, int mask)
114     {
115     commonInit();
116     load(bit, eit, mask);
117     }
118    
119    
120     template<typename Iterator>
121     void 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    
129     template<typename OutputIt>
130     MimeEntity::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

  ViewVC Help
Powered by ViewVC 1.1.26