/[debian]/mimetic/trunk/mimetic/body.h
ViewVC logotype

Contents of /mimetic/trunk/mimetic/body.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 197 - (show annotations)
Sun Apr 16 12:21:05 2006 UTC (15 years, 3 months ago) by gregoa
File MIME type: text/plain
File size: 3471 byte(s)
New upstream release.

1 /***************************************************************************
2 copyright : (C) 2002-2005 by Stefano Barbato
3 email : stefano@codesink.org
4
5 $Id: body.h,v 1.15 2006/03/12 12:04:36 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_BODY_H_
17 #define _MIMETIC_BODY_H_
18 #include <string>
19 #include <math.h>
20 #include <mimetic/rfc822/body.h>
21 #include <mimetic/codec/code.h>
22 #include <mimetic/mimeentitylist.h>
23 #include <mimetic/os/file.h>
24
25
26 namespace mimetic
27 {
28
29 /// MIME message body
30 class Body: public Rfc822Body
31 {
32 public:
33 friend class MimeEntity;
34 Body();
35
36 /**
37 set body content
38 */
39 void set(const std::string&);
40
41 /**
42 load file as is, no encoding is performed
43 */
44 bool load(const std::string&);
45
46 /**
47 load file and code it using \p Codec
48 */
49 template<typename Codec>
50 bool load(const std::string&, const Codec&);
51
52 /**
53 en/decode body content
54 */
55 template<typename Codec>
56 bool code(const Codec&);
57
58 /**
59 set body \e preamble
60
61 \sa RFC822
62 */
63 void preamble(const std::string&);
64 /**
65 get body \e preamble
66
67 \sa RFC822
68 */
69 const std::string& preamble() const;
70 std::string& preamble();
71
72 /**
73 set body \e epilogue
74
75 \sa RFC822
76 */
77 void epilogue(const std::string&);
78 /**
79 get body \e epilogue
80
81 \sa RFC822
82 */
83 const std::string& epilogue() const;
84 std::string& epilogue();
85
86 /**
87 get body's parts list
88 */
89 MimeEntityList& parts();
90 const MimeEntityList& parts() const;
91
92 /**
93 get body's MimeEntity owner
94 */
95 MimeEntity* owner();
96 const MimeEntity* owner() const;
97
98 protected:
99 void owner(MimeEntity*);
100 protected:
101 MimeEntity* m_owner;
102 MimeEntityList m_parts;
103 std::string m_preamble, m_epilogue;
104 };
105
106 template<typename Codec>
107 bool Body::load(const std::string& fqn, const Codec& cc)
108 {
109 File in(fqn);
110 if(!in)
111 return false;
112
113 File::iterator beg = in.begin(), end = in.end();
114 Codec codec(cc);
115
116 if(codec.codeSizeMultiplier() > 1.0)
117 {
118 /* increase body string size */
119 struct stat st;
120 if(::stat(fqn.c_str(), &st))
121 return false;
122 reserve((size_type)(::ceil(st.st_size * codec.codeSizeMultiplier())));
123 }
124
125 mimetic::code(beg, end, codec, back_inserter(*this) );
126 return true;
127 }
128
129
130 template<typename Codec>
131 bool Body::code(const Codec& cc)
132 {
133 // OPTIMIZE
134 std::string coded;
135 Codec codec(cc);
136
137 if(codec.codeSizeMultiplier() > 1.0)
138 coded.reserve((size_type)::ceil(size() * codec.codeSizeMultiplier()));
139
140 mimetic::code(begin(), end(), cc, back_inserter(coded) );
141 this->assign(coded);
142 return true;
143 }
144
145 }
146
147 #endif

  ViewVC Help
Powered by ViewVC 1.1.26